diff --git a/src/components/Layout/Header.tsx b/src/components/Layout/Header.tsx index 39f4eb9..b2a9446 100644 --- a/src/components/Layout/Header.tsx +++ b/src/components/Layout/Header.tsx @@ -1,13 +1,14 @@ -import { Box, IconButton, Typography } from '@mui/material'; +import { Box, IconButton, Skeleton, Typography } from '@mui/material'; import { Icon } from '@rkheftan/harmony-ui'; import { More } from 'iconsax-react'; import type { User } from './type'; interface HeaderProps { user: User; + loading: boolean; } -export const Header: React.FC = ({ user }) => { +export const Header: React.FC = ({ user, loading }) => { return ( = ({ user }) => { > - {user.firstName + ' ' + user.lastName} + {loading ? ( + + ) : ( + user.firstName + ' ' + user.lastName + )} - {user.phoneNumber} + {loading ? : user.phoneNumber} diff --git a/src/components/Layout/Layout.tsx b/src/components/Layout/Layout.tsx index 2652dfe..38c38ae 100644 --- a/src/components/Layout/Layout.tsx +++ b/src/components/Layout/Layout.tsx @@ -6,6 +6,8 @@ import { Box, useMediaQuery, useTheme } from '@mui/material'; import { Header } from './Header'; import { useState } from 'react'; import { Toolbar } from './Toolbar'; +import { useApi } from '@/hooks/useApi'; +import { fetchProfile } from '@/features/profile/api/settingsApi'; import type { User } from './type'; export const Layout = () => { @@ -14,11 +16,7 @@ export const Layout = () => { const theme = useTheme(); const isMobile = useMediaQuery(theme.breakpoints.down('md')); const [sideNavOpen, setSideNavOpen] = useState(false); - const [user] = useState({ - firstName: 'محمد حسین', - lastName: 'برزه گر', - phoneNumber: '09123456789', - }); + const { data, loading } = useApi(fetchProfile, { immediate: true }); return ( { isMobile={isMobile} sideNavOpen={sideNavOpen} setSideNavOpen={setSideNavOpen} - user={user} + loading={loading} + user={{ + firstName: data?.firstName || '', + lastName: data?.lastName || '', + phoneNumber: data?.phoneNumber || '', + profileUrl: data?.profileImageUrl, + }} /> - + + + setSideNavOpen(false)} - header={isMobile ? undefined :
} - footer={isMobile ?
: undefined} + header={ + isMobile ? undefined : ( +
+ ) + } + footer={ + isMobile ? ( +
+ ) : undefined + } navConfig={navItemConfigs} activePath={location.pathname + location.hash} selectedVariant="textOnly" diff --git a/src/components/Layout/Toolbar.tsx b/src/components/Layout/Toolbar.tsx index 46b482e..a7c566f 100644 --- a/src/components/Layout/Toolbar.tsx +++ b/src/components/Layout/Toolbar.tsx @@ -3,18 +3,20 @@ import { Box, IconButton, Toolbar as MuiToolbar, - Typography, + Skeleton, } from '@mui/material'; import { Icon } from '@rkheftan/harmony-ui'; import { HambergerMenu, Menu } from 'iconsax-react'; import type { Dispatch, SetStateAction } from 'react'; import type { User } from './type'; +import Logo from '../Logo'; interface ToolbarProps { sideNavOpen: boolean; setSideNavOpen: Dispatch>; isMobile: boolean; user: User; + loading: boolean; } export const Toolbar: React.FC = ({ @@ -22,6 +24,7 @@ export const Toolbar: React.FC = ({ setSideNavOpen, isMobile, user, + loading, }) => { return ( = ({ )} - {/* */} - LOGO placeholder + - {isMobile && ( - - {user.firstName.charAt(0) + ' ' + user.lastName.charAt(0)} - - )} + {isMobile && + (loading ? ( + + ) : ( + + {user.firstName.charAt(0) + ' ' + user.lastName.charAt(0)} + + ))} diff --git a/src/features/profile/api/settingsApi.ts b/src/features/profile/api/settingsApi.ts index 4cb45a7..bec087f 100644 --- a/src/features/profile/api/settingsApi.ts +++ b/src/features/profile/api/settingsApi.ts @@ -15,7 +15,7 @@ import { import { type InfoRowData } from '../types/settingsType'; export async function fetchProfile() { - return apiClient.post('/Profile/GetProfile'); + return apiClient.post('/Profile/GetProfile', {}); } export async function saveProfile(payload: { diff --git a/src/routes/config.tsx b/src/routes/config.tsx index 1aa145c..6eef082 100644 --- a/src/routes/config.tsx +++ b/src/routes/config.tsx @@ -1,15 +1,4 @@ import { Layout } from '@/components'; -import { - AuthenticationPage, - ForgetPasswordPage, - UserCompletionPage, -} from '@/features/authorization'; -import { - ActiveDevicesPage, - SecurityPage, - SettingPage, - UserInformationPage, -} from '@/features/profile'; import { Calendar, Devices, @@ -23,9 +12,45 @@ import { Sms, type Icon, } from 'iconsax-react'; -import { type ReactNode } from 'react'; +import { lazy, type ReactNode } from 'react'; import { Navigate } from 'react-router-dom'; +const AuthenticationPage = lazy(() => + import('@/features/authorization').then((module) => ({ + default: module.AuthenticationPage, + })), +); +const UserCompletionPage = lazy(() => + import('@/features/authorization').then((module) => ({ + default: module.UserCompletionPage, + })), +); +const ForgetPasswordPage = lazy(() => + import('@/features/authorization').then((module) => ({ + default: module.ForgetPasswordPage, + })), +); +const UserInformationPage = lazy(() => + import('@/features/profile').then((module) => ({ + default: module.UserInformationPage, + })), +); +const SecurityPage = lazy(() => + import('@/features/profile').then((module) => ({ + default: module.SecurityPage, + })), +); +const ActiveDevicesPage = lazy(() => + import('@/features/profile').then((module) => ({ + default: module.ActiveDevicesPage, + })), +); +const SettingPage = lazy(() => + import('@/features/profile').then((module) => ({ + default: module.SettingPage, + })), +); + export interface RouteConfig { path: string; element?: ReactNode;