[questions][ui] add thank you message

pull/514/head
Jeff Sieu 3 years ago
parent 7e06e07df4
commit 5a281031d4

@ -90,7 +90,7 @@ type ReceivedStatisticsProps =
type CreateEncounterProps = type CreateEncounterProps =
| { | {
createEncounterButtonText: string; createEncounterButtonText: string;
onReceivedSubmit: (data: CreateQuestionEncounterData) => void; onReceivedSubmit: (data: CreateQuestionEncounterData) => Promise<void>;
showCreateEncounterButton: true; showCreateEncounterButton: true;
} }
| { | {
@ -263,9 +263,8 @@ export default function BaseQuestionCard({
onCancel={() => { onCancel={() => {
setShowReceivedForm(false); setShowReceivedForm(false);
}} }}
onSubmit={(data) => { onSubmit={async (data) => {
onReceivedSubmit?.(data); await onReceivedSubmit?.(data);
setShowReceivedForm(false);
}} }}
/> />
)} )}

@ -1,5 +1,6 @@
import { startOfMonth } from 'date-fns'; import { startOfMonth } from 'date-fns';
import { useState } from 'react'; import { useState } from 'react';
import { CheckIcon } from '@heroicons/react/20/solid';
import { Button } from '@tih/ui'; import { Button } from '@tih/ui';
import type { Month } from '~/components/shared/MonthYearPicker'; import type { Month } from '~/components/shared/MonthYearPicker';
@ -22,7 +23,7 @@ export type CreateQuestionEncounterData = {
export type CreateQuestionEncounterFormProps = { export type CreateQuestionEncounterFormProps = {
onCancel: () => void; onCancel: () => void;
onSubmit: (data: CreateQuestionEncounterData) => void; onSubmit: (data: CreateQuestionEncounterData) => Promise<void>;
}; };
export default function CreateQuestionEncounterForm({ export default function CreateQuestionEncounterForm({
@ -30,6 +31,8 @@ export default function CreateQuestionEncounterForm({
onSubmit, onSubmit,
}: CreateQuestionEncounterFormProps) { }: CreateQuestionEncounterFormProps) {
const [step, setStep] = useState(0); const [step, setStep] = useState(0);
const [loading, setLoading] = useState(false);
const [submitted, setSubmitted] = useState(false);
const [selectedCompany, setSelectedCompany] = useState<string | null>(null); const [selectedCompany, setSelectedCompany] = useState<string | null>(null);
const [selectedLocation, setSelectedLocation] = useState<Location | null>( const [selectedLocation, setSelectedLocation] = useState<Location | null>(
@ -40,9 +43,18 @@ export default function CreateQuestionEncounterForm({
startOfMonth(new Date()), startOfMonth(new Date()),
); );
if (submitted) {
return (
<div className="font-md flex items-center gap-1 rounded-full border bg-slate-50 py-1 pl-2 pr-3 text-sm text-slate-500">
<CheckIcon className="h-5 w-5" />
<p>Thank you for your response</p>
</div>
);
}
return ( return (
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
<p className="font-md text-md text-slate-600"> <p className="text-md text-slate-600">
I saw this question {step <= 1 ? 'at' : step === 2 ? 'for' : 'on'} I saw this question {step <= 1 ? 'at' : step === 2 ? 'for' : 'on'}
</p> </p>
{step === 0 && ( {step === 0 && (
@ -128,9 +140,10 @@ export default function CreateQuestionEncounterForm({
)} )}
{step === 3 && ( {step === 3 && (
<Button <Button
isLoading={loading}
label="Submit" label="Submit"
variant="primary" variant="primary"
onClick={() => { onClick={async () => {
if ( if (
selectedCompany && selectedCompany &&
selectedLocation && selectedLocation &&
@ -138,14 +151,20 @@ export default function CreateQuestionEncounterForm({
selectedDate selectedDate
) { ) {
const { cityId, stateId, countryId } = selectedLocation; const { cityId, stateId, countryId } = selectedLocation;
onSubmit({ setLoading(true);
cityId, try {
company: selectedCompany, await onSubmit({
countryId, cityId,
role: selectedRole, company: selectedCompany,
seenAt: selectedDate, countryId,
stateId, role: selectedRole,
}); seenAt: selectedDate,
stateId,
});
setSubmitted(true);
} finally {
setLoading(false);
}
} }
}} }}
/> />

@ -139,7 +139,7 @@ export default function QuestionPage() {
}, },
); );
const { mutate: addEncounter } = trpc.useMutation( const { mutateAsync: addEncounterAsync } = trpc.useMutation(
'questions.questions.encounters.user.create', 'questions.questions.encounters.user.create',
{ {
onSuccess: () => { onSuccess: () => {
@ -208,8 +208,8 @@ export default function QuestionPage() {
year: 'numeric', year: 'numeric',
})} })}
upvoteCount={question.numVotes} upvoteCount={question.numVotes}
onReceivedSubmit={(data) => { onReceivedSubmit={async (data) => {
addEncounter({ await addEncounterAsync({
cityId: data.cityId, cityId: data.cityId,
companyId: data.company, companyId: data.company,
countryId: data.countryId, countryId: data.countryId,

Loading…
Cancel
Save