Skip to content

Commit

Permalink
Merge pull request #35 from opticrd/refactor-to-mui
Browse files Browse the repository at this point in the history
refactor(ui): use vainilla Material UI where possible

Former-commit-id: 97445be563b8b562978bf32c5bcb2a87c68ad8f9 [formerly ee9aa907cade008d62e0aed2da676d557ee92a6d] [formerly f4c2e771e3aede2acf6799e03395166d454476d4 [formerly 57420009031eeb99fbf5052067456609d2f9be27]] [formerly 53c0950807128894b75afd84ef3defe9143262f6 [formerly d29f969609e3166f3a7165f017820db29458b17e] [formerly e057112f8e183d532b2a28f8e70f53143cda3ab9 [formerly c5c8588eb1fe489fdb4230a45e2243b98d8b5c8d]]] [formerly a6195dc1213c727ec80b9de0b8ffd79f61c4f9f2 [formerly b00c8211d6a469059644de1c5b40c1e48d29375a] [formerly 983bfd73465509cc51c57925620f25c9662ddba5 [formerly 7f9c3d664c82ad06d0accb95a611a0390e51262d]] [formerly 46859aaea27e8c59ab1845f7d10f514110112dbb [formerly a50133a6f13be67201dc8d9786264efcb1f96bf1] [formerly 4f006f9bd617d33ed905c250fca64cfbc6de7f7c [formerly ce8b7b9dcaf09902c75dd62c176387fc5b27d75c]]]] [formerly 158820c68ce74f6b95f09e96f13e5eec7147b8ea [formerly 078fe0b1680b660675c006c2818ecd6fe7c63f18] [formerly be8a00be0551c1876124f396fce03b184da9dd8b [formerly b9aec02f5ebb804cc531ce91985bc1e2dcefe0ac]] [formerly 93da4a2e58bd6e1e1b1b589f0992b4a54a0260be [formerly f43d91a0158f7414b22a9547060347ddaf31b828] [formerly 93b1b4108819059c0699b0c24fc59d6d637d2d5a [formerly aa2a44a7955f35bdcb11c575203809d6a20676fb]]] [formerly afcf7f4af2ffa72f51b2b1d4eb724eb4a02d1d5f [formerly 0335c9290681cc056fc5384db50a557529649c65] [formerly 5fcd2376b0ac1a985f73aaa237a651971295b7f8 [formerly 8cfb2a238ee20b8a331c87b44fcb350f3c60c29c]] [formerly 334a3cfb8e0731b198a9860e29dc3ae561cdfe14 [formerly 26cab3616804ef23ab19a07186b1861fb13388c2] [formerly fff81b30adfd78ca7ceff9c177d9d82bdfcfae79 [formerly 6fa995f]]]]]
Former-commit-id: b67aceabfd286ecf0f4af92e7089a0f4b4337ffe [formerly 8869c7e5aefa65d9a4e55983b588dc981dffcc99] [formerly 1169a214ce80ca0a44878625657f2d4d32d169a8 [formerly 30d2a2540fcd056cb326ec3bff8137f3333cf74a]] [formerly ff306710be9719e3083e64a7077cdcb7493eb5be [formerly 98c175ea8de2bffecf26a116217b313521a93080] [formerly d9f96ec6df2190cbd9c1d43db2a68470d556e3c5 [formerly 622431049ee7ba16dca8dfb5165df61633c8d226]]] [formerly fad372a57fe3bb42a8f32bd9718d00870d5d47c3 [formerly c73bad251d981a281f9c1d88729a0344ca251f63] [formerly 0354af7b24e07855112d895df31f6a7ec70e3da4 [formerly 711377708e7d0d5c1333674b62993028457875df]] [formerly 74258e589db4d1e974cb889efbdf05c747eb4ac8 [formerly bca77f0a23adacdc008d469a87e150a88fdfd7fc] [formerly 376f8d42bf61cbce89879cca27c9433d54088390 [formerly 47b2c1a8b9e120dc7abbedc121bd26cea9fd0a9e]]]]
Former-commit-id: 1dd8b162e8bf8b4eec427e36dcea8244f3c1a42c [formerly 23f9f3c35765f409a0857797d85ab408d7b56ebf] [formerly 3d49f9c16c6a9b3f31f6feeb5b06dab25c6c6746 [formerly fa230348e2f1047777e16dc6b852a5e52063e7b3]] [formerly d6f11826f750f1df170dd39686c355a143e4292c [formerly 137e00e70ed15ed625bd4a3475758304990ba43b] [formerly eb295a2bfb653811732d6e7751df1427d1ad3fee [formerly 3cc580f404ecf2f93bda90f8c3f3e5e1fb38cc17]]]
Former-commit-id: 521e52b79c1977a443c9ec0e50a638237fcaf444 [formerly 07c2aee1b0471e94977db614528975331fa73abc] [formerly aca072728934c34aa2a2df32c6028061596af9fe [formerly a97a217c99c0a2c5ac503f23eabed8a3712c8a6c]]
Former-commit-id: 322cb81ebf77c77575ffbbcdef1d4639feb04452 [formerly 10a1e79aa5f5e42a7b66772a7627e5473d63dc6d]
Former-commit-id: b3e107aa72fc022f126f24a296a2008869ad7c6a
  • Loading branch information
