Skip to content

Commit

Permalink
fix form
Browse files Browse the repository at this point in the history
  • Loading branch information
timthedev07 committed Jan 10, 2024
1 parent f0f87b6 commit 137c6e8
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions app/src/components/forms/QuestionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -157,8 +159,17 @@ export const QuestionForm: FC<QuestionFormProps> = ({

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,
});
Expand All @@ -176,10 +187,23 @@ export const QuestionForm: FC<QuestionFormProps> = ({
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) {
Expand Down

0 comments on commit 137c6e8

Please sign in to comment.