From 9387f85cf75789629d1ed6c500b668c4e678e188 Mon Sep 17 00:00:00 2001 From: AmirHossein Mahmoodi Date: Mon, 16 Sep 2024 07:59:19 +0000 Subject: [PATCH] Feature/update profile sidebar --- .../headerWithSidebar/HeaderMenu/index.jsx | 19 ++-- .../Sidebar/SidebarBadge.jsx | 25 +++--- .../Sidebar/SidebarListItems.jsx | 6 +- .../headerWithSidebar/Sidebar/SidebarMenu.jsx | 47 ++++------ .../Sidebar/SidebarSubitems.jsx | 16 +++- .../dashboard/headerWithSidebar/index.jsx | 21 +++-- .../DataTable/body/TableBodyCell.js | 2 +- .../DataTable/table/TableContainer.js | 5 +- .../components/Profile/ChangePass/Form.jsx | 15 ++-- .../components/Profile/ChangePass/index.jsx | 26 ++++-- .../components/Profile/ProfileActions.jsx | 10 ++- src/core/components/Profile/ProfileInfo.jsx | 24 +++--- src/core/components/Profile/Update/Form.jsx | 77 +++++++++-------- src/core/components/Profile/Update/index.jsx | 16 ++-- src/core/components/Profile/index.jsx | 14 +-- src/core/utils/getValueByPath.js | 2 +- src/core/utils/headerMenu.js | 86 +++++++++---------- src/core/utils/pageMenu.js | 20 ++--- src/lib/contexts/auth.js | 2 +- 19 files changed, 230 insertions(+), 203 deletions(-) diff --git a/src/components/layouts/dashboard/headerWithSidebar/HeaderMenu/index.jsx b/src/components/layouts/dashboard/headerWithSidebar/HeaderMenu/index.jsx index 0d87a5d..47decdf 100644 --- a/src/components/layouts/dashboard/headerWithSidebar/HeaderMenu/index.jsx +++ b/src/components/layouts/dashboard/headerWithSidebar/HeaderMenu/index.jsx @@ -19,32 +19,23 @@ const HeaderMenu = ({ menu }) => { - + {menu.subMenu.flatMap((subMenu, index) => [ - ...subMenu.map(sub => ( - + ...subMenu.map((sub) => ( + {sub.title} )), - index < menu.subMenu.length - 1 && + index < menu.subMenu.length - 1 && , ])} diff --git a/src/components/layouts/dashboard/headerWithSidebar/Sidebar/SidebarBadge.jsx b/src/components/layouts/dashboard/headerWithSidebar/Sidebar/SidebarBadge.jsx index df8fbc2..4ee1a83 100644 --- a/src/components/layouts/dashboard/headerWithSidebar/Sidebar/SidebarBadge.jsx +++ b/src/components/layouts/dashboard/headerWithSidebar/Sidebar/SidebarBadge.jsx @@ -1,22 +1,19 @@ import { getValueByPath } from "@/core/utils/getValueByPath"; -import { useSidebarBadge } from "@/lib/hooks/useSidebarBadge" -import { Chip } from "@mui/material" +import { useSidebarBadge } from "@/lib/hooks/useSidebarBadge"; +import { Chip } from "@mui/material"; import { useEffect, useState } from "react"; const SidebarBadge = ({ badge, chipProps = {} }) => { - const { data } = useSidebarBadge() - const [value, setValue] = useState() + const { data } = useSidebarBadge(); + const [value, setValue] = useState(); useEffect(() => { - setValue(getValueByPath(data, badge)) - }, [data, badge]) + setValue(getValueByPath(data, badge)); + }, [data, badge]); + if (!data) return null; + if (!value) return null; - if (!data) return null - if (!value) return null - - return ( - - ) -} -export default SidebarBadge \ No newline at end of file + return ; +}; +export default SidebarBadge; diff --git a/src/components/layouts/dashboard/headerWithSidebar/Sidebar/SidebarListItems.jsx b/src/components/layouts/dashboard/headerWithSidebar/Sidebar/SidebarListItems.jsx index bde3bae..7b0aabc 100644 --- a/src/components/layouts/dashboard/headerWithSidebar/Sidebar/SidebarListItems.jsx +++ b/src/components/layouts/dashboard/headerWithSidebar/Sidebar/SidebarListItems.jsx @@ -31,8 +31,10 @@ const SidebarListItems = ({ menuItem, dispatch }) => { {menuItem.badges && ( - - {menuItem.badges.map((badge, i) => )} + + {menuItem.badges.map((badge, i) => ( + + ))} )} {menuItem.hasSubitems ? menuItem.showSubitems ? : : null} diff --git a/src/components/layouts/dashboard/headerWithSidebar/Sidebar/SidebarMenu.jsx b/src/components/layouts/dashboard/headerWithSidebar/Sidebar/SidebarMenu.jsx index a745929..4142b7f 100644 --- a/src/components/layouts/dashboard/headerWithSidebar/Sidebar/SidebarMenu.jsx +++ b/src/components/layouts/dashboard/headerWithSidebar/Sidebar/SidebarMenu.jsx @@ -28,9 +28,7 @@ function selectPage(item, route) { function toggleSubitems(items, actionId) { return items.map((item) => - actionId === item.id - ? { ...item, showSubitems: !item.showSubitems } - : { ...item, showSubitems: false } + actionId === item.id ? { ...item, showSubitems: !item.showSubitems } : { ...item, showSubitems: false } ); } @@ -48,28 +46,23 @@ function reducer(state, action) { case "COLLAPSE_SUB_ITEMS": return state.map((item) => - item.hasSubitems - ? { ...item, Subitems: toggleSubitems(item.Subitems, action.id) } - : item + item.hasSubitems ? { ...item, Subitems: toggleSubitems(item.Subitems, action.id) } : item ); case "COLLAPSE_SUB_SECOND_ITEMS": return state.map((item) => item.hasSubitems ? { - ...item, - Subitems: item.Subitems.map((subitem) => - subitem.hasSubitems - ? { - ...subitem, - Subitems: toggleSubitems( - subitem.Subitems, - action.id - ), - } - : subitem - ), - } + ...item, + Subitems: item.Subitems.map((subitem) => + subitem.hasSubitems + ? { + ...subitem, + Subitems: toggleSubitems(subitem.Subitems, action.id), + } + : subitem + ), + } : item ); @@ -108,15 +101,13 @@ const SidebarMenu = () => { return ( <> - { - userPermissions && ( - - {menuItems.map((menuItem) => { - return ; - })} - - ) - } + {userPermissions && ( + + {menuItems.map((menuItem) => { + return ; + })} + + )} ); }; diff --git a/src/components/layouts/dashboard/headerWithSidebar/Sidebar/SidebarSubitems.jsx b/src/components/layouts/dashboard/headerWithSidebar/Sidebar/SidebarSubitems.jsx index 6e51bcd..3018520 100644 --- a/src/components/layouts/dashboard/headerWithSidebar/Sidebar/SidebarSubitems.jsx +++ b/src/components/layouts/dashboard/headerWithSidebar/Sidebar/SidebarSubitems.jsx @@ -29,11 +29,21 @@ const SidebarSubitems = ({ subitem, dispatch }) => { {subitem.badges && ( - - {subitem.badges.map((badge, i) => )} + + {subitem.badges.map((badge, i) => ( + + ))} )} - {subitem.hasSubitems ? subitem.showSubitems ? : : } + {subitem.hasSubitems ? ( + subitem.showSubitems ? ( + + ) : ( + + ) + ) : ( + + )} diff --git a/src/components/layouts/dashboard/headerWithSidebar/index.jsx b/src/components/layouts/dashboard/headerWithSidebar/index.jsx index c4e3fde..a0ffad2 100644 --- a/src/components/layouts/dashboard/headerWithSidebar/index.jsx +++ b/src/components/layouts/dashboard/headerWithSidebar/index.jsx @@ -10,7 +10,7 @@ import { headerMenu } from "@/core/utils/headerMenu"; import SidebarMenu from "./Sidebar/SidebarMenu"; const drawerWidth = 300; -const headersHeight = 136 +const headersHeight = 136; const Main = styled(Stack, { shouldForwardProp: (prop) => prop !== "open" })(({ theme, open }) => ({ flexGrow: 1, @@ -66,9 +66,14 @@ const HeaderWithSidebar = ({ children }) => { setOpen(false); }; return ( - + { - {headerMenu.map(menu => )} + {headerMenu.map((menu) => ( + + ))} @@ -104,7 +111,9 @@ const HeaderWithSidebar = ({ children }) => { open={open} > - تاریخ امروز: {now} + + تاریخ امروز: {now} + diff --git a/src/core/components/DataTable/body/TableBodyCell.js b/src/core/components/DataTable/body/TableBodyCell.js index 39f6895..292f39e 100644 --- a/src/core/components/DataTable/body/TableBodyCell.js +++ b/src/core/components/DataTable/body/TableBodyCell.js @@ -221,7 +221,7 @@ const DataTable_TableBodyCell = ({ cell, numRows, rowRef, staticColumnIndex, sta {tableCellProps.children ?? ( <> {cell.getIsPlaceholder() ? ( - columnDef.PlaceholderCell?.({ cell, column, row, table }) ?? null + (columnDef.PlaceholderCell?.({ cell, column, row, table }) ?? null) ) : showSkeletons !== false && (isLoading || showSkeletons) ? ( ) : columnDefType === "display" && diff --git a/src/core/components/DataTable/table/TableContainer.js b/src/core/components/DataTable/table/TableContainer.js index bc1d80c..3e1320e 100644 --- a/src/core/components/DataTable/table/TableContainer.js +++ b/src/core/components/DataTable/table/TableContainer.js @@ -27,9 +27,10 @@ const DataTable_TableContainer = ({ table, ...rest }) => { }; useIsomorphicLayoutEffect(() => { - const topToolbarHeight = typeof document !== "undefined" ? topToolbarRef.current?.offsetHeight ?? 0 : 0; + const topToolbarHeight = typeof document !== "undefined" ? (topToolbarRef.current?.offsetHeight ?? 0) : 0; - const bottomToolbarHeight = typeof document !== "undefined" ? bottomToolbarRef?.current?.offsetHeight ?? 0 : 0; + const bottomToolbarHeight = + typeof document !== "undefined" ? (bottomToolbarRef?.current?.offsetHeight ?? 0) : 0; setTotalToolbarHeight(topToolbarHeight + bottomToolbarHeight); }); diff --git a/src/core/components/Profile/ChangePass/Form.jsx b/src/core/components/Profile/ChangePass/Form.jsx index 3499394..80d1890 100644 --- a/src/core/components/Profile/ChangePass/Form.jsx +++ b/src/core/components/Profile/ChangePass/Form.jsx @@ -24,13 +24,11 @@ import VisibilityOff from "@mui/icons-material/VisibilityOff"; const validationSchema = object({ current_password: string().required("اجباری"), new_password: string().required("اجباری"), - repeat_new_password: string().required("اجباری").test( - "password-match", - "رمز عبور جدید و تکرار آن باید یکسان باشند", - function(value) { + repeat_new_password: string() + .required("اجباری") + .test("password-match", "رمز عبور جدید و تکرار آن باید یکسان باشند", function (value) { return this.parent.new_password === value; - }, - ), + }), }); const Form = ({ handleCloseForm, setLoading }) => { @@ -61,8 +59,7 @@ const Form = ({ handleCloseForm, setLoading }) => { try { await request(CHANGE_USER_PASSWORD, "post", { data: formData, signal: controller.signal }); handleCloseForm(); - } catch (error) { - } + } catch (error) {} }; return ( @@ -152,4 +149,4 @@ const Form = ({ handleCloseForm, setLoading }) => { ); }; -export default Form; \ No newline at end of file +export default Form; diff --git a/src/core/components/Profile/ChangePass/index.jsx b/src/core/components/Profile/ChangePass/index.jsx index 15e6fcd..4b388da 100644 --- a/src/core/components/Profile/ChangePass/index.jsx +++ b/src/core/components/Profile/ChangePass/index.jsx @@ -19,19 +19,29 @@ const ChangePass = ({ open, setOpen }) => {
- + بستن - }> + } + > ثبت ); }; -export default ChangePass; \ No newline at end of file +export default ChangePass; diff --git a/src/core/components/Profile/ProfileActions.jsx b/src/core/components/Profile/ProfileActions.jsx index 7683547..1bb99be 100644 --- a/src/core/components/Profile/ProfileActions.jsx +++ b/src/core/components/Profile/ProfileActions.jsx @@ -35,9 +35,13 @@ const ProfileActions = () => { - { - setOpenChangePass(true); - }}> + { + setOpenChangePass(true); + }} + > diff --git a/src/core/components/Profile/ProfileInfo.jsx b/src/core/components/Profile/ProfileInfo.jsx index ea33e8f..6af5082 100644 --- a/src/core/components/Profile/ProfileInfo.jsx +++ b/src/core/components/Profile/ProfileInfo.jsx @@ -1,31 +1,35 @@ "use client"; +import { useAuth } from "@/lib/contexts/auth"; import { Avatar, Box, Chip, Divider, Stack, Typography } from "@mui/material"; +import moment from "jalali-moment"; const ProfileInfo = () => { + const { user } = useAuth(); + return ( <> - + - حسن محمد زاده عبدالله + {`${user.first_name} ${user.last_name}`} - .: اداره کل ستاد :. + .: {user.name} :. - آخرین ورود + + آخرین ورود + - 1 ساعت پیش + + {moment(user.last_login).locale("fa").fromNow()} + - + diff --git a/src/core/components/Profile/Update/Form.jsx b/src/core/components/Profile/Update/Form.jsx index 7c9a340..69b1466 100644 --- a/src/core/components/Profile/Update/Form.jsx +++ b/src/core/components/Profile/Update/Form.jsx @@ -53,11 +53,11 @@ const Form = ({ handleCloseForm, setLoading }) => { const { user, getUser } = useAuth(); const [uploadBackDrop, setUploadBackDrop] = useState(false); const defaultValues = { - first_name: user.data.first_name, - last_name: user.data.last_name, - major: user.data.major, - degree: user.data.degree, - mobile: user.data.mobile, + first_name: user.first_name, + last_name: user.last_name, + major: user.major, + degree: user.degree, + mobile: user.mobile, avatar: null, }; @@ -89,8 +89,7 @@ const Form = ({ handleCloseForm, setLoading }) => { await request(UPDATE_USER_ROUTE, "post", { data: formData }); getUser(); handleCloseForm(); - } catch (error) { - } + } catch (error) {} }; return ( @@ -99,15 +98,17 @@ const Form = ({ handleCloseForm, setLoading }) => { - + @@ -156,8 +161,9 @@ const Form = ({ handleCloseForm, setLoading }) => { fullWidth type="text" /> - {errors.first_name ? errors.first_name.message : null} + + {errors.first_name ? errors.first_name.message : null} + @@ -172,8 +178,9 @@ const Form = ({ handleCloseForm, setLoading }) => { fullWidth type="text" /> - {errors.last_name ? errors.last_name.message : null} + + {errors.last_name ? errors.last_name.message : null} + @@ -188,8 +195,7 @@ const Form = ({ handleCloseForm, setLoading }) => { fullWidth type="text" /> - {errors.major ? errors.major.message : null} + {errors.major ? errors.major.message : null} @@ -217,9 +223,7 @@ const Form = ({ handleCloseForm, setLoading }) => { /> )} /> - - {error ? error.message : null} - + {error ? error.message : null} )} /> @@ -236,8 +240,7 @@ const Form = ({ handleCloseForm, setLoading }) => { fullWidth type="text" /> - {errors.mobile ? errors.mobile.message : null} + {errors.mobile ? errors.mobile.message : null} @@ -245,4 +248,4 @@ const Form = ({ handleCloseForm, setLoading }) => { ); }; -export default Form; \ No newline at end of file +export default Form; diff --git a/src/core/components/Profile/Update/index.jsx b/src/core/components/Profile/Update/index.jsx index 9228261..d72b5a0 100644 --- a/src/core/components/Profile/Update/index.jsx +++ b/src/core/components/Profile/Update/index.jsx @@ -25,14 +25,20 @@ const Update = ({ open, setOpen }) => { - }> + } + > ثبت ); }; -export default Update; \ No newline at end of file +export default Update; diff --git a/src/core/components/Profile/index.jsx b/src/core/components/Profile/index.jsx index 3741dc2..fd5cbf4 100644 --- a/src/core/components/Profile/index.jsx +++ b/src/core/components/Profile/index.jsx @@ -6,12 +6,14 @@ import ProfileActions from "./ProfileActions"; const Profile = () => { return ( - + diff --git a/src/core/utils/getValueByPath.js b/src/core/utils/getValueByPath.js index 6f51b4f..a31f76f 100644 --- a/src/core/utils/getValueByPath.js +++ b/src/core/utils/getValueByPath.js @@ -11,4 +11,4 @@ export const getValueByPath = (obj, path) => { } return value; -} \ No newline at end of file +}; diff --git a/src/core/utils/headerMenu.js b/src/core/utils/headerMenu.js index 4f42f34..32438bb 100644 --- a/src/core/utils/headerMenu.js +++ b/src/core/utils/headerMenu.js @@ -1,80 +1,80 @@ export const headerMenu = [ { - title: 'تصادفات', + title: "تصادفات", subMenu: [ [ { - title: 'تصادفات روزانه', - href: 'https://rms.witel.ir/v2/daily_accidents/create' - } - ] - ] + title: "تصادفات روزانه", + href: "https://rms.witel.ir/v2/daily_accidents/create", + }, + ], + ], }, { - title: 'گزارش های جامع', + title: "گزارش های جامع", subMenu: [ [ { - title: 'گزارش محوری', - href: 'https://rms.witel.ir/v2/axis_reports' + title: "گزارش محوری", + href: "https://rms.witel.ir/v2/axis_reports", }, { - title: 'هوش تجاری (‌BI)', - href: 'https://rms.witel.ir/v2/axis_reports' - } - ] - ] + title: "هوش تجاری (‌BI)", + href: "https://rms.witel.ir/v2/axis_reports", + }, + ], + ], }, { - title: 'زیرساخت و ناوگان', + title: "زیرساخت و ناوگان", subMenu: [ [ { - title: 'پراکندگی بر روی نقشه راهدارخانه ها', - href: 'https://rms.witel.ir/v2/map?type=rahdar' + title: "پراکندگی بر روی نقشه راهدارخانه ها", + href: "https://rms.witel.ir/v2/map?type=rahdar", }, { - title: 'راهدارخانه ها', - href: 'https://rms.witel.ir/v2/rahdari_points' - } + title: "راهدارخانه ها", + href: "https://rms.witel.ir/v2/rahdari_points", + }, ], [ { - title: 'ممیزی ماشین آلات راهداری کشور', - href: 'https://rms.witel.ir/cmms-audit' - } - ] - ] + title: "ممیزی ماشین آلات راهداری کشور", + href: "https://rms.witel.ir/cmms-audit", + }, + ], + ], }, { - title: 'سامانه های راهداری', + title: "سامانه های راهداری", subMenu: [ [ { - title: 'تحقیق و توسعه', - href: 'https://rms.witel.ir/RandD' + title: "تحقیق و توسعه", + href: "https://rms.witel.ir/RandD", }, { - title: 'سامانه مدیریت یکپارچه زیرساخت های راه (PMS,BMS,SMS)', - href: 'http://roadams.rmto.ir' + title: "سامانه مدیریت یکپارچه زیرساخت های راه (PMS,BMS,SMS)", + href: "http://roadams.rmto.ir", }, { - title: 'سامانه مدیریت ناوگان (FMS)', - href: 'http://fms.141.ir' + title: "سامانه مدیریت ناوگان (FMS)", + href: "http://fms.141.ir", }, { - title: 'سامانه جامع مدیریت سوانح و حوادث جاده ای', - href: 'https://items.rmto.ir' + title: "سامانه جامع مدیریت سوانح و حوادث جاده ای", + href: "https://items.rmto.ir", }, { - title: 'سامانه مدیریت نگهداری ماشین آلات (CMMS)', - href: 'https://cmms.rmto.ir/Login.aspx?ReturnUrl=%2f' + title: "سامانه مدیریت نگهداری ماشین آلات (CMMS)", + href: "https://cmms.rmto.ir/Login.aspx?ReturnUrl=%2f", }, { - title: 'درگاه کاتالوگ داده', - href: 'https://roadams.rmto.ir:8080' - } - ] - ] - } -] \ No newline at end of file + title: "درگاه کاتالوگ داده", + href: "https://roadams.rmto.ir:8080", + }, + ], + ], + }, +]; diff --git a/src/core/utils/pageMenu.js b/src/core/utils/pageMenu.js index 306b6ec..6087440 100644 --- a/src/core/utils/pageMenu.js +++ b/src/core/utils/pageMenu.js @@ -91,7 +91,7 @@ export const pageMenu = [ type: "menu", icon: , hasSubitems: true, - badges: ['road_items.total'], + badges: ["road_items.total"], Subitems: [ { id: "roadItemManagmentSupervisor", @@ -99,7 +99,7 @@ export const pageMenu = [ type: "menu", icon: , hasSubitems: true, - badges: ['road_items.supervise_cnt'], + badges: ["road_items.supervise_cnt"], Subitems: [ { id: "roadItemManagmentSupervisorCartable", @@ -119,7 +119,7 @@ export const pageMenu = [ type: "menu", icon: , hasSubitems: true, - badges: ['road_items.operation_cnt'], + badges: ["road_items.operation_cnt"], Subitems: [ { id: "roadItemManagmentOparationCreate", @@ -169,7 +169,7 @@ export const pageMenu = [ type: "menu", icon: , hasSubitems: true, - badges: ['road_patrols.total'], + badges: ["road_patrols.total"], Subitems: [ { id: "roadPatrolManagmentSupervisor", @@ -177,7 +177,7 @@ export const pageMenu = [ type: "menu", icon: , hasSubitems: true, - badges: ['road_patrols.supervise_cnt'], + badges: ["road_patrols.supervise_cnt"], Subitems: [ { id: "roadPatrolManagmentSupervisorCartable", @@ -197,7 +197,7 @@ export const pageMenu = [ type: "menu", icon: , hasSubitems: true, - badges: ['road_patrols.operation_cnt'], + badges: ["road_patrols.operation_cnt"], Subitems: [ { id: "roadPatrolManagmentOparationCreate", @@ -277,7 +277,7 @@ export const pageMenu = [ type: "menu", icon: , hasSubitems: true, - badges: ['safety_and_privacy.step_one', 'safety_and_privacy.step_two'], + badges: ["safety_and_privacy.step_one", "safety_and_privacy.step_two"], Subitems: [ { id: "safetyAndPrivacyManagmentOparation", @@ -340,7 +340,7 @@ export const pageMenu = [ type: "menu", icon: , hasSubitems: true, - badges: ['road_observations.total'], + badges: ["road_observations.total"], Subitems: [ { id: "roadObservationsManagmentSupervisor", @@ -348,7 +348,7 @@ export const pageMenu = [ type: "menu", icon: , hasSubitems: true, - badges: ['road_observations.supervise_cnt'], + badges: ["road_observations.supervise_cnt"], Subitems: [ { id: "roadObservationsManagmentSupervisorCartable", @@ -373,7 +373,7 @@ export const pageMenu = [ type: "menu", icon: , hasSubitems: true, - badges: ['road_observations.operation_cnt'], + badges: ["road_observations.operation_cnt"], Subitems: [ { id: "roadObservationsManagmentOparationCartable", diff --git a/src/lib/contexts/auth.js b/src/lib/contexts/auth.js index 0dfa41a..edc83fb 100644 --- a/src/lib/contexts/auth.js +++ b/src/lib/contexts/auth.js @@ -54,7 +54,7 @@ export const AuthProvider = ({ children }) => { const getUser = useCallback(async () => { try { const { data } = await axios.get(GET_USER_ROUTE, { withCredentials: true }); - changeUser(data); + changeUser(data.data); changeAuthState(true); changeInitAuth(true); } catch (error) {