-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(identification): enhance error handling (wip)
- Loading branch information
1 parent
35c201e
commit 96f1dc2
Showing
4 changed files
with
137 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { CircularProgress } from '@mui/material'; | ||
import { useFormStatus } from 'react-dom'; | ||
|
||
export function LoadingAdornment() { | ||
const status = useFormStatus(); | ||
|
||
if (!status.pending) return null; | ||
|
||
return ( | ||
<div style={{ display: 'flex' }}> | ||
<CircularProgress size={28} /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use server'; | ||
|
||
import { redirect } from 'next/navigation'; | ||
|
||
import { | ||
findCitizen, | ||
findIamCitizen, | ||
setCookie, | ||
validateRecaptcha, | ||
} from '@/actions'; | ||
|
||
type State = { message: string }; | ||
|
||
export async function identifyAccount(prev: State, form: FormData) { | ||
const cedula = form.get('cedula') as string; | ||
const token = form.get('token') as string; | ||
|
||
if (!token) { | ||
return { message: 'intl.errors.recaptcha.issues' }; | ||
} | ||
|
||
if (!cedula) { | ||
return { message: 'No cédula' }; | ||
} | ||
|
||
const { isHuman } = await validateRecaptcha(token); | ||
|
||
if (!isHuman) { | ||
return { message: 'intl.errors.recaptcha.validation' }; | ||
} | ||
|
||
const { exists } = await findIamCitizen(cedula); | ||
|
||
if (exists) { | ||
return { message: 'intl.errors.cedula.exists' }; | ||
} | ||
|
||
const citizen = await findCitizen(cedula); | ||
await setCookie('citizen', citizen); | ||
|
||
redirect('liveness'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import ArrowCircleRightOutlined from '@mui/icons-material/ArrowCircleRightOutlined'; | ||
import { useFormStatus } from 'react-dom'; | ||
|
||
import { ButtonApp } from '@/components/elements/button'; | ||
import { useLanguage } from '../provider'; | ||
|
||
export function SubmitButton() { | ||
const status = useFormStatus(); | ||
const { intl } = useLanguage(); | ||
|
||
return ( | ||
<ButtonApp | ||
submit | ||
endIcon={<ArrowCircleRightOutlined />} | ||
disabled={status.pending} | ||
> | ||
{intl.actions.confirm} | ||
</ButtonApp> | ||
); | ||
} |