From 137c6e8f61a5d98593f09447697b852f61fd8278 Mon Sep 17 00:00:00 2001 From: timthedev07 Date: Wed, 10 Jan 2024 19:26:43 +0100 Subject: [PATCH] fix form --- app/src/components/forms/QuestionForm.tsx | 28 +++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/app/src/components/forms/QuestionForm.tsx b/app/src/components/forms/QuestionForm.tsx index 0caf30c..1f1ddeb 100644 --- a/app/src/components/forms/QuestionForm.tsx +++ b/app/src/components/forms/QuestionForm.tsx @@ -34,6 +34,8 @@ import { Button } from "../reusable/Button"; import { Input } from "../reusable/Input"; +import { z } from "zod"; +import { contentSchema } from "../../schema/shared/content"; import { LabelErrorWrapper } from "../reusable/WithLabelWrapper"; import { QAEditor } from "../richtext/ForwardRefEditor"; import { StyledWrapper } from "../richtext/StyledWrapper"; @@ -157,8 +159,17 @@ export const QuestionForm: FC = ({ try { if (operationType === "ask") { + const { content, ...rest } = formData; const response = await ask({ - ...formData, + ...rest, + content: ( + await validateForm( + { content }, + z.object({ content: contentSchema }) + ) + ).success + ? content + : "Please see the attachments for the question, thank you!", userId: (userId || session?.user.id)!, attachmentIds: atts, }); @@ -176,10 +187,23 @@ export const QuestionForm: FC = ({ push(pageURLs.question(_quid)); } else { if (!quid) return; + const { content, ...rest } = formData; try { await update({ quid, - updateData: { ...formData, attachmentIds: atts }, + updateData: { + ...rest, + content: ( + await validateForm( + { content }, + z.object({ content: contentSchema }) + ) + ).success + ? content + : "Please see the attachments for the question, thank you!", + + attachmentIds: atts, + }, }); clearStorage(); } catch (e) {