From ff128ae1e1ae49386354eb5fd4a197b757ac64e6 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Thu, 30 Mar 2023 21:11:34 +0530 Subject: [PATCH] added delete feedback form --- src/components/DeleteAccountModal.tsx | 208 ++++++++++++++++++-------- 1 file changed, 144 insertions(+), 64 deletions(-) diff --git a/src/components/DeleteAccountModal.tsx b/src/components/DeleteAccountModal.tsx index 0e462137d..64ec6a831 100644 --- a/src/components/DeleteAccountModal.tsx +++ b/src/components/DeleteAccountModal.tsx @@ -1,18 +1,7 @@ -import NoAccountsIcon from '@mui/icons-material/NoAccountsOutlined'; -import TickIcon from '@mui/icons-material/Done'; -import { - Dialog, - DialogContent, - Typography, - Button, - Stack, - Link, -} from '@mui/material'; +import { Button, Link, Stack } from '@mui/material'; import { AppContext } from 'pages/_app'; -import React, { useContext, useEffect, useState } from 'react'; +import { useContext, useEffect, useState } from 'react'; import { preloadImage, initiateEmail } from 'utils/common'; -import VerticallyCentered from './Container'; -import DialogTitleWithCloseButton from './DialogBox/TitleWithCloseButton'; import { deleteAccount, getAccountDeleteChallenge, @@ -23,12 +12,63 @@ import { logError } from 'utils/sentry'; import { decryptDeleteAccountChallenge } from 'utils/crypto'; import { Trans } from 'react-i18next'; import { t } from 'i18next'; -import { DELETE_ACCOUNT_EMAIL, FEEDBACK_EMAIL } from 'constants/urls'; +import { DELETE_ACCOUNT_EMAIL } from 'constants/urls'; +import DialogBoxV2 from './DialogBoxV2'; +import * as Yup from 'yup'; +import { Formik, FormikHelpers } from 'formik'; +import DropdownInput, { DropdownOption } from './DropdownInput'; +import MultilineInput from './MultilineInput'; +import { CheckboxInput } from './CheckboxInput'; interface Iprops { onClose: () => void; open: boolean; } + +interface FormValues { + reason: string; + feedback: string; +} + +enum DELETE_REASON { + MISSING_FEATURE = '0', + BROKEN_BEHAVIOR = '1', + FOUND_ANOTHER_SERVICE = '2', + USING_DIFFERENT_ACCOUNT = '3', + NOT_LISTED = '4', +} + +const getReasonOptions = (): DropdownOption[] => { + return [ + { + label: t('DELETE_REASON.MISSING_FEATURE'), + value: DELETE_REASON.MISSING_FEATURE, + }, + { + label: t('DELETE_REASON.BROKEN_BEHAVIOR'), + value: DELETE_REASON.BROKEN_BEHAVIOR, + }, + { + label: t('DELETE_REASON.FOUND_ANOTHER_SERVICE'), + value: DELETE_REASON.FOUND_ANOTHER_SERVICE, + }, + { + label: t('DELETE_REASON.USING_DIFFERENT_ACCOUNT'), + value: DELETE_REASON.USING_DIFFERENT_ACCOUNT, + }, + { + label: t('DELETE_REASON.NOT_LISTED'), + value: DELETE_REASON.NOT_LISTED, + }, + ]; +}; + +const REASON_WITH_REQUIRED_FEEDBACK = new Set([ + DELETE_REASON.MISSING_FEATURE, + DELETE_REASON.BROKEN_BEHAVIOR, + DELETE_REASON.NOT_LISTED, +]); + const DeleteAccountModal = ({ open, onClose }: Iprops) => { const { setDialogMessage, isMobile } = useContext(AppContext); const [authenticateUserModalView, setAuthenticateUserModalView] = @@ -38,13 +78,12 @@ const DeleteAccountModal = ({ open, onClose }: Iprops) => { const openAuthenticateUserModal = () => setAuthenticateUserModalView(true); const closeAuthenticateUserModal = () => setAuthenticateUserModalView(false); + const [acceptDataDeletion, setAcceptDataDeletion] = useState(false); useEffect(() => { preloadImage('/images/delete-account'); }, []); - const sendFeedbackMail = () => initiateEmail('feedback@ente.io'); - const somethingWentWrong = () => setDialogMessage({ title: t('ERROR'), @@ -52,8 +91,19 @@ const DeleteAccountModal = ({ open, onClose }: Iprops) => { content: t('UNKNOWN_ERROR'), }); - const initiateDelete = async () => { + const initiateDelete = async ( + { reason, feedback }: FormValues, + { setFieldError }: FormikHelpers + ) => { try { + console.log({ reason, feedback }); + if ( + REASON_WITH_REQUIRED_FEEDBACK.has(reason as DELETE_REASON) && + !feedback?.length + ) { + setFieldError('feedback', t('REQUIRED')); + return; + } const deleteChallengeResponse = await getAccountDeleteChallenge(); setDeleteAccountChallenge( deleteChallengeResponse.encryptedChallenge @@ -120,56 +170,86 @@ const DeleteAccountModal = ({ open, onClose }: Iprops) => { return ( <> - - - - {t('DELETE_ACCOUNT')} - - - - - - - - - , - }} - values={{ emailID: FEEDBACK_EMAIL }} - /> - - - - - - - - + fullScreen={isMobile} + attributes={{ + title: t('DELETE_ACCOUNT'), + secondary: { + action: onClose, + text: t('CANCEL'), + }, + }}> + + initialValues={{ + reason: '', + feedback: '', + }} + validationSchema={Yup.object().shape({ + reason: Yup.string().required(t('REQUIRED')), + })} + validateOnChange={false} + validateOnBlur={false} + onSubmit={initiateDelete}> + {({ + values, + errors, + handleChange, + handleSubmit, + }): JSX.Element => ( +
+ + + + + + + + + +
+ )} + +