From 8fdea6b5bc39ff0457ee0a6b6dee28af5eb6967c Mon Sep 17 00:00:00 2001 From: Jeff Sieu Date: Mon, 31 Oct 2022 10:47:27 +0800 Subject: [PATCH] [questions][feat] add similar questions check (#468) Co-authored-by: wlren --- .../questions/ContributeQuestionDialog.tsx | 12 +- .../card/question/BaseQuestionCard.tsx | 5 +- .../card/question/SimilarQuestionCard.tsx | 22 +- .../forms/ContributeQuestionForm.tsx | 119 +- .../[questionId]/[questionSlug]/index.tsx | 1 + ...uestions-question-encounter-user-router.ts | 4 +- tatus | 6907 ----------------- 7 files changed, 142 insertions(+), 6928 deletions(-) delete mode 100644 tatus diff --git a/apps/portal/src/components/questions/ContributeQuestionDialog.tsx b/apps/portal/src/components/questions/ContributeQuestionDialog.tsx index 4115a2db..ed31837d 100644 --- a/apps/portal/src/components/questions/ContributeQuestionDialog.tsx +++ b/apps/portal/src/components/questions/ContributeQuestionDialog.tsx @@ -1,6 +1,6 @@ import { Fragment, useState } from 'react'; import { Dialog, Transition } from '@headlessui/react'; -import { HorizontalDivider } from '@tih/ui'; +import { HorizontalDivider, useToast } from '@tih/ui'; import DiscardDraftDialog from './DiscardDraftDialog'; import type { ContributeQuestionFormProps } from './forms/ContributeQuestionForm'; @@ -21,6 +21,8 @@ export default function ContributeQuestionDialog({ }: ContributeQuestionDialogProps) { const [showDiscardDialog, setShowDiscardDialog] = useState(false); + const { showToast } = useToast(); + const handleDraftDiscard = () => { setShowDiscardDialog(false); onCancel(); @@ -75,6 +77,14 @@ export default function ContributeQuestionDialog({
setShowDiscardDialog(true)} + onSimilarQuestionFound={() => { + onCancel(); + showToast({ + title: + 'Your response has been recorded. Draft discarded.', + variant: 'success', + }); + }} onSubmit={(data) => { onSubmit(data); onCancel(); diff --git a/apps/portal/src/components/questions/card/question/BaseQuestionCard.tsx b/apps/portal/src/components/questions/card/question/BaseQuestionCard.tsx index 4d8059e6..b183b012 100644 --- a/apps/portal/src/components/questions/card/question/BaseQuestionCard.tsx +++ b/apps/portal/src/components/questions/card/question/BaseQuestionCard.tsx @@ -88,10 +88,12 @@ type ReceivedStatisticsProps = type CreateEncounterProps = | { + createEncounterButtonText: string; onReceivedSubmit: (data: CreateQuestionEncounterData) => void; showCreateEncounterButton: true; } | { + createEncounterButtonText?: never; onReceivedSubmit?: never; showCreateEncounterButton?: false; }; @@ -132,6 +134,7 @@ export default function BaseQuestionCard({ showAnswerStatistics, showReceivedStatistics, showCreateEncounterButton, + createEncounterButtonText, showActionButton, actionButtonLabel, onActionButtonClick, @@ -238,7 +241,7 @@ export default function BaseQuestionCard({