From 5a281031d4dcfbf9552e56328ff729427f1ed4b3 Mon Sep 17 00:00:00 2001 From: Jeff Sieu Date: Thu, 3 Nov 2022 15:36:50 +0800 Subject: [PATCH] [questions][ui] add thank you message --- .../card/question/BaseQuestionCard.tsx | 7 ++-- .../forms/CreateQuestionEncounterForm.tsx | 41 ++++++++++++++----- .../[questionId]/[questionSlug]/index.tsx | 6 +-- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/apps/portal/src/components/questions/card/question/BaseQuestionCard.tsx b/apps/portal/src/components/questions/card/question/BaseQuestionCard.tsx index 7b50c1a9..2eb2c194 100644 --- a/apps/portal/src/components/questions/card/question/BaseQuestionCard.tsx +++ b/apps/portal/src/components/questions/card/question/BaseQuestionCard.tsx @@ -90,7 +90,7 @@ type ReceivedStatisticsProps = type CreateEncounterProps = | { createEncounterButtonText: string; - onReceivedSubmit: (data: CreateQuestionEncounterData) => void; + onReceivedSubmit: (data: CreateQuestionEncounterData) => Promise; showCreateEncounterButton: true; } | { @@ -263,9 +263,8 @@ export default function BaseQuestionCard({ onCancel={() => { setShowReceivedForm(false); }} - onSubmit={(data) => { - onReceivedSubmit?.(data); - setShowReceivedForm(false); + onSubmit={async (data) => { + await onReceivedSubmit?.(data); }} /> )} diff --git a/apps/portal/src/components/questions/forms/CreateQuestionEncounterForm.tsx b/apps/portal/src/components/questions/forms/CreateQuestionEncounterForm.tsx index 453733c8..6f65bf22 100644 --- a/apps/portal/src/components/questions/forms/CreateQuestionEncounterForm.tsx +++ b/apps/portal/src/components/questions/forms/CreateQuestionEncounterForm.tsx @@ -1,5 +1,6 @@ import { startOfMonth } from 'date-fns'; import { useState } from 'react'; +import { CheckIcon } from '@heroicons/react/20/solid'; import { Button } from '@tih/ui'; import type { Month } from '~/components/shared/MonthYearPicker'; @@ -22,7 +23,7 @@ export type CreateQuestionEncounterData = { export type CreateQuestionEncounterFormProps = { onCancel: () => void; - onSubmit: (data: CreateQuestionEncounterData) => void; + onSubmit: (data: CreateQuestionEncounterData) => Promise; }; export default function CreateQuestionEncounterForm({ @@ -30,6 +31,8 @@ export default function CreateQuestionEncounterForm({ onSubmit, }: CreateQuestionEncounterFormProps) { const [step, setStep] = useState(0); + const [loading, setLoading] = useState(false); + const [submitted, setSubmitted] = useState(false); const [selectedCompany, setSelectedCompany] = useState(null); const [selectedLocation, setSelectedLocation] = useState( @@ -40,9 +43,18 @@ export default function CreateQuestionEncounterForm({ startOfMonth(new Date()), ); + if (submitted) { + return ( +
+ +

Thank you for your response

+
+ ); + } + return (
-

+

I saw this question {step <= 1 ? 'at' : step === 2 ? 'for' : 'on'}

{step === 0 && ( @@ -128,9 +140,10 @@ export default function CreateQuestionEncounterForm({ )} {step === 3 && (