gustavovalverde authored Jun 19, 2023
2 parents a7180a4 + 61ccec1 commit 106c566
Show file tree
Hide file tree
Showing 12 changed files with 434 additions and 396 deletions.
9 changes: 2 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
"@aws-amplify/ui-react-liveness": "^1.0.1",
"@aws-sdk/client-rekognition": "^3.354.0",
"@babel/core": "*",
"@babel/preset-env": "^7.1.6",
"@emotion/react": "^11.10.6",
"@emotion/styled": "^11.10.6",
"@fontsource/roboto": "^4.5.8",
"@hookform/resolvers": "2.9.7",
"@mui/icons-material": "^5.11.11",
"@mui/material": "^5.11.12",
Expand All @@ -31,15 +29,11 @@
"hibp": "^13.0.0",
"next": "13.2.3",
"next-recaptcha-v3": "^1.1.5",
"prop-types": ">=15.7.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-hook-form": "7.34.0",
"react-native": ">=0.56",
"sharp": "^0.32.1",
"sweetalert2": "11.4.8",
"typescript": "4.9.5",
"yup": "0.32.11"
"yup": "^1.2.0"
},
"devDependencies": {
"@types/cookie": "^0.5.1",
Expand All @@ -53,6 +47,7 @@
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.2.1",
"install-peers": "^1.0.4",
"prettier": ">=2.0.0"
}
}
66 changes: 33 additions & 33 deletions src/components/biometric/displayText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ export const defaultErrorDisplayText = {
timeoutHeaderText: 'Se acabó el tiempo',
timeoutMessageText:
'La cara no llenó el óvalo dentro del límite de tiempo. Vuelva a intentarlo y llene completamente el óvalo con la cara en 7 segundos.',
faceDistanceHeaderText: 'Comprobación fallida durante la cuenta atrás',
faceDistanceHeaderText: 'Comprobación fallida durante la cuenta regresiva',
faceDistanceMessageText:
'Evite acercarse durante la cuenta regresiva y asegúrese de que solo una cara esté frente a la cámara.',
'Evite acercarse durante la cuenta regresiva y asegúrese de que solo haya una cara frente a la cámara.',
clientHeaderText: 'Error del cliente',
clientMessageText: 'Verificación fallida debido a un problema con el cliente',
serverHeaderText: 'Problema del servidor',
Expand All @@ -69,54 +69,54 @@ export type ErrorDisplayTextFoo = typeof defaultErrorDisplayText;
export type ErrorDisplayText = Partial<ErrorDisplayTextFoo>;

export const defaultLivenessDisplayText: Required<LivenessDisplayText> = {
instructionsHeaderHeadingText: 'Liveness check',
instructionsHeaderHeadingText: 'Prueba de vida',
instructionsHeaderBodyText:
'You will go through a face verification process to prove that you are a real person.',
instructionsBeginCheckText: 'Begin check',
photosensitivyWarningHeadingText: 'Photosensitivity warning',
'Ahora va a realizar un proceso de verificación facial para demostrar que es una persona real.',
instructionsBeginCheckText: 'Iniciar prueba',
photosensitivyWarningHeadingText: 'Alerta de fotosensibilidad',
photosensitivyWarningBodyText:
'This check displays colored lights. Use caution if you are photosensitive.',
'Esta comprobación muestra luces de colores. Tenga cuidado si es fotosensible.',
photosensitivyWarningInfoText:
'A small percentage of individuals may experience epileptic seizures when exposed to colored lights. Use caution if you, or anyone in your family, have an epileptic condition.',
instructionListHeadingText: 'Follow the instructions to complete the check:',
goodFitCaptionText: 'Good fit',
'Un pequeño porcentaje de personas puede experimentar convulsiones epilépticas cuando se exponen a luces de colores. Tenga cuidado si usted o alguien de su familia tiene alguna condición epiléptica.',
instructionListHeadingText:
'Siga las instrucciones para completar la verificación:',
goodFitCaptionText: 'Bien encajado',
goodFitAltText:
"Ilustration of a person's face, perfectly fitting inside of an oval.",
tooFarCaptionText: 'Too far',
'Ilustración de la cara de una persona, encajando perfectamente dentro de un óvalo.',
tooFarCaptionText: 'Demasiado lejos',
tooFarAltText:
"Illustration of a person's face inside of an oval; there is a gap between the perimeter of the face and the boundaries of the oval.",
'Ilustración de la cara de una persona dentro de un óvalo; hay un espacio entre el perímetro de la cara y los límites del óvalo.',
instructionListStepOneText:
'When an oval appears, fill the oval with your face within 7 seconds.',
instructionListStepTwoText: "Maximize your screen's brightness.",
'Cuando el óvalo aparezca, llénelo con su cara en 7 segundos.',
instructionListStepTwoText: 'Maximice el brillo de su pantalla.',
instructionListStepThreeText:
'Make sure your face is not covered with sunglasses or a mask.',
'Asegúrese de que su cara no esté cubierta con gafas de sol o una máscara.',
instructionListStepFourText:
'Move to a well-lit place that is not in direct sunlight.',
'Muévase a un lugar bien iluminado que no esté expuesto a la luz solar directa.',
cameraMinSpecificationsHeadingText:
'Camera does not meet minimum specifications',
'La cámara no cumple con las especificaciones mínimas',
cameraMinSpecificationsMessageText:
'Camera must support at least 320*240 resolution and 15 frames per second.',
cameraNotFoundHeadingText: 'Camera not accessible.',
'La cámara debe admitir una resolución de al menos 320 * 240 y 15 fotogramas por segundo.',
cameraNotFoundHeadingText: 'Cámara no accesible',
cameraNotFoundMessageText:
'Verifique que la cámara esté conectada y que los permisos de la cámara estén habilitados en la configuración antes de volver a intentarlo.',
retryCameraPermissionsText: 'Procesar de nuevo',
cancelLivenessCheckText: 'Cancelar comprobación de vitalidad',
recordingIndicatorText: 'Grabación',
hintMoveFaceFrontOfCameraText: 'Mover la cara frente a la cámara',
hintTooManyFacesText:
'Asegúrese de que solo una cara esté frente a la cámara',
cancelLivenessCheckText: 'Cancelar prueba de vida',
recordingIndicatorText: 'Grabando',
hintMoveFaceFrontOfCameraText: 'Posicione la cara frente a la cámara',
hintTooManyFacesText: 'Asegúrese que solo una cara esté frente a la cámara',
hintFaceDetectedText: 'Cara detectada',
hintCanNotIdentifyText: 'Mover la cara frente a la cámara',
hintTooCloseText: 'Muévete mas atrás',
hintTooFarText: 'Muévete mas cerca',
hintCanNotIdentifyText: 'No podemos identificar su cara frente a la cámara',
hintTooCloseText: 'Muévase más atrás',
hintTooFarText: 'Muévase más cerca',
hintHoldFacePositionCountdownText:
'Mantener la posición de la cara durante la cuenta regresiva',
'Mantenga la posición de la cara durante la cuenta regresiva',
hintConnectingText: 'Conectando...',
hintVerifyingText: 'Verificando...',
hintIlluminationTooBrightText: 'Mover al área de atenuación',
hintIlluminationTooDarkText: 'Mover a un área más brillante',
hintIlluminationNormalText: 'Condiciones de iluminación normales',
hintHoldFaceForFreshnessText: 'Quédate quieto',
hintIlluminationTooBrightText: 'Muévase a un área con menos iluminación',
hintIlluminationTooDarkText: 'Muévase a un área con mayor iluminación',
hintIlluminationNormalText: 'Condiciones de iluminación correctas',
hintHoldFaceForFreshnessText: 'Quédese quieto',
...defaultErrorDisplayText,
};

Expand Down
17 changes: 9 additions & 8 deletions src/components/biometric/face-liveness-detector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Loader, ThemeProvider } from '@aws-amplify/ui-react';
import React from 'react';
import { useState, useEffect } from 'react';

