Skip to content

Commit

Permalink
refactor: use hook
Browse files Browse the repository at this point in the history
  • Loading branch information
yoannfleurydev committed Oct 9, 2023
1 parent 4bf02e0 commit bae4d43
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/features/auth/PageLoginValidate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ import {
getRetryDelayInSeconds,
} from '@/features/auth/utils';
import { DevCodeHint } from '@/features/dev/DevCodeHint';
import { useSearchParamsUpdater } from '@/hooks/useSearchParamsUpdater';
import { trpc } from '@/lib/trpc/client';

export default function PageLoginValidate() {
const { t } = useTranslation(['auth']);
const router = useRouter();
const params = useParams();
const pathname = usePathname();
const trpcContext = trpc.useContext();
const searchParams = useSearchParams();
const searchParamsUpdater = useSearchParamsUpdater();

const token = params?.token?.toString() ?? '';
const email = searchParams.get('email');
Expand All @@ -63,9 +64,12 @@ export default function PageLoginValidate() {
code: `Code is invalid, please wait ${seconds} seconds before submitting`,
});

const params = new URLSearchParams(searchParams);
params.set('retries', (retries + 1).toString());
router.replace(`${pathname}?${params.toString()}`);
searchParamsUpdater(
{
retries: (retries + 1).toString(),
},
{ replace: true }
);

await new Promise((r) => {
setTimeout(r, seconds * 1_000);
Expand Down

0 comments on commit bae4d43

Please sign in to comment.