From 23cc2cf5676cf3619e109f973a662d45fcfe8332 Mon Sep 17 00:00:00 2001 From: kkatusic Date: Wed, 27 Nov 2024 22:41:12 +0100 Subject: [PATCH] Removing email verification from project verification form --- .../views/verification/PersonalInfo.tsx | 240 +++++------------- src/helpers/projects.ts | 12 +- 2 files changed, 77 insertions(+), 175 deletions(-) diff --git a/src/components/views/verification/PersonalInfo.tsx b/src/components/views/verification/PersonalInfo.tsx index ab1152ff8e..2f853dd58f 100644 --- a/src/components/views/verification/PersonalInfo.tsx +++ b/src/components/views/verification/PersonalInfo.tsx @@ -1,48 +1,43 @@ import { useIntl } from 'react-intl'; -import { brandColors, Button, H6, Flex } from '@giveth/ui-design-system'; -import styled from 'styled-components'; -import { useEffect, useState } from 'react'; +import { Button, H6 } from '@giveth/ui-design-system'; +import { useEffect } from 'react'; import { useForm } from 'react-hook-form'; -import { ButtonStyled, ContentSeparator, BtnContainer } from './Common.sc'; +import { ContentSeparator, BtnContainer } from './Common.sc'; import Input from '@/components/Input'; import { useVerificationData } from '@/context/verification.context'; import { client } from '@/apollo/apolloClient'; -import { - SEND_EMAIL_VERIFICATION, - UPDATE_PROJECT_VERIFICATION, -} from '@/apollo/gql/gqlVerification'; -import { getNowUnixMS } from '@/helpers/time'; -import { durationToYMDh, showToastError } from '@/lib/helpers'; -import { requiredOptions } from '@/lib/constants/regex'; +import { UPDATE_PROJECT_VERIFICATION } from '@/apollo/gql/gqlVerification'; +import { useAppSelector } from '@/features/hooks'; interface IFormInfo { name: string; walletAddress: string; - email: string; + email?: string; disabledEmail: string; } -function addZero(num: number) { - return num < 10 ? '0' + num : num; -} +// function addZero(num: number) { +// return num < 10 ? '0' + num : num; +// } const PersonalInfo = () => { - const [loading, setLoading] = useState(false); - const { verificationData, setStep, setVerificationData, isDraft } = - useVerificationData(); - const [resetMail, setResetMail] = useState(false); - const [timer, setTimer] = useState(0); - const [canReSendEmail, setCanReSendEmail] = useState(false); - const [isSentMailLoading, setIsSentMailLoading] = useState(false); + // const [loading, setLoading] = useState(false); + const { verificationData, setStep } = useVerificationData(); + // const [resetMail, setResetMail] = useState(false); + // const [timer, setTimer] = useState(0); + // const [canReSendEmail, setCanReSendEmail] = useState(false); + // const [isSentMailLoading, setIsSentMailLoading] = useState(false); const { register, handleSubmit, setValue, - getValues, + // getValues, formState: { errors }, } = useForm(); const { formatMessage } = useIntl(); + const { userData } = useAppSelector(state => state.user); + const sendPersonalInfo = async () => { return await client.mutate({ mutation: UPDATE_PROJECT_VERIFICATION, @@ -50,7 +45,7 @@ const PersonalInfo = () => { projectVerificationUpdateInput: { step: 'personalInfo', personalInfo: { - email: getValues('email'), + email: userData?.email, walletAddress: verificationData?.user?.walletAddress, fullName: verificationData?.user.firstName + @@ -62,71 +57,72 @@ const PersonalInfo = () => { }, }); }; - const sendEmail = async () => { - setLoading(true); - try { - const { data } = await client.mutate({ - mutation: SEND_EMAIL_VERIFICATION, - variables: { - projectVerificationFormId: Number(verificationData?.id), - }, - }); - setVerificationData(data.projectVerificationSendEmailConfirmation); - } catch (error: any) { - showToastError(error?.message); - } finally { - setLoading(false); - } - }; - const showMailInput = () => { - if (resetMail) { - return true; - } else if ( - verificationData?.emailConfirmed || - verificationData?.emailConfirmationSent - ) { - return false; - } else { - return true; - } - }; + // const sendEmail = async () => { + // setLoading(true); + // try { + // const { data } = await client.mutate({ + // mutation: SEND_EMAIL_VERIFICATION, + // variables: { + // projectVerificationFormId: Number(verificationData?.id), + // }, + // }); + // setVerificationData(data.projectVerificationSendEmailConfirmation); + // } catch (error: any) { + // showToastError(error?.message); + // } finally { + // setLoading(false); + // } + // }; + // const showMailInput = () => { + // if (resetMail) { + // return true; + // } else if ( + // verificationData?.emailConfirmed || + // verificationData?.emailConfirmationSent + // ) { + // return false; + // } else { + // return true; + // } + // }; const handleFormSubmit = async () => { try { - setIsSentMailLoading(true); + // setIsSentMailLoading(true); await sendPersonalInfo(); - await sendEmail(); - setResetMail(false); + // await sendEmail(); + // setResetMail(false); } catch (error) { console.error('SubmitError', error); } finally { - setIsSentMailLoading(false); + // setIsSentMailLoading(false); } }; - function handleNext() { + async function handleNext() { // if (!verificationData?.emailConfirmed) { - showToastError( - formatMessage({ id: 'label.please_confirm_your_email' }), - ); + // showToastError( + // formatMessage({ id: 'label.please_confirm_your_email' }), + // ); // } else { + await sendPersonalInfo(); setStep(2); // } } - useEffect(() => { - if (!verificationData?.emailConfirmationTokenExpiredAt) return; - const date = new Date( - verificationData?.emailConfirmationTokenExpiredAt, - ).getTime(); - const interval = setInterval(() => { - const diff = date - getNowUnixMS(); - setTimer(diff); - diff > 0 ? setCanReSendEmail(false) : setCanReSendEmail(true); - }, 1000); + // useEffect(() => { + // if (!verificationData?.emailConfirmationTokenExpiredAt) return; + // const date = new Date( + // verificationData?.emailConfirmationTokenExpiredAt, + // ).getTime(); + // const interval = setInterval(() => { + // const diff = date - getNowUnixMS(); + // setTimer(diff); + // diff > 0 ? setCanReSendEmail(false) : setCanReSendEmail(true); + // }, 1000); - return () => { - clearInterval(interval); - }; - }, [verificationData?.emailConfirmationTokenExpiredAt]); + // return () => { + // clearInterval(interval); + // }; + // }, [verificationData?.emailConfirmationTokenExpiredAt]); useEffect(() => { setValue( @@ -163,78 +159,6 @@ const PersonalInfo = () => { registerName='walletAddress' register={register} /> - - {showMailInput() ? ( - <> - - {isDraft && ( - - )} - - ) : ( - <> - - {isDraft && ( - <> - - setResetMail(true)} - label={formatMessage({ - id: 'label.change_email', - })} - /> - - )} - - )} -
@@ -257,28 +181,4 @@ const PersonalInfo = () => { ); }; -const EmailSection = styled(Flex)` - gap: 0 24px; - align-items: center; - flex-wrap: wrap; - > :first-child { - width: 100%; - min-width: 250px; - } -`; - -const LightBotton = styled(Button)` - background-color: transparent; - color: ${brandColors.deep[400]}; - &:hover { - background-color: transparent; - color: ${brandColors.deep[600]}; - } -`; - -const ResendEmailButton = styled(ButtonStyled)` - min-width: 200px; - width: 220px; -`; - export default PersonalInfo; diff --git a/src/helpers/projects.ts b/src/helpers/projects.ts index c33fa4b82f..a6d4a50e92 100644 --- a/src/helpers/projects.ts +++ b/src/helpers/projects.ts @@ -39,11 +39,13 @@ export function checkVerificationStep( case EVerificationSteps.BEFORE_START: return true; case EVerificationSteps.PERSONAL_INFO: - return ( - verificationData !== undefined && - verificationData.personalInfo !== null && - verificationData.emailConfirmed !== false - ); + // Removed because we are doing these confirmation on user profile + // return ( + // verificationData !== undefined && + // verificationData.personalInfo !== null && + // verificationData.emailConfirmed !== false + // ); + return true; case EVerificationSteps.SOCIAL_PROFILES: return ( verificationData !== undefined &&