1408
package-lock.json
generated
1408
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -15,13 +15,16 @@
|
|||||||
"@emotion/styled": "^11.14.1",
|
"@emotion/styled": "^11.14.1",
|
||||||
"@mui/material": "^7.2.0",
|
"@mui/material": "^7.2.0",
|
||||||
"@mui/stylis-plugin-rtl": "^7.2.0",
|
"@mui/stylis-plugin-rtl": "^7.2.0",
|
||||||
"@rkheftan/harmony-ui": "^0.1.5",
|
"@rkheftan/harmony-ui": "^0.1.6",
|
||||||
|
"@types/stylis": "^4.2.7",
|
||||||
"i18next": "^25.3.0",
|
"i18next": "^25.3.0",
|
||||||
"i18next-browser-languagedetector": "^8.2.0",
|
"i18next-browser-languagedetector": "^8.2.0",
|
||||||
"i18next-http-backend": "^3.0.2",
|
"i18next-http-backend": "^3.0.2",
|
||||||
|
"iconsax-react": "^0.0.8",
|
||||||
"react": "^19.1.0",
|
"react": "^19.1.0",
|
||||||
"react-dom": "^19.1.0",
|
"react-dom": "^19.1.0",
|
||||||
"react-i18next": "^15.6.0",
|
"react-i18next": "^15.6.0",
|
||||||
|
"react-router-dom": "^7.8.0",
|
||||||
"stylis": "^4.3.6",
|
"stylis": "^4.3.6",
|
||||||
"stylis-plugin-rtl": "^2.1.1"
|
"stylis-plugin-rtl": "^2.1.1"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,3 +1,14 @@
|
|||||||
{
|
{
|
||||||
"helloWorld": "سلام دنیا"
|
"side": {
|
||||||
|
"account": "حساب کاربری",
|
||||||
|
"personalInfo": "اطلاعات شخصی",
|
||||||
|
"contactInfo": "شماره تماس",
|
||||||
|
"email": "ایمیل",
|
||||||
|
"security": "امنیت",
|
||||||
|
"password": "رمز عبور",
|
||||||
|
"confirmedIps": "آدرس های تایید شده",
|
||||||
|
"recentSessions": "ورود های اخیر",
|
||||||
|
"activeSessions": "نشست های فعال",
|
||||||
|
"setting": "تنظیمات"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
61
src/App.tsx
61
src/App.tsx
@@ -1,68 +1,17 @@
|
|||||||
import {
|
import { CssBaseline } from '@mui/material';
|
||||||
Alert,
|
|
||||||
Box,
|
|
||||||
CssBaseline,
|
|
||||||
TextField,
|
|
||||||
Typography,
|
|
||||||
useColorScheme,
|
|
||||||
} from '@mui/material';
|
|
||||||
import './App.css';
|
import './App.css';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { LanguageManager } from '@/components/LanguageManager';
|
||||||
import { LanguageManager } from './components/LanguageManager';
|
import { RouterProvider } from 'react-router-dom';
|
||||||
|
import { router } from '@/routes';
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const { t } = useTranslation();
|
|
||||||
const showToast = useToast();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<CssBaseline />
|
<CssBaseline />
|
||||||
<LanguageManager />
|
<LanguageManager />
|
||||||
<div style={{ padding: '16px' }}>
|
<RouterProvider router={router} />
|
||||||
<Typography variant="h3">{t('helloWorld')}</Typography>
|
|
||||||
<Box
|
|
||||||
sx={{ display: 'flex', flexDirection: 'column', gap: '10px', mt: 5 }}
|
|
||||||
>
|
|
||||||
<ThemeToggleButton />
|
|
||||||
<Button color="secondary" variant="contained">
|
|
||||||
secondary button
|
|
||||||
</Button>
|
|
||||||
<TextField label={t('helloWorld')} />
|
|
||||||
<Alert severity="success" variant="filled">
|
|
||||||
success
|
|
||||||
</Alert>
|
|
||||||
<Alert severity="warning" variant="filled">
|
|
||||||
warning
|
|
||||||
</Alert>
|
|
||||||
<Alert severity="info" variant="filled">
|
|
||||||
info
|
|
||||||
</Alert>
|
|
||||||
<Alert severity="error" variant="filled">
|
|
||||||
error
|
|
||||||
</Alert>
|
|
||||||
</Box>
|
|
||||||
</div>
|
|
||||||
<Button onClick={() => showToast({ message: 'info toast' })}>
|
|
||||||
toast
|
|
||||||
</Button>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default App;
|
export default App;
|
||||||
|
|
||||||
import { Button } from '@mui/material';
|
|
||||||
import { useToast } from '@rkheftan/harmony-ui';
|
|
||||||
|
|
||||||
export const ThemeToggleButton = () => {
|
|
||||||
const { mode, setMode } = useColorScheme();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
onClick={() => setMode(mode === 'light' ? 'dark' : 'light')}
|
|
||||||
>
|
|
||||||
Switch to {mode === 'light' ? 'Dark' : 'Light'} Mode
|
|
||||||
</Button>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|||||||
35
src/components/Layout/Header.tsx
Normal file
35
src/components/Layout/Header.tsx
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import { Box, IconButton, Typography } from '@mui/material';
|
||||||
|
import { Icon } from '@rkheftan/harmony-ui';
|
||||||
|
import { More } from 'iconsax-react';
|
||||||
|
import type { User } from './type';
|
||||||
|
|
||||||
|
interface HeaderProps {
|
||||||
|
user: User;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Header: React.FC<HeaderProps> = ({ user }) => {
|
||||||
|
return (
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
p: 2,
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
height: (t) => t.spacing(10.5),
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box>
|
||||||
|
<Typography variant="body1">
|
||||||
|
{user.firstName + ' ' + user.lastName}
|
||||||
|
</Typography>
|
||||||
|
<Typography variant="body2" color="textSecondary">
|
||||||
|
{user.phoneNumber}
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<IconButton>
|
||||||
|
<Icon Component={More} />
|
||||||
|
</IconButton>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
69
src/components/Layout/Layout.tsx
Normal file
69
src/components/Layout/Layout.tsx
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
import { SideNav } from '@rkheftan/harmony-ui';
|
||||||
|
import { buildNavItems } from './buildNavItems';
|
||||||
|
import { appRoutes } from '@/routes/config';
|
||||||
|
import { Outlet, useLocation } from 'react-router-dom';
|
||||||
|
import { Box, useMediaQuery, useTheme } from '@mui/material';
|
||||||
|
import { Header } from './Header';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { Toolbar } from './Toolbar';
|
||||||
|
import type { User } from './type';
|
||||||
|
|
||||||
|
export const Layout = () => {
|
||||||
|
const navItemConfigs = buildNavItems(appRoutes);
|
||||||
|
const location = useLocation();
|
||||||
|
const theme = useTheme();
|
||||||
|
const isMobile = useMediaQuery(theme.breakpoints.down('md'));
|
||||||
|
const [sideNavOpen, setSideNavOpen] = useState(false);
|
||||||
|
const [user] = useState<User>({
|
||||||
|
firstName: 'محمد حسین',
|
||||||
|
lastName: 'برزه گر',
|
||||||
|
phoneNumber: '09123456789',
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
height: '100vh',
|
||||||
|
display: 'flex',
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
// TODO: Check for better approach
|
||||||
|
width: isMobile ? '100%' : 1070,
|
||||||
|
height: isMobile ? '100vh' : '80%',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'row-reverse',
|
||||||
|
borderRadius: isMobile ? 0 : 4,
|
||||||
|
backgroundColor: 'background.paper',
|
||||||
|
overflow: 'hidden',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box sx={{ flex: 1 }}>
|
||||||
|
<Toolbar
|
||||||
|
isMobile={isMobile}
|
||||||
|
sideNavOpen={sideNavOpen}
|
||||||
|
setSideNavOpen={setSideNavOpen}
|
||||||
|
user={user}
|
||||||
|
/>
|
||||||
|
<Outlet />
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<SideNav
|
||||||
|
open={sideNavOpen}
|
||||||
|
onClose={() => setSideNavOpen(false)}
|
||||||
|
header={isMobile ? undefined : <Header user={user} />}
|
||||||
|
footer={isMobile ? <Header user={user} /> : undefined}
|
||||||
|
navConfig={navItemConfigs}
|
||||||
|
activePath={location.pathname + location.hash}
|
||||||
|
selectedVariant="textOnly"
|
||||||
|
positioning="absolute"
|
||||||
|
sideNavVariant={isMobile ? 'temporary' : 'full'}
|
||||||
|
top={8.125}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
75
src/components/Layout/Toolbar.tsx
Normal file
75
src/components/Layout/Toolbar.tsx
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
import {
|
||||||
|
Avatar,
|
||||||
|
Box,
|
||||||
|
IconButton,
|
||||||
|
Toolbar as MuiToolbar,
|
||||||
|
Typography,
|
||||||
|
} 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';
|
||||||
|
|
||||||
|
interface ToolbarProps {
|
||||||
|
sideNavOpen: boolean;
|
||||||
|
setSideNavOpen: Dispatch<SetStateAction<boolean>>;
|
||||||
|
isMobile: boolean;
|
||||||
|
user: User;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Toolbar: React.FC<ToolbarProps> = ({
|
||||||
|
sideNavOpen,
|
||||||
|
setSideNavOpen,
|
||||||
|
isMobile,
|
||||||
|
user,
|
||||||
|
}) => {
|
||||||
|
return (
|
||||||
|
<MuiToolbar
|
||||||
|
sx={{
|
||||||
|
height: (t) => t.spacing(isMobile ? 8 : 10.5),
|
||||||
|
px: isMobile ? 3 : 2,
|
||||||
|
borderBottom: (t) => `1px solid ${t.palette.divider}`,
|
||||||
|
boxSizing: 'content-box',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box
|
||||||
|
sx={{ display: 'flex', height: '100%', alignItems: 'center', gap: 2 }}
|
||||||
|
>
|
||||||
|
{isMobile && (
|
||||||
|
<IconButton
|
||||||
|
sx={{
|
||||||
|
backgroundColor: sideNavOpen ? 'primary.light' : undefined,
|
||||||
|
color: sideNavOpen ? 'primary.main' : undefined,
|
||||||
|
'&:hover': {
|
||||||
|
backgroundColor: sideNavOpen ? 'primary.light' : undefined,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
onClick={() => setSideNavOpen(!sideNavOpen)}
|
||||||
|
>
|
||||||
|
<Icon Component={HambergerMenu} />
|
||||||
|
</IconButton>
|
||||||
|
)}
|
||||||
|
{/* <Logo /> */}
|
||||||
|
<Typography variant="h6">LOGO placeholder</Typography>
|
||||||
|
</Box>
|
||||||
|
<Box
|
||||||
|
sx={{ display: 'flex', height: '100%', alignItems: 'center', gap: 1 }}
|
||||||
|
>
|
||||||
|
{isMobile && (
|
||||||
|
<Avatar
|
||||||
|
sx={{ width: 32, height: 32, fontSize: '14px' }}
|
||||||
|
src={user.profileUrl}
|
||||||
|
>
|
||||||
|
{user.firstName.charAt(0) + ' ' + user.lastName.charAt(0)}
|
||||||
|
</Avatar>
|
||||||
|
)}
|
||||||
|
<IconButton>
|
||||||
|
<Icon Component={Menu} variant="Bold" />
|
||||||
|
</IconButton>
|
||||||
|
</Box>
|
||||||
|
</MuiToolbar>
|
||||||
|
);
|
||||||
|
};
|
||||||
34
src/components/Layout/buildNavItems.tsx
Normal file
34
src/components/Layout/buildNavItems.tsx
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
// src/components/SideNav.tsx (Conceptual Example)
|
||||||
|
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { type RouteConfig } from '@/routes/config';
|
||||||
|
import { Icon, type NavItemConfig } from '@rkheftan/harmony-ui';
|
||||||
|
import type { Icon as Iconsax } from 'iconsax-react';
|
||||||
|
|
||||||
|
const getIcon = (icon?: Iconsax) => (isSelected: boolean) =>
|
||||||
|
icon ? (
|
||||||
|
<Icon Component={icon} variant={isSelected ? 'Bold' : 'Broken'} />
|
||||||
|
) : undefined;
|
||||||
|
|
||||||
|
export function buildNavItems(routes: RouteConfig[]): NavItemConfig[] {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
return routes.flatMap((route) => {
|
||||||
|
// Check if route itself does not have a navItem but its child has
|
||||||
|
if (!route.navConfig && route.children) {
|
||||||
|
return buildNavItems(route.children);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if route.navConfig is defined before destructuring
|
||||||
|
if (!route.navConfig) {
|
||||||
|
return []; // Return an empty array to be flattened
|
||||||
|
}
|
||||||
|
const { title, icon } = route.navConfig;
|
||||||
|
return {
|
||||||
|
text: t(title),
|
||||||
|
getIcon: getIcon(icon),
|
||||||
|
path: route.path,
|
||||||
|
children: route.children ? buildNavItems(route.children) : undefined,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
8
src/components/Layout/type.ts
Normal file
8
src/components/Layout/type.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
// TODO: this type file is temporary and should replace it with the actual use type and value when api is ready
|
||||||
|
|
||||||
|
export interface User {
|
||||||
|
firstName: string;
|
||||||
|
lastName: string;
|
||||||
|
phoneNumber: string;
|
||||||
|
profileUrl?: string;
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { CacheProvider } from '@emotion/react';
|
import { CacheProvider } from '@emotion/react';
|
||||||
import createCache from '@emotion/cache';
|
import createCache from '@emotion/cache';
|
||||||
import rtlPlugin from 'stylis-plugin-rtl';
|
import rtlPlugin from 'stylis-plugin-rtl';
|
||||||
|
import { prefixer } from 'stylis';
|
||||||
|
|
||||||
// This provider configures Emotion's cache to support RTL.
|
// This provider configures Emotion's cache to support RTL.
|
||||||
export const RtlProvider: React.FC<{ children: React.ReactNode }> = ({
|
export const RtlProvider: React.FC<{ children: React.ReactNode }> = ({
|
||||||
@@ -15,8 +16,8 @@ export const RtlProvider: React.FC<{ children: React.ReactNode }> = ({
|
|||||||
const newDir = i18n.dir(i18n.language);
|
const newDir = i18n.dir(i18n.language);
|
||||||
|
|
||||||
const newCache = createCache({
|
const newCache = createCache({
|
||||||
key: 'css',
|
key: 'mui',
|
||||||
stylisPlugins: newDir === 'rtl' ? [rtlPlugin] : [],
|
stylisPlugins: newDir === 'rtl' ? [prefixer, rtlPlugin] : [],
|
||||||
});
|
});
|
||||||
setCache(newCache);
|
setCache(newCache);
|
||||||
}, [i18n, i18n.language]);
|
}, [i18n, i18n.language]);
|
||||||
|
|||||||
119
src/routes/config.tsx
Normal file
119
src/routes/config.tsx
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
import { Layout } from '@/components/Layout/Layout';
|
||||||
|
import {
|
||||||
|
Calendar,
|
||||||
|
Devices,
|
||||||
|
LocationTick,
|
||||||
|
Mobile,
|
||||||
|
PasswordCheck,
|
||||||
|
Personalcard,
|
||||||
|
ProfileCircle,
|
||||||
|
Setting,
|
||||||
|
Shield,
|
||||||
|
Sms,
|
||||||
|
type Icon,
|
||||||
|
} from 'iconsax-react';
|
||||||
|
import { type ReactNode } from 'react';
|
||||||
|
import { Navigate } from 'react-router-dom';
|
||||||
|
|
||||||
|
export interface RouteConfig {
|
||||||
|
path: string;
|
||||||
|
element?: ReactNode;
|
||||||
|
navConfig?: {
|
||||||
|
title: string; // Translation key
|
||||||
|
icon?: Icon;
|
||||||
|
};
|
||||||
|
children?: RouteConfig[];
|
||||||
|
}
|
||||||
|
|
||||||
|
// can lazy load component if needed (ex. lazy(() => import('@/features/home/routes/HomePage'));)
|
||||||
|
export const appRoutes: RouteConfig[] = [
|
||||||
|
{
|
||||||
|
path: '/',
|
||||||
|
element: <Navigate to="/setting/profile" replace />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/setting',
|
||||||
|
element: <Layout />,
|
||||||
|
children: [
|
||||||
|
// TODO: add route component to each route
|
||||||
|
{
|
||||||
|
path: '/setting/profile',
|
||||||
|
navConfig: {
|
||||||
|
// Profile component
|
||||||
|
title: 'side.account',
|
||||||
|
icon: ProfileCircle,
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: '/setting/profile#info',
|
||||||
|
navConfig: {
|
||||||
|
title: 'side.personalInfo',
|
||||||
|
icon: Personalcard,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/setting/profile#contact-info',
|
||||||
|
navConfig: {
|
||||||
|
title: 'side.contactInfo',
|
||||||
|
icon: Mobile,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/setting/profile#email',
|
||||||
|
navConfig: {
|
||||||
|
title: 'side.email',
|
||||||
|
icon: Sms,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/setting/security',
|
||||||
|
// security component
|
||||||
|
navConfig: {
|
||||||
|
title: 'side.security',
|
||||||
|
icon: Shield,
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: '/setting/security#password',
|
||||||
|
navConfig: {
|
||||||
|
title: 'side.password',
|
||||||
|
icon: PasswordCheck,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/setting/security#confirmed-ips',
|
||||||
|
navConfig: {
|
||||||
|
title: 'side.confirmedIps',
|
||||||
|
icon: LocationTick,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/setting/security#recent-sessions',
|
||||||
|
navConfig: {
|
||||||
|
title: 'side.recentSessions',
|
||||||
|
icon: Devices,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/setting/active-sessions',
|
||||||
|
// active session component
|
||||||
|
navConfig: {
|
||||||
|
title: 'side.activeSessions',
|
||||||
|
icon: Calendar,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/setting/preferences',
|
||||||
|
// setting component
|
||||||
|
navConfig: {
|
||||||
|
title: 'side.setting',
|
||||||
|
icon: Setting,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
34
src/routes/index.tsx
Normal file
34
src/routes/index.tsx
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import { Suspense, type ReactNode } from 'react';
|
||||||
|
import { createBrowserRouter, type RouteObject } from 'react-router-dom';
|
||||||
|
import { appRoutes, type RouteConfig } from './config';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A recursive function to map our custom route config to the format
|
||||||
|
* that react-router-dom expects, applying layouts and guards.
|
||||||
|
*/
|
||||||
|
function mapRoutes(routes: RouteConfig[]): RouteObject[] {
|
||||||
|
return routes.map((route) => {
|
||||||
|
// Start with the base element, wrapped in Suspense for lazy loading
|
||||||
|
let element: ReactNode = (
|
||||||
|
<Suspense fallback={<div>Loading...</div>}>{route.element}</Suspense>
|
||||||
|
);
|
||||||
|
|
||||||
|
// Conditionally wrap the element in the specified layout
|
||||||
|
// if (route.layout) {
|
||||||
|
// element = <route.layout>{element}</route.layout>;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Conditionally wrap the element in the authentication guard
|
||||||
|
// if (route.authRequired) {
|
||||||
|
// element = <ProtectedRoute>{element}</ProtectedRoute>;
|
||||||
|
// }
|
||||||
|
|
||||||
|
return {
|
||||||
|
path: route.path,
|
||||||
|
element: element,
|
||||||
|
...(route.children && { children: mapRoutes(route.children) }),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export const router = createBrowserRouter(mapRoutes(appRoutes));
|
||||||
Reference in New Issue
Block a user