import { Button, Checkbox, NumberInput, Paper, Title, Text, } from "@mantine/core"; import { useForm } from "@mantine/form"; import { notifications } from "@mantine/notifications"; import { fetchHeaders } from "./fetch"; import React from "react"; type ProfileVerificationProps = Pick< UserProfile, "verify_mastodon_favorite" | "verify_delay" > & { username: string }; type OrderVerificationForm = Pick< UserProfile, "verify_mastodon_favorite" | "verify_delay" >; export const ProfileVerification: React.FC = ({ username, verify_mastodon_favorite, verify_delay, }) => { const [loading, setLoading] = React.useState(false); const form = useForm({ mode: "uncontrolled", initialValues: { verify_mastodon_favorite, verify_delay, }, validate: { verify_delay: (value: number, values: OrderVerificationForm) => { console.log("oh boy", values.verify_mastodon_favorite, value); return !values.verify_mastodon_favorite || value ? null : "You must set a verification delay"; }, }, }); const handleSubmit = React.useCallback( form.onSubmit((values) => { setLoading(true); fetch(`/api/subs/${username}`, { method: "POST", headers: fetchHeaders(), body: JSON.stringify(values), }) .then((response) => { if (response.ok) { notifications.show({ title: "Success", message: "Your preferences have been saved", color: "green", }); } else { notifications.show({ title: "Error", message: "There was a problem saving your preferences", color: "red", }); } }) .finally(() => { setLoading(false); }); }), [], ); return (
Order Verification hours} />
); };