// AK-P21 (AD-28 interim polish) — global feedback widget. The mini form is a // real ~/ui Dialog (size XS 420) with a category select (bug/feature/question, // designer brief P21); the category is prefixed into the message because the // support-ticket contract intentionally has no category column. Shared by the // legacy NavBar trigger (mobile visibility restriction removed) and the shadcn // nav-actions trigger. Submission keeps the established add-feedback intent on // the tenant root route (rate limit 3/24h lives in Feedback.server). // // Instead of the originally sketched screenshot checkbox, the reporter attaches // an image themselves (decision 2026-07-21): the client never captures the page // on its own, so no third-party personal data leaves the workspace without the // reporter consciously picking the file. The upload is fail-closed scanned and // ClamAV-checked server-side. import { useFetcher, useLocation, useParams } from "react-router"; import { Fragment, useEffect, useState } from "react"; import { toast } from "sonner"; import { useTranslation } from "react-i18next"; import StarsIconFilled from "~/components/ui/icons/StarsIconFilled"; import { appPath } from "~/utils/app/CanonicalUrlUtils"; import { useAppOrAdminData } from "~/utils/data/useAppOrAdminData"; import { useRootData } from "~/utils/data/useRootData"; import { Button } from "~/ui/components/Button"; import { Dialog } from "~/ui/components/Dialog"; import { Select } from "~/ui/components/Select"; import { TextArea } from "~/ui/components/TextArea"; const FEEDBACK_CATEGORIES = ["bug", "feature", "question"] as const; type FeedbackCategory = (typeof FEEDBACK_CATEGORIES)[number]; /** Mirrors the server-side contract in Feedback.server. */ const FEEDBACK_ATTACHMENT_ACCEPT = "image/png,image/jpeg,image/webp,image/gif"; const FEEDBACK_ATTACHMENT_MAX_MB = 5; export default function AddFeedbackButton() { const [isOpen, setIsOpen] = useState(false); const { t } = useTranslation(); return (
setIsOpen(false)} />
); } export function FeedbackFormDialog({ open, onClose }: { open: boolean; onClose: () => void }) { const { t } = useTranslation(); const params = useParams(); const appOrAdminData = useAppOrAdminData(); const { csrf } = useRootData(); const fetcher = useFetcher<{ success?: string; error?: string }>(); const location = useLocation(); const [category, setCategory] = useState("bug"); const [attachmentError, setAttachmentError] = useState(null); useEffect(() => { if (open) { setCategory("bug"); setAttachmentError(null); } }, [open]); useEffect(() => { if (fetcher.data?.success) { toast.success(fetcher.data.success); onClose(); } else if (fetcher.data?.error) { toast.error(fetcher.data.error); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [fetcher.data]); const submitting = fetcher.state !== "idle"; const onSubmit = (e: React.FormEvent) => { e.preventDefault(); if (attachmentError) return; void fetcher.submit(e.currentTarget, { method: "post", encType: "multipart/form-data", action: params.tenant ? appPath({ tenantSlug: params.tenant, mode: "host-aware" }) : "", }); }; // Reject oversized or non-image picks before the upload is attempted; the // server enforces the same limits again. const onAttachmentChange = (e: React.ChangeEvent) => { const file = e.currentTarget.files?.[0] ?? null; if (!file) { setAttachmentError(null); return; } if (file.size > FEEDBACK_ATTACHMENT_MAX_MB * 1024 * 1024) { setAttachmentError(t("feedback.attachment.tooLarge", { megabytes: FEEDBACK_ATTACHMENT_MAX_MB })); return; } if (!FEEDBACK_ATTACHMENT_ACCEPT.split(",").includes(file.type)) { setAttachmentError(t("feedback.attachment.unsupportedType")); return; } setAttachmentError(null); }; return ( (nextOpen ? undefined : onClose())}> {/* Radix Select is not a native form control — mirror the picked category. */}
{t("feedback.title")} {t("feedback.description")}
{attachmentError ? ( {attachmentError} ) : ( {t("feedback.attachment.hint", { megabytes: FEEDBACK_ATTACHMENT_MAX_MB })} )}
{t("feedback.rateLimitHint")}
); }