/* This file is part of the Notesnook project (https://notesnook.com/) Copyright (C) 2023 Streetwriters (Private) Limited This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ import { useCallback, useRef, useState } from "react"; import Modal from "react-modal"; import { Button, Flex, Text } from "@theme-ui/components"; import { Monograph } from "./types"; import Turnstile from "react-turnstile"; import { BaseThemeProvider } from "../theme-provider"; const BASE_URL = "https://notesnook.com/api/v1/reports"; const REPORT_TYPES = [ { type: "spam", title: "Spam" }, { type: "malware", title: "Malware" }, { type: "violence", title: "Violence" }, { type: "child_abuse", title: "Child abuse" }, { type: "copyright", title: "Copyright" } ]; type SubmitStatus = { success: boolean; error?: string }; export default function ReportDialog({ setVisible, monograph }: { monograph: Monograph; setVisible: (visible: boolean) => void; }) { const formRef = useRef(null); const [status, setStatus] = useState(); const onSubmit = useCallback(async (body: FormData) => { try { setStatus(undefined); const response = await fetch(`${BASE_URL}/submit`, { method: "post", body }); const json = (await response.json()) as { error: string }; if (!response.ok) { setStatus({ success: false, error: json.error }); } else { setStatus({ success: true }); } } catch (e) { if (e instanceof Error) { setStatus({ success: false, error: e.message }); console.error(e); } } }, []); return ( { setVisible(false); setStatus(undefined); }} > { if (e.target instanceof HTMLFormElement) { e.preventDefault(); const body = new FormData(e.target); onSubmit(body); } }} > {status?.success ? "Reported" : "Report"} {status?.success ? ( <> Thank you for helping us keep Monographs safe for everyone. ) : ( <> {REPORT_TYPES.map((item) => ( ))} { // noop }} style={{ fontSize: "1rem" }} theme={/*colorMode === "dark" ? "dark" :*/ "light"} /> )} ); }