@asaleh37/ui-base 1.0.9 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/dist/index.js +1 -1
  2. package/dist/index.js.map +1 -1
  3. package/dist/index.mjs +1 -1
  4. package/dist/index.mjs.map +1 -1
  5. package/package.json +1 -1
  6. package/src/components/App.tsx +31 -0
  7. package/src/components/admin/AttachmentGrid.tsx +116 -0
  8. package/src/components/admin/AuthorityGrid.tsx +88 -0
  9. package/src/components/admin/BluePrintGrid.tsx +55 -0
  10. package/src/components/admin/BluePrintPageGrid.tsx +85 -0
  11. package/src/components/admin/BluePrintPointGrid.tsx +85 -0
  12. package/src/components/admin/DashboardGrid.tsx +95 -0
  13. package/src/components/admin/DashboardWidgetGrid.tsx +75 -0
  14. package/src/components/admin/DataQueryGrid.tsx +75 -0
  15. package/src/components/admin/DataQueryParameterGrid.tsx +98 -0
  16. package/src/components/admin/DatasourceConnectionGrid.tsx +98 -0
  17. package/src/components/admin/EmployeeGrid.tsx +105 -0
  18. package/src/components/admin/EntityParameterGrid.tsx +125 -0
  19. package/src/components/admin/ExcelUploaderDetailGrid.tsx +78 -0
  20. package/src/components/admin/ExcelUploaderHeaderGrid.tsx +78 -0
  21. package/src/components/admin/LookupGrid.tsx +95 -0
  22. package/src/components/admin/MailAttachmentGrid.tsx +65 -0
  23. package/src/components/admin/MailBodyGrid.tsx +105 -0
  24. package/src/components/admin/MailNotificationQueueGrid.tsx +131 -0
  25. package/src/components/admin/MailRecipientGrid.tsx +75 -0
  26. package/src/components/admin/MailTemplateGrid.tsx +145 -0
  27. package/src/components/admin/NewTableGrid.tsx +65 -0
  28. package/src/components/admin/NotificationGrid.tsx +115 -0
  29. package/src/components/admin/NotificationQueueGrid.tsx +125 -0
  30. package/src/components/admin/OrganizationApplicationGrid.tsx +81 -0
  31. package/src/components/admin/OrganizationGrid.tsx +65 -0
  32. package/src/components/admin/OrganizationRankGrid.tsx +85 -0
  33. package/src/components/admin/OrganizationUnitGrid.tsx +85 -0
  34. package/src/components/admin/OrganizationUserGrid.tsx +75 -0
  35. package/src/components/admin/OrganizationUserRoleGrid.tsx +98 -0
  36. package/src/components/admin/ReportGrid.tsx +155 -0
  37. package/src/components/admin/ReportParameterGrid.tsx +95 -0
  38. package/src/components/admin/RoleAuthorityGrid.tsx +65 -0
  39. package/src/components/admin/RoleGrid.tsx +78 -0
  40. package/src/components/admin/UserAccountGrid.tsx +65 -0
  41. package/src/components/admin/UserRequestGrid.tsx +145 -0
  42. package/src/components/admin/WidgetGrid.tsx +175 -0
  43. package/src/components/admin/WorkflowDocumentActionGrid.tsx +111 -0
  44. package/src/components/admin/WorkflowDocumentActionHistoryGrid.tsx +111 -0
  45. package/src/components/admin/WorkflowDocumentActionMailGrid.tsx +71 -0
  46. package/src/components/admin/WorkflowDocumentGrid.tsx +185 -0
  47. package/src/components/admin/WorkflowDocumentMailLogGrid.tsx +141 -0
  48. package/src/components/admin/WorkflowDocumentStatusGrid.tsx +121 -0
  49. package/src/components/common/Home.tsx +31 -0
  50. package/src/components/common/LanguageSwitcher.tsx +25 -0
  51. package/src/components/common/LayoutHandlers.tsx +12 -0
  52. package/src/components/common/LoadingMask.tsx +19 -0
  53. package/src/components/common/Login.tsx +183 -0
  54. package/src/components/templates/DataEntryTemplates/DataEntryTypes.ts +288 -0
  55. package/src/components/templates/DataEntryTemplates/DataEntryUtil.ts +201 -0
  56. package/src/components/templates/DataEntryTemplates/TemplateDataForm/FormAction.tsx +60 -0
  57. package/src/components/templates/DataEntryTemplates/TemplateDataForm/FormElementField.tsx +194 -0
  58. package/src/components/templates/DataEntryTemplates/TemplateDataForm/FormElementGroup.tsx +98 -0
  59. package/src/components/templates/DataEntryTemplates/TemplateDataForm/FormFields/CheckBox.tsx +64 -0
  60. package/src/components/templates/DataEntryTemplates/TemplateDataForm/FormFields/ComboBox.tsx +94 -0
  61. package/src/components/templates/DataEntryTemplates/TemplateDataForm/FormFields/Datefield.tsx +65 -0
  62. package/src/components/templates/DataEntryTemplates/TemplateDataForm/FormFields/DatetimeField.tsx +64 -0
  63. package/src/components/templates/DataEntryTemplates/TemplateDataForm/FormFields/FiltersPanel.tsx +237 -0
  64. package/src/components/templates/DataEntryTemplates/TemplateDataForm/FormFields/TemplateTextField.tsx +9 -0
  65. package/src/components/templates/DataEntryTemplates/TemplateDataForm/TemplateForm.tsx +256 -0
  66. package/src/components/templates/DataEntryTemplates/TemplateDataGrid/DataGridColumnsUtil.tsx +188 -0
  67. package/src/components/templates/DataEntryTemplates/TemplateDataGrid/TemplateGrid.tsx +844 -0
  68. package/src/components/templates/DataEntryTemplates/TemplateDataGrid/TemplateGridMultiRecordAction.tsx +89 -0
  69. package/src/components/templates/DataEntryTemplates/TemplateDataGrid/TemplateGridRecordAction.tsx +92 -0
  70. package/src/components/templates/DataEntryTemplates/TemplateDataGrid/TemplateGridTopBar.tsx +228 -0
  71. package/src/components/templates/DataEntryTemplates/useApiActions.ts +125 -0
  72. package/src/components/templates/TransferList.tsx +250 -0
  73. package/src/components/templates/Window/ConfirmationWindow.tsx +55 -0
  74. package/src/components/templates/visuals/TemplateDashboard.tsx +126 -0
  75. package/src/components/templates/visuals/charts/TemplateBarChart.tsx +16 -0
  76. package/src/components/templates/visuals/charts/TemplateDataCard.tsx +60 -0
  77. package/src/components/templates/visuals/charts/TemplateGauge.tsx +16 -0
  78. package/src/components/templates/visuals/charts/TemplateLineChart.tsx +16 -0
  79. package/src/components/templates/visuals/charts/TemplateLineProgress.tsx +40 -0
  80. package/src/components/templates/visuals/charts/TemplatePieChart.tsx +25 -0
  81. package/src/hooks/UseConfirmationWindow.tsx +54 -0
  82. package/src/hooks/UseMobile.tsx +13 -0
  83. package/src/hooks/UseSession.tsx +26 -0
  84. package/src/hooks/UseWindow.tsx +106 -0
  85. package/src/hooks/useAxios.tsx +271 -0
  86. package/src/hooks/useLoadingMask.tsx +16 -0
  87. package/src/layout/DrawerHeader.tsx +10 -0
  88. package/src/layout/Layout.tsx +122 -0
  89. package/src/layout/MainContent.tsx +43 -0
  90. package/src/layout/MobileDrawer.tsx +103 -0
  91. package/src/layout/NavigationTree.tsx +284 -0
  92. package/src/layout/SideBar.tsx +80 -0
  93. package/src/layout/TopBar.tsx +142 -0
  94. package/src/locales/arabic/adminLocalsAr.json +356 -0
  95. package/src/locales/arabic/common.json +34 -0
  96. package/src/locales/arabic/index.ts +7 -0
  97. package/src/locales/english/adminLocalsEn.json +356 -0
  98. package/src/locales/english/common.json +33 -0
  99. package/src/locales/english/index.ts +6 -0
  100. package/src/locales/english/index.tsx +0 -0
  101. package/src/locales/i18n.ts +15 -0
  102. package/src/locales/index.ts +9 -0
  103. package/src/navigationItems/Administration/adminNavigationItems.tsx +182 -0
  104. package/src/navigationItems/Administration/index.tsx +71 -0
  105. package/src/navigationItems/common/CommonNavigationItems.tsx +12 -0
  106. package/src/navigationItems/common/index.tsx +7 -0
  107. package/src/navigationItems/index.tsx +34 -0
  108. package/src/redux/features/administration/AdministrationStoresMetaData.ts +72 -0
  109. package/src/redux/features/business/BusinessStoresMetaData.ts +3 -0
  110. package/src/redux/features/business/CommonStoreSlice.ts +37 -0
  111. package/src/redux/features/common/AppInfoSlice.ts +30 -0
  112. package/src/redux/features/common/AppLayoutSlice.ts +37 -0
  113. package/src/redux/features/common/LoadingMaskSlice.ts +30 -0
  114. package/src/redux/features/common/UserSessionSlice.ts +62 -0
  115. package/src/redux/store.ts +10 -10
  116. package/src/routes/administration/adminRoutes.tsx +259 -0
  117. package/src/routes/administration/index.ts +4 -0
  118. package/src/routes/index.ts +11 -0
  119. package/src/routes/types/index.ts +5 -0
  120. package/src/theme/DarkThemeOptions.ts +30 -0
  121. package/src/theme/LightThemeOptions.ts +34 -0
  122. package/src/util/AppUtils.ts +18 -0
  123. package/src/util/constants.ts +2 -0
  124. package/tsconfig.json +2 -2
  125. package/src/redux/CounterSlice.ts +0 -17
