Skip to content

Commit 2844b21

Browse files
authored
Merge pull request #31 from meceware/dev
v1.0.0
2 parents 34f602c + af5cc31 commit 2844b21

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/app/#/signin-form.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import { useEffect, useState } from 'react';
3+
import { useEffect, useState, useCallback } from 'react';
44
import { useRouter } from 'next/navigation';
55
import { toast } from 'sonner';
66
import { signIn } from 'next-auth/react';
@@ -36,18 +36,19 @@ import { signInAction, generateOTPLink } from './action';
3636
const SignInOTP = ({email}) => {
3737
const [otp, setOtp] = useState('');
3838
const [disabled, setDisabled] = useState(false);
39+
const [url, setUrl] = useState(null);
3940
const router = useRouter();
4041

41-
const onSubmit = async (data) => {
42+
const onSubmit = useCallback(async (code, email) => {
4243
setDisabled(true);
4344

44-
const parsedCode = signInOTPSchema.safeParse({ code: data });
45+
const parsedCode = signInOTPSchema.safeParse({ code: code });
4546
const parsedEmail = signInSchema.safeParse({ email: email });
4647

4748
if (parsedCode?.success && parsedEmail?.success) {
4849
const url = await generateOTPLink(parsedCode.data.code, parsedEmail.data.email);
4950
if (url) {
50-
router.push(url);
51+
setUrl(url);
5152
} else {
5253
toast.error('This is not a valid code! Please try again.');
5354
}
@@ -56,14 +57,21 @@ const SignInOTP = ({email}) => {
5657
}
5758

5859
setDisabled(false);
59-
};
60+
}, []);
61+
62+
useEffect(() => {
63+
if (url) {
64+
setUrl(null);
65+
router.push(url);
66+
}
67+
}, [url]);
6068

6169
return (
6270
<InputOTP
6371
maxLength={6}
6472
value={otp}
6573
onChange={setOtp}
66-
onComplete={onSubmit}
74+
onComplete={(data) => onSubmit(data, email)}
6775
disabled={disabled}
6876
containerClassName='flex-col sm:flex-row justify-center'
6977
>
@@ -116,7 +124,7 @@ const SignInSendAgain = ({ email, onClick }) => {
116124
<CardContent className='flex flex-col gap-4'>
117125
<Divider text='or' />
118126
<div className='space-y-2 text-center'>
119-
<p className='text-sm text-muted-foreground'>Enter the 8-digit code sent to your email</p>
127+
<p className='text-sm text-muted-foreground'>Enter the 6-digit code sent to your email</p>
120128
<SignInOTP email={email} />
121129
</div>
122130
</CardContent>

src/components/home-visitor.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const HomeVisitor = () => {
2222
<h3 className='text-xl text-muted-foreground-light font-semibold max-w-4xl'>
2323
Get notified and never miss a payment again.
2424
</h3>
25-
<Button size='lg' asChild className='text-lg'>
25+
<Button size='lg' asChild className='text-base'>
2626
<Link href='/#'>
2727
Get Started
2828
<Icons.arrowRight className='ml-2 h-4 w-4' />

0 commit comments

Comments
 (0)