import { t } from "@lingui/core/macro"; import ContentEditable from "react-contenteditable"; import { useForm } from "react-hook-form"; import { HiOutlineArrowUp } from "react-icons/hi2"; import LoadingSpinner from "~/components/LoadingSpinner"; import { usePopup } from "~/providers/popup"; import { api } from "~/utils/api"; interface FormValues { comment: string; } const NewCommentForm = ({ cardPublicId }: { cardPublicId: string }) => { const utils = api.useUtils(); const { showPopup } = usePopup(); const { handleSubmit, setValue, watch, reset } = useForm({ values: { comment: "", }, }); const queryParams = { cardPublicId, }; const addCommentMutation = api.card.addComment.useMutation({ onError: (_error, _newList) => { showPopup({ header: t`Unable to add comment`, message: t`Please try again later, or contact customer support.`, icon: "error", }); }, onSettled: async () => { reset(); await utils.card.byId.invalidate(queryParams); }, onSuccess: async () => { await utils.card.byId.refetch(); }, }); const onSubmit = (data: FormValues) => { addCommentMutation.mutate({ cardPublicId, comment: data.comment, }); }; return (
setValue("comment", e.target.value)} className="block w-full border-0 bg-transparent py-1.5 text-light-900 focus-visible:outline-none dark:text-dark-1000 sm:text-sm sm:leading-6" onKeyDown={async (e) => { if (e.key === "Enter" && e.shiftKey) { e.preventDefault(); await handleSubmit(onSubmit)(); } }} />
); }; export default NewCommentForm;