diff --git a/src/interfaces/index.ts b/src/interfaces/index.ts index df1ea68..8724a17 100644 --- a/src/interfaces/index.ts +++ b/src/interfaces/index.ts @@ -53,7 +53,7 @@ export interface IUpdatedContactsResult extends IDataResult { } export interface IUserResult extends IDataResult { - data: IUser; + data: Omit; } export interface IPageProps extends RouteComponentProps { diff --git a/src/pages/profile/components/UserAccountInfo/UserAccountInfo.tsx b/src/pages/profile/components/UserAccountInfo/UserAccountInfo.tsx index 6877836..3e3b962 100644 --- a/src/pages/profile/components/UserAccountInfo/UserAccountInfo.tsx +++ b/src/pages/profile/components/UserAccountInfo/UserAccountInfo.tsx @@ -9,6 +9,7 @@ type UserAccountInfoPropsType = { const UserAccountInfo: React.FC = ({ user }) => { const { setStatusPageView } = useContext(ProfilePageViewContext); + return ( @@ -44,7 +45,7 @@ const UserAccountInfo: React.FC = ({ user }) => { {user.email} - + diff --git a/src/pages/profile/containers/UpdateEmailContainer/UpdateEmailContainer.tsx b/src/pages/profile/containers/UpdateEmailContainer/UpdateEmailContainer.tsx new file mode 100644 index 0000000..3bb60f9 --- /dev/null +++ b/src/pages/profile/containers/UpdateEmailContainer/UpdateEmailContainer.tsx @@ -0,0 +1,31 @@ +import { IconButton } from '@chakra-ui/button'; +import { ChevronLeftIcon } from '@chakra-ui/icons'; +import { Box, Flex, Heading, Text } from '@chakra-ui/layout'; +import { ProfilePageViewContext } from 'contexts'; +import React, { useContext } from 'react'; +import UpdateEmailForm from './UpdateEmailForm'; + +const UpdateEmailContainer: React.FC = () => { + const { setStatusPageView } = useContext(ProfilePageViewContext); + + return ( + + + } + onClick={() => setStatusPageView('default')} + mr='5' + /> + Edit email address + + + Type your new email address. + + + + ); +}; + +export default UpdateEmailContainer; diff --git a/src/pages/profile/containers/UpdateEmailContainer/UpdateEmailForm/UpdateEmailForm.tsx b/src/pages/profile/containers/UpdateEmailContainer/UpdateEmailForm/UpdateEmailForm.tsx new file mode 100644 index 0000000..37d2bdd --- /dev/null +++ b/src/pages/profile/containers/UpdateEmailContainer/UpdateEmailForm/UpdateEmailForm.tsx @@ -0,0 +1,58 @@ +import { Button } from '@chakra-ui/button'; +import { FormControl, FormHelperText, FormLabel } from '@chakra-ui/form-control'; +import { Input } from '@chakra-ui/input'; +import { Box, Stack } from '@chakra-ui/layout'; +import { yupResolver } from '@hookform/resolvers/yup'; +import { useRootStore } from 'hooks/useRootStore'; +import React from 'react'; +import { SubmitHandler, useForm } from 'react-hook-form'; +import UpdateEmailSchema from './UpdateEmailForm.validator'; + +type UpdateEmailInputType = { + email: string; +}; + +/** + * Update email using form + */ +const UpdateEmailForm: React.FC = () => { + const { + userStore: { me }, + } = useRootStore(); + const { + handleSubmit, + register, + formState: { errors }, + } = useForm({ + resolver: yupResolver(UpdateEmailSchema), + }); + + const onSubmit: SubmitHandler = async data => { + console.log(data); + }; + + return ( + +
+ + + Current email + + + + New email + + + {errors.email ? errors.email.message : 'A confirmation 4-digit code will be sent to this address.'} + + + + +
+
+ ); +}; + +export default UpdateEmailForm; diff --git a/src/pages/profile/containers/UpdateEmailContainer/UpdateEmailForm/UpdateEmailForm.validator.ts b/src/pages/profile/containers/UpdateEmailContainer/UpdateEmailForm/UpdateEmailForm.validator.ts new file mode 100644 index 0000000..4faf108 --- /dev/null +++ b/src/pages/profile/containers/UpdateEmailContainer/UpdateEmailForm/UpdateEmailForm.validator.ts @@ -0,0 +1,7 @@ +import yup from 'schema'; + +const UpdateEmailSchema = yup.object().shape({ + email: yup.string().required('Email address is required.').email('Please type your email correctly.'), +}); + +export default UpdateEmailSchema; diff --git a/src/pages/profile/containers/UpdateEmailContainer/UpdateEmailForm/index.ts b/src/pages/profile/containers/UpdateEmailContainer/UpdateEmailForm/index.ts new file mode 100644 index 0000000..544e5d4 --- /dev/null +++ b/src/pages/profile/containers/UpdateEmailContainer/UpdateEmailForm/index.ts @@ -0,0 +1,3 @@ +import UpdateEmailForm from './UpdateEmailForm'; + +export default UpdateEmailForm; diff --git a/src/pages/profile/containers/UpdateEmailContainer/index.ts b/src/pages/profile/containers/UpdateEmailContainer/index.ts new file mode 100644 index 0000000..818243b --- /dev/null +++ b/src/pages/profile/containers/UpdateEmailContainer/index.ts @@ -0,0 +1,3 @@ +import UpdateEmailContainer from './UpdateEmailContainer'; + +export default UpdateEmailContainer; diff --git a/src/pages/profile/index.tsx b/src/pages/profile/index.tsx index 248c812..ad8c668 100644 --- a/src/pages/profile/index.tsx +++ b/src/pages/profile/index.tsx @@ -23,6 +23,7 @@ import LoadingPage from './components/LoadingPage'; import UserAccountInfo from './components/UserAccountInfo'; import UpdateUserContactsForm from './components/UpdateUserContactsForm'; import UpdatePasswordContainer from './containers/UpdatePasswordContainer'; +import UpdateEmailContainer from './containers/UpdateEmailContainer'; /** * Profile page @@ -120,6 +121,7 @@ const ProfilePage: React.FC = () => {
)} {statusPageView === 'update-password' && } + {statusPageView === 'update-email' && } ); };