import { getFormProps, getSelectProps, getInputProps, getTextareaProps, useForm, } from "@conform-to/react"; import { parseWithZod } from "~/utils/conform"; import { InformationCircleIcon, ArrowUpCircleIcon } from "@heroicons/react/20/solid"; import { EnvelopeIcon, ShieldCheckIcon } from "@heroicons/react/24/solid"; import { Form, useActionData, useLocation, useNavigation } from "@remix-run/react"; import { useEffect } from "react"; import { type FeedbackType, feedbackTypes, schema } from "~/utils/feedback"; import { Button } from "./primitives/Buttons"; import { Fieldset } from "./primitives/Fieldset"; import { FormButtons } from "./primitives/FormButtons"; import { FormError } from "./primitives/FormError"; import { Icon } from "./primitives/Icon"; import { InfoPanel } from "./primitives/InfoPanel"; import { InputGroup } from "./primitives/InputGroup"; import { Label } from "./primitives/Label"; import { Paragraph } from "./primitives/Paragraph"; import { Select, SelectItem } from "./primitives/Select"; import { TextArea } from "./primitives/TextArea"; import { TextLink } from "./primitives/TextLink"; import { DialogClose } from "@radix-ui/react-dialog"; // The body of the Contact us dialog. It loads when the dialog opens (see Feedback.tsx), which keeps // the form library and the select menu out of every page's first load. export function FeedbackForm({ type, setType, setOpen, }: { type: FeedbackType; setType: (type: FeedbackType) => void; setOpen: (open: boolean) => void; }) { const location = useLocation(); const lastSubmission = useActionData(); const navigation = useNavigation(); const [form, fields] = useForm({ id: "accept-invite", lastResult: lastSubmission as any, onValidate({ formData }) { return parseWithZod(formData, { schema }); }, shouldRevalidate: "onInput", }); useEffect(() => { if ( navigation.formAction === "/resources/feedback" && navigation.state === "loading" && Object.keys(form.allErrors).length === 0 ) { setOpen(false); } }, [navigation.formAction, navigation.state, form.allErrors, setOpen]); return (