From 6017803cee1cb1221d73f5bfcd784407afff9139 Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Fri, 24 Nov 2023 15:34:24 +0100 Subject: [PATCH] :sparkles: Verify sms request working --- src/front/Api/Auth/Customer/Auth.ts | 29 ++++++++++++++++ .../Layouts/LoginCustomer/index.tsx | 33 ++++++++++++++++--- 2 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 src/front/Api/Auth/Customer/Auth.ts diff --git a/src/front/Api/Auth/Customer/Auth.ts b/src/front/Api/Auth/Customer/Auth.ts new file mode 100644 index 00000000..7d0481f2 --- /dev/null +++ b/src/front/Api/Auth/Customer/Auth.ts @@ -0,0 +1,29 @@ +import BaseApiService from "@Front/Api/BaseApiService"; + +export type IMailVerifyParams = { + email: string; +}; + +export type IMailVerifyReturn = { + partialPhoneNumber: string; +}; + +export default class Auth extends BaseApiService { + private static instance: Auth; + protected readonly namespaceUrl = this.getBaseUrl().concat("/customer"); + private readonly baseURl = this.namespaceUrl.concat("/auth"); + + public static getInstance() { + return (this.instance ??= new this()); + } + + public async mailVerifySms(body: IMailVerifyParams): Promise { + const url = new URL(this.baseURl.concat("/mail/verify-sms")); + try { + return this.postRequest(url, body); + } catch (err) { + this.onError(err); + return Promise.reject(err); + } + } +} diff --git a/src/front/Components/Layouts/LoginCustomer/index.tsx b/src/front/Components/Layouts/LoginCustomer/index.tsx index fb386de1..384f59fd 100644 --- a/src/front/Components/Layouts/LoginCustomer/index.tsx +++ b/src/front/Components/Layouts/LoginCustomer/index.tsx @@ -8,15 +8,17 @@ import { useCallback, useEffect, useState } from "react"; import Customers from "@Front/Api/Auth/Id360/Customers/Customers"; import classes from "./classes.module.scss"; import LandingImage from "./landing-connect.jpeg"; -import Link from "next/link"; import Confirm from "@Front/Components/DesignSystem/Modal/Confirm"; import Form from "@Front/Components/DesignSystem/Form"; import TextField from "@Front/Components/DesignSystem/Form/TextField"; +import Module from "@Front/Config/Module"; +import { ValidationError } from "class-validator"; +import Auth from "@Front/Api/Auth/Customer/Auth"; export default function Login() { const router = useRouter(); const error = router.query["error"]; - + const [validationError, setValidationError] = useState([]); const [isErrorModalOpen, setIsErrorModalOpen] = useState(false); const redirectCustomerOnConnection = useCallback(() => { @@ -43,6 +45,25 @@ export default function Login() { if (error === "1") openErrorModal(); }, [error, openErrorModal]); + const onSubmitHandler = useCallback( + async (e: React.FormEvent | null, values: { [key: string]: string }) => { + try { + console.log(values); + if (!values["email"]) return; + const phoneNumber = await Auth.getInstance().mailVerifySms({ email: values["email"] }); + /* router.push( + Module.getInstance().get().modules.pages.DeedTypes.pages.DeedTypesInformations.props.path.replace("[uid]", "1"), + ); */ + } catch (validationErrors: Array | any) { + console.log(validationErrors); + if (validationErrors.length > 0) { + setValidationError(validationErrors as ValidationError[]); + } + return; + } + }, + [router], + ); return (
@@ -55,8 +76,12 @@ export default function Login() { Ou -
- + + error.property === "email")} + />