@@ -0,0 +1,284 @@
1
+ import * as React from "react";
2
+ import clsx from "clsx";
3
+ import { animated, useSpring } from "@react-spring/web";
4
+ import { styled, alpha } from "@mui/material/styles";
5
+ import { TransitionProps } from "@mui/material/transitions";
6
+ import Box from "@mui/material/Box";
7
+ import Collapse from "@mui/material/Collapse";
8
+ import Typography from "@mui/material/Typography";
9
+ import { RichTreeView } from "@mui/x-tree-view/RichTreeView";
10
+ import { treeItemClasses } from "@mui/x-tree-view/TreeItem";
11
+ import {
12
+ useTreeItem2,
13
+ UseTreeItem2Parameters,
14
+ } from "@mui/x-tree-view/useTreeItem2";
15
+ import {
16
+ TreeItem2Checkbox,
17
+ TreeItem2Content,
18
+ TreeItem2IconContainer,
19
+ TreeItem2Label,
20
+ TreeItem2Root,
21
+ } from "@mui/x-tree-view/TreeItem2";
22
+ import { TreeItem2Icon } from "@mui/x-tree-view/TreeItem2Icon";
23
+ import { TreeItem2Provider } from "@mui/x-tree-view/TreeItem2Provider";
24
+ import { TreeItem2DragAndDropOverlay } from "@mui/x-tree-view/TreeItem2DragAndDropOverlay";
25
+ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
26
+ import { useNavigate } from "react-router-dom";
27
+ import { useTranslation } from "react-i18next";
28
+ import { useDispatch, useSelector } from "react-redux";
29
+ import { RootState } from "../redux/store";
30
+ import { IconProp } from "@fortawesome/fontawesome-svg-core";
31
+ import { useIsMobile } from "../hooks/UseMobile";
32
+ import useSession from "../hooks/UseSession";
33
+ import { findNavigationItemById, NavigationItems } from "../navigationItems";
34
+ import { DRAWER_WIDTH } from "../redux/features/common/AppLayoutSlice";
35
+
36
+ function DotIcon() {
37
+ return (
38
+ <Box
39
+ sx={{
40
+ width: 6,
41
+ height: 6,
42
+ borderRadius: "70%",
43
+ bgcolor: "warning.main",
44
+ display: "inline-block",
45
+ verticalAlign: "middle",
46
+ zIndex: 1,
47
+ mx: 1,
48
+ }}
49
+ />
50
+ );
51
+ }
52
+ declare module "react" {
53
+ interface CSSProperties {
54
+ "--tree-view-color"?: string;
55
+ "--tree-view-bg-color"?: string;
56
+ }
57
+ }
58
+
59
+ const StyledTreeItemRoot = styled(TreeItem2Root)(({ theme }) => ({
60
+ color: theme.palette.grey[400],
61
+ position: "relative",
62
+ [`& .${treeItemClasses.groupTransition}`]: {
63
+ marginLeft: theme.spacing(2.5),
64
+ },
65
+ ...theme.applyStyles("light", {
66
+ color: theme.palette.grey[800],
67
+ }),
68
+ })) as unknown as typeof TreeItem2Root;
69
+
70
+ const CustomTreeItemContent = styled(TreeItem2Content)(({ theme }) => ({
71
+ flexDirection: "row-reverse",
72
+ borderRadius: theme.spacing(0.7),
73
+ marginBottom: theme.spacing(0.5),
74
+ marginTop: theme.spacing(0.5),
75
+ padding: theme.spacing(0.5),
76
+ paddingRight: theme.spacing(1),
77
+ [`&.Mui-expanded `]: {
78
+ "&:not(.Mui-focused, .Mui-selected, .Mui-selected.Mui-focused) .labelIcon":
79
+ {
80
+ color: theme.palette.primary.dark,
81
+ ...theme.applyStyles("light", {
82
+ color: theme.palette.primary.main,
83
+ }),
84
+ },
85
+ "&::before": {
86
+ content: '""',
87
+ display: "block",
88
+ position: "absolute",
89
+ left: "16px",
90
+ top: "44px",
91
+ height: "calc(100% - 48px)",
92
+ width: "1.5px",
93
+ backgroundColor: theme.palette.grey[700],
94
+ ...theme.applyStyles("light", {
95
+ backgroundColor: theme.palette.grey[300],
96
+ }),
97
+ },
98
+ },
99
+ "&:hover": {
100
+ backgroundColor: alpha(theme.palette.primary.main, 0.1),
101
+ color: "white",
102
+ ...theme.applyStyles("light", {
103
+ color: theme.palette.primary.main,
104
+ }),
105
+ },
106
+ [`&.Mui-focused, &.Mui-selected, &.Mui-selected.Mui-focused`]: {
107
+ backgroundColor: theme.palette.primary.dark,
108
+ color: theme.palette.primary.contrastText,
109
+ ...theme.applyStyles("light", {
110
+ backgroundColor: theme.palette.primary.main,
111
+ }),
112
+ },
113
+ }));
114
+
115
+ const AnimatedCollapse = animated(Collapse);
116
+
117
+ function TransitionComponent(props: TransitionProps) {
118
+ const style = useSpring({
119
+ to: {
120
+ opacity: props.in ? 1 : 0,
121
+ transform: `translate3d(0,${props.in ? 0 : 20}px,0)`,
122
+ },
123
+ });
124
+
125
+ return <AnimatedCollapse style={style} {...props} />;
126
+ }
127
+
128
+ const StyledTreeItemLabelText = styled(Typography)({
129
+ color: "inherit",
130
+ fontWeight: 500,
131
+ }) as unknown as typeof Typography;
132
+
133
+ interface CustomLabelProps {
134
+ children: any;
135
+ icon: IconProp;
136
+ expandable?: boolean;
137
+ }
138
+
139
+ function CustomLabel({
140
+ icon,
141
+ expandable,
142
+ children,
143
+ ...other
144
+ }: CustomLabelProps) {
145
+ const { t } = useTranslation();
146
+ const appLayoutState = useSelector((state: RootState) => state.AppLayout);
147
+ return (
148
+ <TreeItem2Label
149
+ {...other}
150
+ sx={{
151
+ display: "flex",
152
+ alignItems: "center",
153
+ padding: 1,
154
+ }}
155
+ >
156
+ <FontAwesomeIcon
157
+ style={{
158
+ marginRight: appLayoutState.appDirection === "ltr" ? 7 : undefined,
159
+ marginLeft: appLayoutState.appDirection === "rtl" ? 7 : undefined,
160
+ fontSize: "1.2rem",
161
+ }}
162
+ icon={icon}
163
+ />
164
+ <StyledTreeItemLabelText variant="body2" sx={{ fontSize: 16 }}>
165
+ {t(children)}
166
+ </StyledTreeItemLabelText>
167
+ {expandable && <DotIcon />}
168
+ </TreeItem2Label>
169
+ );
170
+ }
171
+
172
+ const isExpandable = (reactChildren: React.ReactNode) => {
173
+ if (Array.isArray(reactChildren)) {
174
+ return reactChildren.length > 0 && reactChildren.some(isExpandable);
175
+ }
176
+ return Boolean(reactChildren);
177
+ };
178
+
179
+ interface CustomTreeItemProps
180
+ extends Omit<UseTreeItem2Parameters, "rootRef">,
181
+ Omit<React.HTMLAttributes<HTMLLIElement>, "onFocus"> {}
182
+
183
+ const CustomTreeItem = React.forwardRef(function CustomTreeItem(
184
+ props: CustomTreeItemProps,
185
+ ref: React.Ref<HTMLLIElement>
186
+ ) {
187
+ const { id, itemId, label, disabled, children, ...other } = props;
188
+ const {
189
+ getRootProps,
190
+ getContentProps,
191
+ getIconContainerProps,
192
+ getCheckboxProps,
193
+ getLabelProps,
194
+ getGroupTransitionProps,
195
+ getDragAndDropOverlayProps,
196
+ status,
197
+ publicAPI,
198
+ } = useTreeItem2({ id, itemId, children, label, disabled, rootRef: ref });
199
+ const item = publicAPI.getItem(itemId);
200
+ const expandable = isExpandable(children);
201
+ return (
202
+ <TreeItem2Provider itemId={itemId}>
203
+ <StyledTreeItemRoot {...getRootProps(other)}>
204
+ <CustomTreeItemContent
205
+ {...getContentProps({
206
+ className: clsx("content", {
207
+ "Mui-expanded": status.expanded,
208
+ "Mui-selected": status.selected,
209
+ "Mui-focused": status.focused,
210
+ "Mui-disabled": status.disabled,
211
+ }),
212
+ })}
213
+ >
214
+ <TreeItem2IconContainer {...getIconContainerProps()}>
215
+ <TreeItem2Icon status={status} />
216
+ </TreeItem2IconContainer>
217
+ <TreeItem2Checkbox {...getCheckboxProps()} />
218
+ <CustomLabel
219
+ {...getLabelProps({
220
+ icon: item?.icon || "book",
221
+ expandable: expandable && status.expanded,
222
+ })}
223
+ />
224
+ <TreeItem2DragAndDropOverlay {...getDragAndDropOverlayProps()} />
225
+ </CustomTreeItemContent>
226
+ {children && <TransitionComponent {...getGroupTransitionProps()} />}
227
+ </StyledTreeItemRoot>
228
+ </TreeItem2Provider>
229
+ );
230
+ });
231
+
232
+ export default function NavigationTree() {
233
+ const navigate = useNavigate();
234
+ const appLayoutState = useSelector((state: RootState) => state.AppLayout);
235
+ const dispatch = useDispatch();
236
+ const isMobile = useIsMobile();
237
+ const { isUserAuthorized } = useSession();
238
+ const filterData = (data) => {
239
+ return data
240
+ .filter(
241
+ (item: any) =>
242
+ item.authority === undefined ||
243
+ item.authority == null ||
244
+ isUserAuthorized(item.authority)
245
+ )
246
+ .map((item: any) => {
247
+ if (item.children) {
248
+ item.children = filterData(item.children);
249
+ }
250
+ return item;
251
+ });
252
+ };
253
+
254
+ const authoriedNavigationItems = filterData(NavigationItems);
255
+
256
+ return (
257
+ <RichTreeView
258
+ items={authoriedNavigationItems}
259
+ onItemClick={(event, itemId) => {
260
+ const navigationItem = findNavigationItemById(itemId, NavigationItems);
261
+ if (
262
+ navigationItem?.action === "NAVIGATION" &&
263
+ navigationItem?.actionPayload != null &&
264
+ (navigationItem.children === undefined ||
265
+ navigationItem.children === null ||
266
+ navigationItem.children.length == 0)
267
+ ) {
268
+ navigate(navigationItem?.actionPayload?.path || "");
269
+ // dispatch(AppLayoutActions.toggleSideBarState());
270
+ }
271
+ }}
272
+ sx={{
273
+ height: "fit-content",
274
+ flexGrow: 1,
275
+ maxWidth: DRAWER_WIDTH,
276
+ direction: appLayoutState.appDirection,
277
+ maxHeight: isMobile ? 300 : undefined,
278
+ overflowY: "auto",
279
+ overflowX: "auto",
280
+ }}
281
+ slots={{ item: CustomTreeItem }}
282
+ />
283
+ );
284
+ }
@@ -0,0 +1,80 @@
1
+ import Divider from "@mui/material/Divider";
2
+ import IconButton from "@mui/material/IconButton";
3
+ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
4
+ import Drawer from "@mui/material/Drawer";
5
+ import { useDispatch, useSelector } from "react-redux";
6
+ import { DrawerHeader } from "./DrawerHeader";
7
+ import { Box, Typography, useTheme } from "@mui/material";
8
+ import { RootState } from "../redux/store";
9
+ import {
10
+ AppLayoutActions,
11
+ DRAWER_WIDTH,
12
+ } from "../redux/features/common/AppLayoutSlice";
13
+ import NavigationTree from "./NavigationTree";
14
+
15
+ const SideBar: React.FC = () => {
16
+ const AppInfo = useSelector((state: RootState) => state.AppInfo);
17
+ const theme = useTheme();
18
+ const AppLayout = useSelector((state: RootState) => state.AppLayout);
19
+ const dispatch = useDispatch();
20
+ const toggleSideBar = () => {
21
+ dispatch(AppLayoutActions.toggleSideBarState());
22
+ };
23
+ return (
24
+ <Drawer
25
+ sx={{
26
+ width: DRAWER_WIDTH,
27
+ flexShrink: 0,
28
+ "& .MuiDrawer-paper": {
29
+ width: DRAWER_WIDTH,
30
+ boxSizing: "border-box",
31
+ },
32
+ }}
33
+ variant="persistent"
34
+ anchor={AppLayout.appDirection === "ltr" ? "left" : "right"}
35
+ open={AppLayout.sideBarOpened}
36
+ >
37
+ <DrawerHeader>
38
+ <Box sx={{ width: "100%" }}>
39
+ <Typography
40
+ color="primary"
41
+ sx={{
42
+ width: "100%",
43
+ textAlign: "center",
44
+ fontSize: 18,
45
+ fontWeight: "bold",
46
+ }}
47
+ >
48
+ System Content
49
+ </Typography>
50
+ <Box
51
+ sx={{
52
+ display: "flex",
53
+ alignItems: "center",
54
+ justifyContent: "space-around",
55
+ marginTop: 1,
56
+ }}
57
+ >
58
+ <Typography sx={{ fontSize: 12 }} color="textDisabled">
59
+ {AppInfo.appName}
60
+ </Typography>
61
+ <Typography sx={{ fontSize: 12 }} color="textDisabled">
62
+ V.{AppInfo.appVersion}
63
+ </Typography>
64
+ </Box>
65
+ </Box>
66
+ <IconButton onClick={toggleSideBar}>
67
+ {theme.direction === "ltr" ? (
68
+ <FontAwesomeIcon icon="angle-left" />
69
+ ) : (
70
+ <FontAwesomeIcon icon="angle-right" />
71
+ )}
72
+ </IconButton>
73
+ </DrawerHeader>
74
+ <Divider />
75
+ <NavigationTree />
76
+ </Drawer>
77
+ );
78
+ };
79
+
80
+ export default SideBar;
@@ -0,0 +1,142 @@
1
+ import { Avatar, IconButton, styled, Typography } from "@mui/material";
2
+ import MuiAppBar, { AppBarProps as MuiAppBarProps } from "@mui/material/AppBar";
3
+ import Toolbar from "@mui/material/Toolbar";
4
+ import { useDispatch, useSelector } from "react-redux";
5
+ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
6
+ import { RootState } from "../redux/store";
7
+ import { useIsMobile } from "../hooks/UseMobile";
8
+ import {
9
+ AppLayoutActions,
10
+ DRAWER_WIDTH,
11
+ } from "../redux/features/common/AppLayoutSlice";
12
+ import useAxios from "../hooks/useAxios";
13
+ import { UserSessionActions } from "../redux/features/common/UserSessionSlice";
14
+ import i18n, { changeLanguage } from "../locales/i18n";
15
+
16
+ interface AppBarProps extends MuiAppBarProps {
17
+ open?: boolean;
18
+ }
19
+
20
+ const AppBar = styled(MuiAppBar, {
21
+ shouldForwardProp: (prop) => prop !== "open",
22
+ })<AppBarProps>(({ theme }) => {
23
+ const AppLayout = useSelector((state: RootState) => state.AppLayout);
24
+ const isMobile = useIsMobile();
25
+ return {
26
+ transition: theme.transitions.create(["margin", "width"], {
27
+ easing: theme.transitions.easing.sharp,
28
+ duration: theme.transitions.duration.leavingScreen,
29
+ }),
30
+ variants: [
31
+ {
32
+ props: ({ open }) => open,
33
+ style: {
34
+ width: !isMobile ? `calc(100% - ${DRAWER_WIDTH}px)` : undefined,
35
+ marginLeft:
36
+ !isMobile && AppLayout.appDirection === "ltr"
37
+ ? `${DRAWER_WIDTH}px`
38
+ : undefined,
39
+ marginRight:
40
+ !isMobile && AppLayout.appDirection === "rtl"
41
+ ? `${DRAWER_WIDTH}px`
42
+ : undefined,
43
+ transition: theme.transitions.create(["margin", "width"], {
44
+ easing: theme.transitions.easing.easeOut,
45
+ duration: theme.transitions.duration.enteringScreen,
46
+ }),
47
+ },
48
+ },
49
+ ],
50
+ };
51
+ });
52
+
53
+ const TopBar: React.FC = () => {
54
+ const AppInfo = useSelector((state: RootState) => state.AppInfo);
55
+ const AppLayout = useSelector((state: RootState) => state.AppLayout);
56
+ const UserSession = useSelector((state: RootState) => state.UserSession);
57
+ const { handleGetRequest } = useAxios();
58
+ const isMobile = useIsMobile();
59
+ const dispatch = useDispatch();
60
+ const handleLogout = async () => {
61
+ try {
62
+ await handleGetRequest({ endPointURI: "api/auth/logout" });
63
+ } catch (error) {
64
+ console.log("logout error", error);
65
+ }
66
+ dispatch(UserSessionActions.setUnAuthenticated());
67
+ };
68
+ const toggleSideBar = () => {
69
+ dispatch(AppLayoutActions.toggleSideBarState());
70
+ };
71
+ return (
72
+ <AppBar position="fixed" open={AppLayout.sideBarOpened}>
73
+ <Toolbar>
74
+ <IconButton
75
+ color="inherit"
76
+ aria-label="open drawer"
77
+ onClick={toggleSideBar}
78
+ edge="start"
79
+ sx={[
80
+ {
81
+ mr: AppLayout.appDirection === "ltr" ? 2 : undefined,
82
+ ml: AppLayout.appDirection === "rtl" ? 2 : undefined,
83
+ },
84
+ AppLayout.sideBarOpened && { display: "none" },
85
+ ]}
86
+ >
87
+ <FontAwesomeIcon icon="bars" />
88
+ </IconButton>
89
+ <Avatar src={AppInfo.appLogo} sx={{ marginRight: 1, marginLeft: 1 }} />
90
+ <Typography variant="h6" noWrap component="div" sx={{ flex: 1 }}>
91
+ {isMobile ? "" : AppInfo.appName}
92
+ </Typography>
93
+ <IconButton
94
+ color="inherit"
95
+ onClick={() => {
96
+ dispatch(
97
+ AppLayoutActions.setThemeMode(
98
+ AppLayout.themeMode === "light" ? "dark" : "light"
99
+ )
100
+ );
101
+ localStorage.setItem(
102
+ "themeMode",
103
+ AppLayout.themeMode === "light" ? "dark" : "light"
104
+ );
105
+ }}
106
+ >
107
+ {AppLayout.themeMode === "light" ? (
108
+ <FontAwesomeIcon icon="moon" />
109
+ ) : (
110
+ <FontAwesomeIcon icon={{ prefix: "far", iconName: "sun" }} />
111
+ )}
112
+ </IconButton>
113
+ <IconButton
114
+ color="inherit"
115
+ onClick={() => {
116
+ let nextLanguage = i18n.language === "ar" ? "en" : "ar";
117
+ changeLanguage(nextLanguage);
118
+ dispatch(
119
+ AppLayoutActions.setAppDirection(
120
+ nextLanguage === "ar" ? "rtl" : "ltr"
121
+ )
122
+ );
123
+ }}
124
+ >
125
+ <FontAwesomeIcon icon="language" />
126
+ </IconButton>
127
+ <Avatar />
128
+ <div style={{ marginLeft: 5, marginRight: 5 }}>
129
+ {isMobile ? "" : UserSession.value?.userProfile?.username}
130
+ </div>
131
+ <IconButton color="inherit" onClick={handleLogout}>
132
+ <FontAwesomeIcon
133
+ rotation={AppLayout.appDirection === "rtl" ? 180 : undefined}
134
+ icon="arrow-right-from-bracket"
135
+ />
136
+ </IconButton>
137
+ </Toolbar>
138
+ </AppBar>
139
+ );
140
+ };
141
+
142
+ export default TopBar;