import React from "react"; import hotToast from "react-hot-toast"; import { useTranslation } from "react-i18next"; import { I18nKey } from "#/i18n/declaration"; import { Feedback } from "#/api/open-hands.types"; import { useSubmitFeedback } from "#/hooks/mutation/use-submit-feedback"; import { ModalButton } from "#/components/shared/buttons/modal-button"; const FEEDBACK_VERSION = "1.0"; const VIEWER_PAGE = "https://www.all-hands.dev/share"; interface FeedbackFormProps { onClose: () => void; polarity: "positive" | "negative"; } export function FeedbackForm({ onClose, polarity }: FeedbackFormProps) { const { t } = useTranslation(); const copiedToClipboardToast = () => { hotToast(t(I18nKey.FEEDBACK$PASSWORD_COPIED_MESSAGE), { icon: "📋", position: "bottom-right", }); }; const onPressToast = (password: string) => { navigator.clipboard.writeText(password); copiedToClipboardToast(); }; const shareFeedbackToast = ( message: string, link: string, password: string, ) => { hotToast(
{message} onPressToast(password)} href={link} target="_blank" rel="noreferrer" > {t(I18nKey.FEEDBACK$GO_TO_FEEDBACK)} onPressToast(password)} className="cursor-pointer"> {t(I18nKey.FEEDBACK$PASSWORD)}: {password}{" "} ({t(I18nKey.FEEDBACK$COPY_LABEL)})
, { duration: 10000 }, ); }; const { mutate: submitFeedback, isPending } = useSubmitFeedback(); const handleSubmit = async (event: React.FormEvent) => { event?.preventDefault(); const formData = new FormData(event.currentTarget); const email = formData.get("email")?.toString() || ""; const permissions = (formData.get("permissions")?.toString() || "private") as "private" | "public"; const feedback: Feedback = { version: FEEDBACK_VERSION, email, polarity, permissions, trajectory: [], token: "", }; submitFeedback( { feedback }, { onSuccess: (data) => { const { message, feedback_id, password } = data.body; // eslint-disable-line const link = `${VIEWER_PAGE}?share_id=${feedback_id}`; shareFeedbackToast(message, link, password); onClose(); }, }, ); }; return (
); }