import { AlertErrorMessage } from '../elements/alert';
import { useSnackbar } from '@/components/elements/alert';
import { defaultLivenessDisplayText } from './displayText';

export function LivenessQuickStartReact({ handleNextForm, cedula }: any) {
Expand All @@ -12,6 +12,7 @@ export function LivenessQuickStartReact({ handleNextForm, cedula }: any) {
const [loading, setLoading] = useState<boolean>(true);
const [error, setError] = useState<Error | null>(null);
const [sessionId, setSessionId] = useState<string | null>(null);
const { AlertError } = useSnackbar();

const fetchCreateLiveness = async () => {
const response = await fetch(`/api/biometric`, { method: 'POST' });
Expand Down Expand Up @@ -48,14 +49,14 @@ export function LivenessQuickStartReact({ handleNextForm, cedula }: any) {
});
}, []);

useEffect(() => {
if (error) {
AlertError('No se ha podido validar correctamente la identidad.');
}
}, [error, AlertError]);

return (
<>
{error && (
<AlertErrorMessage
type="info"
message="No se ha podido validar correctamente la identidad."
/>
)}
<br />
<ThemeProvider>
{loading ? (
Expand All @@ -68,7 +69,7 @@ export function LivenessQuickStartReact({ handleNextForm, cedula }: any) {
onUserCancel={onUserCancel}
onError={(error) => setError(error)}
onAnalysisComplete={handleAnalysisComplete}
disableInstructionScreen={true}
disableInstructionScreen={false}
displayText={defaultLivenessDisplayText}
/>
)
Expand Down
97 changes: 66 additions & 31 deletions src/components/elements/alert/index.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,74 @@
import Swal from 'sweetalert2';
import Alert from '@mui/material/Alert';
import React, { createContext, useContext, useState } from 'react';
import Snackbar from '@mui/material/Snackbar';
import MuiAlert, { AlertProps } from '@mui/material/Alert';

interface IPropsAlertErrorMessage {
message: string;
type: 'error' | 'warning' | 'info' | 'success';
interface SnackbarContextProps {
openSnackbar: (message: string, severity: AlertProps['severity']) => void;
}

export const AlertErrorMessage = ({
message,
type,
}: IPropsAlertErrorMessage) => <Alert severity={type}>{message}</Alert>;

export const AlertError = (text?: string) => {
return Swal.fire({
icon: 'error',
title: 'Error',
text: text ? text : 'Ocurrió un error al procesar la solicitud',
confirmButtonColor: '#003670',
});
};
// Create context with default undefined value
const SnackbarContext = createContext<SnackbarContextProps | undefined>(
undefined
);

interface SnackbarProviderProps {
children?: React.ReactNode;
}

export const AlertWarning = (text: string) => {
return Swal.fire({
icon: 'warning',
title: 'Aviso',
text: text,
confirmButtonColor: '#003670',
export const SnackbarProvider = ({ children }: SnackbarProviderProps) => {
const [snackbarConfig, setSnackbarConfig] = useState({
open: false,
message: '',
severity: 'success' as AlertProps['severity'],
});

// Open snackbar
const openSnackbar = (message: string, severity: AlertProps['severity']) => {
setSnackbarConfig({ open: true, message, severity });
};

// Close snackbar
const closeSnackbar = () => {
setSnackbarConfig((prevState) => ({ ...prevState, open: false }));
};

return (
<SnackbarContext.Provider value={{ openSnackbar }}>
<Snackbar
open={snackbarConfig.open}
autoHideDuration={6000}
onClose={closeSnackbar}
>
<MuiAlert
onClose={closeSnackbar}
severity={snackbarConfig.severity}
variant="filled"
>
{snackbarConfig.message}
</MuiAlert>
</Snackbar>
{children}
</SnackbarContext.Provider>
);
};

export const AlertSuccess = (text?: string) => {
return Swal.fire({
icon: 'success',
title: 'Correcto',
text: text ? text : 'Proceso realizado correctamente',
confirmButtonColor: '#003670',
});
export const useSnackbar = () => {
const context = useContext(SnackbarContext);

if (!context) {
throw new Error('useSnackbar must be used within a SnackbarProvider');
}

const { openSnackbar } = context;

return {
AlertError: (text?: string) =>
openSnackbar(
text || 'Ocurrió un error al procesar la solicitud',
'error'
),
AlertWarning: (text: string) => openSnackbar(text, 'warning'),
AlertSuccess: (text: string) =>
openSnackbar(text || 'Proceso realizado correctamente', 'success'),
};
};
15 changes: 8 additions & 7 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ThemeProvider } from '@mui/material/styles';
import type { AppProps } from 'next/app';
import { Amplify } from 'aws-amplify';
import { ReCaptchaProvider } from "next-recaptcha-v3";
import { SnackbarProvider } from '../components/elements/alert';
import Head from 'next/head';

import Layout from '../components/layout';
Expand All @@ -22,13 +23,13 @@ export default function App({ Component, pageProps }: AppProps) {
</Head>
<ThemeProvider theme={theme}>
<CssBaseline />
<Layout>
<ReCaptchaProvider
useEnterprise
>
<Component {...pageProps} />
</ReCaptchaProvider>
</Layout>
<SnackbarProvider>
<Layout>
<ReCaptchaProvider useEnterprise>
<Component {...pageProps} />
</ReCaptchaProvider>
</Layout>
</SnackbarProvider>
</ThemeProvider>
</>
);
Expand Down
4 changes: 2 additions & 2 deletions src/pages/register/registered/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export default function Index() {
<br />
<TextBody textCenter>
Revisa tu correo y haz clic en el enlace de confirmación, luego
podras ver, realizar tramites y solicitar servicios
gubernamentales con una sola cuenta y contraseña.
realizar tramites y solicitar servicios gubernamentales
con una sola cuenta y contraseña.
</TextBody>
<br />
</GridItem>
Expand Down
Loading

0 comments on commit 106c566

Please sign in to comment.