mirror of
https://github.com/sergeyyarkov/educt-client.git
synced 2026-10-11 18:29:15 +03:00
feat: default value for status page & fullname field for user
This commit is contained in:
parent
f29f87ef6b
commit
204889fa3a
@ -33,15 +33,15 @@ const UserInfo: React.FC = () => {
|
|||||||
<Menu>
|
<Menu>
|
||||||
<MenuButton as={Button} pr={6}>
|
<MenuButton as={Button} pr={6}>
|
||||||
<Flex alignItems='center'>
|
<Flex alignItems='center'>
|
||||||
<Avatar size='sm' name={`${userStore.me.first_name} ${userStore.me.last_name}`} marginRight={3} />
|
<Avatar size='sm' name={userStore.me.fullname} marginRight={3} />
|
||||||
<Text as='span' mr={2}>
|
<Text as='span' mr={2}>
|
||||||
{`${userStore.me.first_name} ${userStore.me.last_name}`}
|
{userStore.me.fullname}
|
||||||
</Text>
|
</Text>
|
||||||
<UserBadge roles={userStore.me.roles} />
|
<UserBadge roles={userStore.me.roles} />
|
||||||
</Flex>
|
</Flex>
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
<MenuList mr='1rem'>
|
<MenuList mr='1rem'>
|
||||||
<MenuGroup title={`${userStore.me.first_name} ${userStore.me.last_name}`}>
|
<MenuGroup title={userStore.me.fullname}>
|
||||||
<MenuDivider />
|
<MenuDivider />
|
||||||
<Link to='/profile'>
|
<Link to='/profile'>
|
||||||
<MenuItem>
|
<MenuItem>
|
||||||
|
|||||||
@ -5,6 +5,6 @@ import RootStore from '../stores/RootStore';
|
|||||||
export const StoreContext = React.createContext<RootStore | undefined>(undefined);
|
export const StoreContext = React.createContext<RootStore | undefined>(undefined);
|
||||||
|
|
||||||
export const ProfilePageViewContext = React.createContext<ProfilePageViewStatusContextType>({
|
export const ProfilePageViewContext = React.createContext<ProfilePageViewStatusContextType>({
|
||||||
statusPageView: undefined,
|
statusPageView: 'default',
|
||||||
setStatusPageView: () => {},
|
setStatusPageView: () => {},
|
||||||
});
|
});
|
||||||
|
|||||||
@ -13,6 +13,7 @@ export interface IAppConfig {
|
|||||||
|
|
||||||
export interface IUser {
|
export interface IUser {
|
||||||
id: string;
|
id: string;
|
||||||
|
fullname: string;
|
||||||
first_name: string;
|
first_name: string;
|
||||||
last_name: string;
|
last_name: string;
|
||||||
email: string;
|
email: string;
|
||||||
|
|||||||
@ -14,7 +14,7 @@ const UpdatePasswordContainer: React.FC = () => {
|
|||||||
aria-label='Back'
|
aria-label='Back'
|
||||||
borderRadius='full'
|
borderRadius='full'
|
||||||
icon={<ChevronLeftIcon />}
|
icon={<ChevronLeftIcon />}
|
||||||
onClick={() => setStatusPageView(undefined)}
|
onClick={() => setStatusPageView('default')}
|
||||||
mr='5'
|
mr='5'
|
||||||
/>
|
/>
|
||||||
<Heading as='h1'>Update password</Heading>
|
<Heading as='h1'>Update password</Heading>
|
||||||
|
|||||||
@ -41,7 +41,7 @@ const UpdatePasswordForm: React.FC = () => {
|
|||||||
await userStore.updateCurrentUserPassword(old_password, new_password);
|
await userStore.updateCurrentUserPassword(old_password, new_password);
|
||||||
toast({ title: 'Password changed.', status: 'success' });
|
toast({ title: 'Password changed.', status: 'success' });
|
||||||
reset();
|
reset();
|
||||||
setStatusPageView(undefined);
|
setStatusPageView('default');
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
if (error.response) {
|
if (error.response) {
|
||||||
if (error.response.status === 401) {
|
if (error.response.status === 401) {
|
||||||
|
|||||||
@ -28,7 +28,7 @@ import UpdatePasswordContainer from './containers/UpdatePasswordContainer';
|
|||||||
* Profile page
|
* Profile page
|
||||||
*/
|
*/
|
||||||
const ProfilePage: React.FC<IPageProps> = () => {
|
const ProfilePage: React.FC<IPageProps> = () => {
|
||||||
const [statusPageView, setStatusPageView] = useState<ProfilePageStatusType>(undefined);
|
const [statusPageView, setStatusPageView] = useState<ProfilePageStatusType>('default');
|
||||||
const { colorMode } = useColorMode();
|
const { colorMode } = useColorMode();
|
||||||
const { userStore, authStore } = useRootStore();
|
const { userStore, authStore } = useRootStore();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
@ -45,7 +45,7 @@ const ProfilePage: React.FC<IPageProps> = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<ProfilePageViewContext.Provider value={{ statusPageView, setStatusPageView }}>
|
<ProfilePageViewContext.Provider value={{ statusPageView, setStatusPageView }}>
|
||||||
{statusPageView === undefined && (
|
{statusPageView === 'default' && (
|
||||||
<Box maxW='900px'>
|
<Box maxW='900px'>
|
||||||
<Heading as='h1'>My account</Heading>
|
<Heading as='h1'>My account</Heading>
|
||||||
<Flex
|
<Flex
|
||||||
@ -64,7 +64,7 @@ const ProfilePage: React.FC<IPageProps> = () => {
|
|||||||
<Avatar
|
<Avatar
|
||||||
border={`4px solid ${colorMode === 'dark' ? '#2D3748' : '#E2E8F0'}`}
|
border={`4px solid ${colorMode === 'dark' ? '#2D3748' : '#E2E8F0'}`}
|
||||||
size='2xl'
|
size='2xl'
|
||||||
name={`${userStore.me.first_name} ${userStore.me.last_name}`}
|
name={userStore.me.fullname}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
<Flex
|
<Flex
|
||||||
@ -77,7 +77,7 @@ const ProfilePage: React.FC<IPageProps> = () => {
|
|||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Heading as='h2'>{`${userStore.me.first_name} ${userStore.me.last_name}`}</Heading>
|
<Heading as='h2'>{userStore.me.fullname}</Heading>
|
||||||
<Flex
|
<Flex
|
||||||
alignItems='center'
|
alignItems='center'
|
||||||
sx={{
|
sx={{
|
||||||
|
|||||||
@ -30,9 +30,20 @@ export default class UserStore {
|
|||||||
public async loadCurrentUserData(): Promise<IUserResult> {
|
public async loadCurrentUserData(): Promise<IUserResult> {
|
||||||
try {
|
try {
|
||||||
const result = await this.userService.fetchMe();
|
const result = await this.userService.fetchMe();
|
||||||
|
const {
|
||||||
|
data: { id, first_name, last_name, email, roles, contacts },
|
||||||
|
} = result;
|
||||||
|
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
this.me = result.data;
|
this.me = {
|
||||||
|
id,
|
||||||
|
fullname: `${first_name} ${last_name}`,
|
||||||
|
first_name,
|
||||||
|
last_name,
|
||||||
|
email,
|
||||||
|
roles,
|
||||||
|
contacts,
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
2
src/types/index.d.ts
vendored
2
src/types/index.d.ts
vendored
@ -7,7 +7,7 @@ export type LinkType = {
|
|||||||
icon: IconType;
|
icon: IconType;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ProfilePageStatusType = 'update-password' | 'update-email' | undefined;
|
export type ProfilePageStatusType = 'update-password' | 'update-email' | 'default';
|
||||||
export type ProfilePageViewStatusContextType = {
|
export type ProfilePageViewStatusContextType = {
|
||||||
statusPageView: ProfilePageStatusType;
|
statusPageView: ProfilePageStatusType;
|
||||||
setStatusPageView: React.Dispatch<React.SetStateAction<ProfilePageStatusType>>;
|
setStatusPageView: React.Dispatch<React.SetStateAction<ProfilePageStatusType>>;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user