Skip to content

Commit e51c5eb

Browse files
committed
improve verification
1 parent ff656db commit e51c5eb

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

app/routes/recipients+/__editor.server.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ export async function action({ request, params }: ActionFunctionArgs) {
9595
export async function usertRecipientAction({
9696
formData,
9797
userId,
98-
request,
9998
recipient,
10099
}: Pick<RecipientActionArgs, 'formData' | 'request' | 'userId'> & {
101100
recipient: RecipientActionArgs['recipient'] | null
@@ -128,7 +127,6 @@ export async function usertRecipientAction({
128127

129128
if (recipientId) {
130129
invariantResponse(recipient, 'Recipient not found')
131-
const verified = phoneNumber === recipient?.phoneNumber
132130
const updatedRecipient = await prisma.recipient.update({
133131
select: { id: true },
134132
where: { id: recipientId },
@@ -143,14 +141,10 @@ export async function usertRecipientAction({
143141
timeZone,
144142
},
145143
})
146-
if (verified) {
147-
return redirect(`/recipients/${updatedRecipient.id}`)
148-
} else {
149-
return sendVerificationAction({ formData, userId, request, recipient })
150-
}
144+
return redirect(`/recipients/${updatedRecipient.id}`)
151145
} else {
152-
recipient = await prisma.recipient.create({
153-
select: { id: true, name: true, phoneNumber: true, verified: true },
146+
const newRecipient = await prisma.recipient.create({
147+
select: { id: true },
154148
data: {
155149
name,
156150
phoneNumber,
@@ -161,7 +155,12 @@ export async function usertRecipientAction({
161155
},
162156
})
163157

164-
return sendVerificationAction({ formData, userId, request, recipient })
158+
return redirectWithToast(`/recipients/${newRecipient.id}/edit`, {
159+
type: 'success',
160+
title: 'Recipient created',
161+
description:
162+
'Your recipient has been created. You must verify them before sending messages.',
163+
})
165164
}
166165
}
167166

app/routes/recipients+/__editor.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export function RecipientEditor({
5252
}) {
5353
const actionData = useActionData<typeof usertRecipientAction>()
5454
const isPending = useIsPending()
55+
const needsVerification = recipient?.verified === false
5556

5657
const [form, fields] = useForm({
5758
id: 'recipient-editor',
@@ -67,9 +68,21 @@ export function RecipientEditor({
6768
return (
6869
<div className="absolute inset-0">
6970
<div className="flex justify-end gap-2 p-6">
70-
{recipient && !recipient.verified ? <VerifyForm /> : null}
71+
{needsVerification ? <VerifyForm /> : null}
7172
{recipient?.id ? <DeleteRecipient id={recipient.id} /> : null}
7273
</div>
74+
{needsVerification ? (
75+
<div className="px-6">
76+
<strong className="font-bold text-destructive">
77+
Verification required
78+
</strong>
79+
<p>
80+
When you click "Verify" above, it will send a text message with a
81+
verification code to {recipient?.phoneNumber} (their phone number).
82+
You will be required to enter their code in the next step.
83+
</p>
84+
</div>
85+
) : null}
7386
<Form
7487
method="POST"
7588
className="flex h-full flex-col gap-y-4 overflow-y-auto overflow-x-hidden px-10 pb-28 pt-12"

0 commit comments

Comments
 (0)