import * as React from "react"; import { useTranslation } from "react-i18next"; import { useFetcher } from "react-router"; import { SendouDialog } from "~/components/elements/Dialog"; import { FormMessage } from "~/components/FormMessage"; import { Label } from "~/components/Label"; import { SubmitButton } from "~/components/SubmitButton"; import type { Tables } from "~/db/tables"; import { SENDOUQ } from "~/features/sendouq/q-constants"; import { preferenceEmojiUrl, userCardNotePage } from "~/utils/urls"; type PrivateNote = Pick; /** * Modal for adding/editing the viewer's private note about a user, posting to the * `/user-card/:id/note` resource route. Closes once the fetcher settles (save succeeds → * automatic revalidation refreshes the card). Clearing the text with a neutral sentiment and saving * deletes the note (handled by the route). Rendered wherever a `UserCard` lives. */ export function AddPrivateNoteDialog({ userId, username, note, onClose, }: { userId: number; username: string; note: PrivateNote | null; onClose: () => void; }) { const { t } = useTranslation(["q", "common"]); const fetcher = useFetcher(); const wasSubmittingRef = React.useRef(false); React.useEffect(() => { if (fetcher.state !== "idle") { wasSubmittingRef.current = true; } else if (wasSubmittingRef.current) { wasSubmittingRef.current = false; if ((fetcher.data as { ok?: boolean } | undefined)?.ok) { onClose(); } } }, [fetcher.state, fetcher.data, onClose]); return (