From 4069ac5b45a9145b99f9823bdc3e6305785e386e Mon Sep 17 00:00:00 2001 From: Sergey Yarkov Date: Fri, 4 Feb 2022 22:46:46 +0300 Subject: [PATCH] refactor: profile page --- .../SwitchDarkThemeButton/index.tsx | 10 - .../UserProfile/Settings/Fields/index.tsx | 196 +++++++++++++ .../UserProfile/Settings/Settings.tsx | 71 ++++- .../Settings/Settings.validator.ts | 26 ++ .../Settings/SettingsContextProvider.tsx | 71 +++++ .../UserProfile/Settings/context.ts | 26 ++ src/pages/profile/profile.tsx | 266 ++++-------------- 7 files changed, 433 insertions(+), 233 deletions(-) delete mode 100644 src/components/SwitchDarkThemeButton/index.tsx create mode 100644 src/components/UserProfile/Settings/Fields/index.tsx create mode 100644 src/components/UserProfile/Settings/Settings.validator.ts create mode 100644 src/components/UserProfile/Settings/SettingsContextProvider.tsx create mode 100644 src/components/UserProfile/Settings/context.ts diff --git a/src/components/SwitchDarkThemeButton/index.tsx b/src/components/SwitchDarkThemeButton/index.tsx deleted file mode 100644 index 843d9ed..0000000 --- a/src/components/SwitchDarkThemeButton/index.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import React from 'react'; -import { Switch, SwitchProps, useColorMode } from '@chakra-ui/react'; - -const SwitchDarkThemeButton: React.FC = props => { - const { colorMode, toggleColorMode } = useColorMode(); - - return ; -}; - -export { SwitchDarkThemeButton }; diff --git a/src/components/UserProfile/Settings/Fields/index.tsx b/src/components/UserProfile/Settings/Fields/index.tsx new file mode 100644 index 0000000..d810b4a --- /dev/null +++ b/src/components/UserProfile/Settings/Fields/index.tsx @@ -0,0 +1,196 @@ +import React from 'react'; +import { + Box, + FormControl, + FormHelperText, + FormLabel, + Input, + InputGroup, + InputRightElement, + InputProps, + Button, + Textarea, + Text, + TextareaProps, + Select, + SelectProps, + Switch, + SwitchProps, + ButtonProps, +} from '@chakra-ui/react'; +import { SaveButton } from '@educt/components/Buttons'; + +/** + * Hooks + */ +import { useColorMode } from '@chakra-ui/react'; +import { useSettingsContext } from '../context'; +import { useHistory } from 'react-router-dom'; + +const InputWithButton: React.FC< + InputProps & { buttonText?: string | undefined; buttonHandler?: () => void } +> = props => { + const { buttonText, buttonHandler, ...inputProps } = props; + + return ( + + + + + + + ); +}; + +export const FullnameInput: React.FC = props => ( + + Fullname + + +); + +export const EmailInput: React.FC = props => { + const history = useHistory(); + + const onChangeEmail = () => history.push(`/profile/change-email`); + + return ( + + Email + + + ); +}; + +export const AboutInput: React.FC = props => { + const { + form: { + register, + formState: { errors }, + }, + } = useSettingsContext(); + + return ( + + About +