Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing email verification from project verification form #4880

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
240 changes: 70 additions & 170 deletions src/components/views/verification/PersonalInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,56 +1,51 @@
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<IFormInfo>();
const { formatMessage } = useIntl();

const { userData } = useAppSelector(state => state.user);

const sendPersonalInfo = async () => {
return await client.mutate({
mutation: UPDATE_PROJECT_VERIFICATION,
variables: {
projectVerificationUpdateInput: {
step: 'personalInfo',
personalInfo: {
email: getValues('email'),
email: userData?.email,
walletAddress: verificationData?.user?.walletAddress,
fullName:
verificationData?.user.firstName +
Expand All @@ -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(
Expand Down Expand Up @@ -163,78 +159,6 @@ const PersonalInfo = () => {
registerName='walletAddress'
register={register}
/>
<EmailSection>
{showMailInput() ? (
<>
<Input
key='1'
label={formatMessage({
id: 'page.verification.personal_info.three',
})}
registerName='email'
register={register}
registerOptions={requiredOptions.email}
error={errors.email}
autoFocus
/>
{isDraft && (
<ButtonStyled
loading={loading}
color={brandColors.giv[500]}
label={formatMessage({
id: 'label.verify_email_address',
})}
size='small'
type='submit'
/>
)}
</>
) : (
<>
<Input
key='2'
label={formatMessage({
id: 'page.verification.personal_info.three',
})}
registerName='email'
register={register}
disabled
/>
{isDraft && (
<>
<ResendEmailButton
color={brandColors.giv[500]}
label={
canReSendEmail || timer === 0
? formatMessage({
id: 'label.resend_email',
})
: `${formatMessage({
id: 'label.resend_email_in',
})} ${addZero(
durationToYMDh(timer)
.min,
)} : ${addZero(
durationToYMDh(timer)
.sec,
)}`
}
size='small'
onClick={handleFormSubmit}
disabled={!canReSendEmail}
loading={isSentMailLoading}
/>
<LightBotton
onClick={() => setResetMail(true)}
label={formatMessage({
id: 'label.change_email',
})}
/>
</>
)}
</>
)}
</EmailSection>
</div>
<div>
<ContentSeparator />
Expand All @@ -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;
12 changes: 7 additions & 5 deletions src/helpers/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
Loading