@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,89 @@
1
+ import { Button } from "@mui/material";
2
+ import { RecordAction } from "../DataEntryTypes";
3
+ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
4
+ import { toast } from "react-toastify";
5
+ import { useTranslation } from "react-i18next";
6
+ import useSession from "../../../../hooks/UseSession";
7
+ import { useConfirmationWindow } from "../../../../hooks/UseConfirmationWindow";
8
+
9
+ const TemplateGridMultiRecordAction: React.FC<RecordAction> = (
10
+ rowAction: RecordAction
11
+ ) => {
12
+ const { t } = useTranslation();
13
+ const session = useSession();
14
+ const { ConfirmationWindow, setOpen } = useConfirmationWindow({
15
+ body: t(rowAction?.confirmationMessage || "ACTION_CONFIRMATION"),
16
+ title: t("CONFIRMATION"),
17
+ onConfirmationCallBk: async () => {
18
+ await rowAction?.actionFn(
19
+ rowAction.recordsToProcessActionOn,
20
+ rowAction.recordIdsToProcessActionOn
21
+ );
22
+ if (rowAction?.reloadData) {
23
+ rowAction.reloadData();
24
+ }
25
+ },
26
+ });
27
+ let isActionAllowed = true;
28
+ if (rowAction.authority) {
29
+ isActionAllowed = session.isUserAuthorized(rowAction.authority);
30
+ }
31
+
32
+ if (isActionAllowed) {
33
+ return (
34
+ <>
35
+ <ConfirmationWindow />
36
+ <Button
37
+ onClick={async () => {
38
+ if (
39
+ rowAction?.recordsToProcessActionOn &&
40
+ rowAction?.recordsToProcessActionOn.length > 0
41
+ ) {
42
+ if (rowAction?.preActionValidation) {
43
+ for (const record of rowAction.recordsToProcessActionOn) {
44
+ if (!rowAction.preActionValidation(record)) {
45
+ return;
46
+ }
47
+ }
48
+ }
49
+ if (rowAction?.isConfirmationRequired === true) {
50
+ setOpen(true);
51
+ } else {
52
+ await rowAction.actionFn(
53
+ rowAction.recordsToProcessActionOn,
54
+ rowAction.recordIdsToProcessActionOn
55
+ );
56
+ if (rowAction?.reloadData) {
57
+ rowAction.reloadData();
58
+ }
59
+ }
60
+ } else {
61
+ toast.error(t("AT_LEAST_ONE_RECORD_SELECTED_MESSAGE"));
62
+ }
63
+ }}
64
+ variant={
65
+ rowAction?.label
66
+ ? "outlined"
67
+ : rowAction?.formActionProps?.actionButtonVariant
68
+ ? rowAction.formActionProps.actionButtonVariant
69
+ : "text"
70
+ }
71
+ size="small"
72
+ color={rowAction?.formActionProps?.actionButtonColor || "primary"}
73
+ >
74
+ {rowAction?.icon ? (
75
+ <FontAwesomeIcon
76
+ style={{ marginRight: 5, marginLeft: 5 }}
77
+ icon={rowAction.icon}
78
+ />
79
+ ) : (
80
+ <></>
81
+ )}
82
+ {rowAction?.label ? t(rowAction.label) : <></>}
83
+ </Button>
84
+ </>
85
+ );
86
+ }
87
+ };
88
+
89
+ export default TemplateGridMultiRecordAction;
@@ -0,0 +1,92 @@
1
+ import { Tooltip } from "@mui/material";
2
+ import { GridActionsCellItem } from "@mui/x-data-grid-premium";
3
+ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
4
+ import { RecordAction } from "../DataEntryTypes";
5
+ import { useTranslation } from "react-i18next";
6
+ import useSession from "../../../../hooks/UseSession";
7
+ import { useConfirmationWindow } from "../../../../hooks/UseConfirmationWindow";
8
+
9
+ const TemplateGridRecordAction: React.FC<RecordAction> = (
10
+ rowAction: RecordAction
11
+ ) => {
12
+ const { t } = useTranslation();
13
+ const session = useSession();
14
+ const { ConfirmationWindow, setOpen } = useConfirmationWindow({
15
+ body: t(rowAction?.confirmationMessage || "ACTION_CONFIRMATION"),
16
+ title: t("CONFIRMATION"),
17
+ onConfirmationCallBk: async () => {
18
+ await rowAction?.actionFn(rowAction.record);
19
+ if (rowAction?.reloadData) {
20
+ rowAction.reloadData();
21
+ }
22
+ },
23
+ });
24
+ let isActionAllowed = true;
25
+ if (rowAction.authority) {
26
+ isActionAllowed = session.isUserAuthorized(rowAction.authority);
27
+ }
28
+ let iconStyle: any = {};
29
+ if (rowAction?.getActionIconStyleForRecord) {
30
+ iconStyle = rowAction.getActionIconStyleForRecord(rowAction.record);
31
+ }
32
+ let isActionVisibleForRecord = true;
33
+ if (rowAction?.isActionVisibleForRecord) {
34
+ isActionVisibleForRecord = rowAction?.isActionVisibleForRecord(
35
+ rowAction.record
36
+ );
37
+ }
38
+ let isActionDisabledForRecord = false;
39
+ if (rowAction?.isActionDisabledForRecord) {
40
+ isActionDisabledForRecord = rowAction.isActionDisabledForRecord(
41
+ rowAction.record
42
+ );
43
+ }
44
+ if (isActionAllowed && isActionVisibleForRecord) {
45
+ return (
46
+ <>
47
+ <ConfirmationWindow />
48
+ <GridActionsCellItem
49
+ disabled={isActionDisabledForRecord}
50
+ icon={
51
+ <Tooltip title={rowAction?.label ? t(rowAction.label) : ""}>
52
+ <FontAwesomeIcon
53
+ icon={rowAction.icon}
54
+ style={{
55
+ ...iconStyle,
56
+ color: isActionDisabledForRecord
57
+ ? "gray"
58
+ : iconStyle?.color != undefined
59
+ ? iconStyle.color
60
+ : undefined,
61
+ }}
62
+ />
63
+ </Tooltip>
64
+ }
65
+ showInMenu={rowAction?.gridActionProps?.showInMenu || false}
66
+ label={""}
67
+ className="textPrimary"
68
+ color="inherit"
69
+ onClick={async () => {
70
+ if (!isActionDisabledForRecord) {
71
+ if (rowAction?.preActionValidation) {
72
+ if (!rowAction.preActionValidation(rowAction.record)) {
73
+ return;
74
+ }
75
+ }
76
+ if (rowAction?.isConfirmationRequired === true) {
77
+ setOpen(true);
78
+ } else {
79
+ await rowAction.actionFn(rowAction.record);
80
+ if (rowAction?.reloadData) {
81
+ rowAction.reloadData();
82
+ }
83
+ }
84
+ }
85
+ }}
86
+ />
87
+ </>
88
+ );
89
+ }
90
+ };
91
+
92
+ export default TemplateGridRecordAction;
@@ -0,0 +1,228 @@
1
+ import {
2
+ Badge,
3
+ Box,
4
+ Button,
5
+ Divider,
6
+ IconButton,
7
+ InputAdornment,
8
+ MenuItem,
9
+ styled,
10
+ TextField,
11
+ Tooltip,
12
+ } from "@mui/material";
13
+ import {
14
+ Toolbar,
15
+ ToolbarButton,
16
+ ColumnsPanelTrigger,
17
+ FilterPanelTrigger,
18
+ QuickFilter,
19
+ QuickFilterControl,
20
+ QuickFilterClear,
21
+ QuickFilterTrigger,
22
+ GridViewColumnIcon,
23
+ GridFilterListIcon,
24
+ ExportExcel,
25
+ } from "@mui/x-data-grid-premium";
26
+ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
27
+ import TemplateGridMultiRecordAction from "./TemplateGridMultiRecordAction";
28
+ import { getGridSelection } from "../DataEntryUtil";
29
+ import { useTranslation } from "react-i18next";
30
+ import { TemplateGridTopBarProps } from "../DataEntryTypes";
31
+ import useSession from "../../../../hooks/UseSession";
32
+
33
+ type OwnerState = {
34
+ expanded: boolean;
35
+ };
36
+
37
+ const StyledQuickFilter = styled(QuickFilter)({
38
+ display: "grid",
39
+ alignItems: "center",
40
+ });
41
+
42
+ const StyledToolbarButton = styled(ToolbarButton)<{ ownerState: OwnerState }>(
43
+ ({ theme, ownerState }) => ({
44
+ gridArea: "1 / 1",
45
+ width: "min-content",
46
+ height: "min-content",
47
+ zIndex: 1,
48
+ opacity: ownerState.expanded ? 0 : 1,
49
+ pointerEvents: ownerState.expanded ? "none" : "auto",
50
+ transition: theme.transitions.create(["opacity"]),
51
+ })
52
+ );
53
+
54
+ const StyledTextField = styled(TextField)<{
55
+ ownerState: OwnerState;
56
+ }>(({ theme, ownerState }) => ({
57
+ gridArea: "1 / 1",
58
+ overflowX: "clip",
59
+ width: ownerState.expanded ? 260 : "var(--trigger-width)",
60
+ opacity: ownerState.expanded ? 1 : 0,
61
+ transition: theme.transitions.create(["width", "opacity"]),
62
+ }));
63
+
64
+ const TemplateGridTopBar: React.FC<TemplateGridTopBarProps> = (
65
+ props: TemplateGridTopBarProps
66
+ ) => {
67
+ const { t } = useTranslation();
68
+ const session = useSession();
69
+ const isCreationAuthorized = props?.templateProps?.editAction?.authority
70
+ ? session.isUserAuthorized(props.templateProps.editAction.authority)
71
+ : true;
72
+ const isCreationEnabled = props?.templateProps?.disableDefaultAction || true;
73
+ const gridSelection = getGridSelection(
74
+ props?.templateProps?.rowSelectionModel || {
75
+ ids: new Set(),
76
+ type: "include",
77
+ },
78
+ props?.templateProps?.data || [],
79
+ props?.templateProps?.keyColumnName || "id"
80
+ );
81
+ return (
82
+ <Toolbar>
83
+ {isCreationEnabled &&
84
+ isCreationAuthorized &&
85
+ props?.templateProps?.editMode?.editMode != "none" ? (
86
+ <Button onClick={props?.handleCreateNewRecord}>
87
+ <FontAwesomeIcon
88
+ icon="add"
89
+ style={{ marginRight: 5, marginLeft: 5 }}
90
+ />
91
+ {t("ADD_BTN_LABEL")}
92
+ </Button>
93
+ ) : (
94
+ <></>
95
+ )}
96
+ {props?.templateProps?.rowActions ? (
97
+ props.templateProps.rowActions.map((rowAction) =>
98
+ rowAction?.gridActionProps?.multiRecord === true ? (
99
+ <TemplateGridMultiRecordAction
100
+ {...rowAction}
101
+ reloadData={async () => {
102
+ props.templateProps.apiActions.reloadData(
103
+ props?.templateProps?.gridLoadParametersValues
104
+ );
105
+ }}
106
+ recordIdsToProcessActionOn={gridSelection.selectedRecordIds}
107
+ recordsToProcessActionOn={gridSelection.selectedRecords}
108
+ />
109
+ ) : (
110
+ <></>
111
+ )
112
+ )
113
+ ) : (
114
+ <></>
115
+ )}
116
+ <Box sx={{ flex: 1, mx: 0.5 }}>{props?.templateProps?.tBar}</Box>
117
+
118
+ <Tooltip title="Columns">
119
+ <ColumnsPanelTrigger render={<ToolbarButton />}>
120
+ <GridViewColumnIcon fontSize="small" />
121
+ </ColumnsPanelTrigger>
122
+ </Tooltip>
123
+
124
+ <Tooltip title="Filters">
125
+ <FilterPanelTrigger
126
+ render={(props, state) => (
127
+ <ToolbarButton {...props} color="default">
128
+ <Badge
129
+ badgeContent={state.filterCount}
130
+ color="primary"
131
+ variant="dot"
132
+ >
133
+ <GridFilterListIcon fontSize="small" />
134
+ </Badge>
135
+ </ToolbarButton>
136
+ )}
137
+ />
138
+ </Tooltip>
139
+
140
+ {props?.templateProps?.gridStateKey ? (
141
+ <Tooltip title={t("RESET_GRID_STATE")}>
142
+ <IconButton onClick={props?.clearGridState}>
143
+ <FontAwesomeIcon icon="eraser" />
144
+ </IconButton>
145
+ </Tooltip>
146
+ ) : (
147
+ <></>
148
+ )}
149
+
150
+ <Divider
151
+ orientation="vertical"
152
+ variant="middle"
153
+ flexItem
154
+ sx={{ mx: 0.5 }}
155
+ />
156
+
157
+ <Tooltip title={t("EXPORT_EXECL_LABEL")}>
158
+ <ExportExcel render={<MenuItem />}>
159
+ <FontAwesomeIcon icon="file-excel" color="green" />
160
+ </ExportExcel>
161
+ </Tooltip>
162
+
163
+ <StyledQuickFilter>
164
+ <QuickFilterTrigger
165
+ render={(triggerProps, state) => (
166
+ <Tooltip title={t("SEARCH_BTN_LABEL")} enterDelay={0}>
167
+ <StyledToolbarButton
168
+ {...triggerProps}
169
+ ownerState={{ expanded: state.expanded }}
170
+ color="default"
171
+ aria-disabled={state.expanded}
172
+ >
173
+ <FontAwesomeIcon icon="search" />
174
+ </StyledToolbarButton>
175
+ </Tooltip>
176
+ )}
177
+ />
178
+ <QuickFilterControl
179
+ render={({ ref, ...controlProps }, state) => (
180
+ <StyledTextField
181
+ {...controlProps}
182
+ ownerState={{ expanded: state.expanded }}
183
+ inputRef={ref}
184
+ aria-label="Search"
185
+ placeholder={`${t("SEARCH_BTN_LABEL")}...`}
186
+ size="small"
187
+ slotProps={{
188
+ input: {
189
+ startAdornment: (
190
+ <InputAdornment position="start">
191
+ <FontAwesomeIcon icon="search" />
192
+ </InputAdornment>
193
+ ),
194
+ endAdornment: state.value ? (
195
+ <InputAdornment position="end">
196
+ <QuickFilterClear
197
+ edge="end"
198
+ size="small"
199
+ aria-label="Clear search"
200
+ // material={{ sx: { marginRight: -0.75 } }}
201
+ >
202
+ <FontAwesomeIcon icon="xmark" />
203
+ </QuickFilterClear>
204
+ </InputAdornment>
205
+ ) : null,
206
+ ...controlProps.slotProps?.input,
207
+ },
208
+ ...controlProps.slotProps,
209
+ }}
210
+ />
211
+ )}
212
+ />
213
+ </StyledQuickFilter>
214
+
215
+ <IconButton
216
+ onClick={() => {
217
+ props.templateProps.apiActions.reloadData(
218
+ props?.templateProps?.gridLoadParametersValues
219
+ );
220
+ }}
221
+ >
222
+ <FontAwesomeIcon icon="refresh" />
223
+ </IconButton>
224
+ </Toolbar>
225
+ );
226
+ };
227
+
228
+ export default TemplateGridTopBar;
@@ -0,0 +1,125 @@
1
+ import { useDispatch, useSelector } from "react-redux";
2
+ import { RootState } from "../../../redux/store";
3
+ import { setStoreData } from "../../../redux/features/business/CommonStoreSlice";
4
+ import useSession from "../../../hooks/UseSession";
5
+ import useAxios from "../../../hooks/useAxios";
6
+
7
+ export type ApiActionsProps = {
8
+ findAll?: string;
9
+ commonStoreKey?: string;
10
+ setData?: any;
11
+ findById?: string;
12
+ findByIdParamName?: string;
13
+ save?: string;
14
+ deleteById?: string;
15
+ deleteByIdParamName?: string;
16
+ };
17
+
18
+ export type ApiActions = {
19
+ reloadData: (params?: any) => Promise<void>;
20
+ saveRecord: (record: any) => Promise<any | null>;
21
+ loadRecordById: (recordId: any) => Promise<any>;
22
+ deleteRecordById: (recordId: any) => Promise<boolean>;
23
+ };
24
+
25
+ const useApiActions: (apiActionsProps: ApiActionsProps) => ApiActions = (
26
+ apiActionsProps: ApiActionsProps
27
+ ) => {
28
+ const CommonStores = useSelector((state: RootState) => state.commonStores);
29
+ const dispatch = useDispatch();
30
+ const session = useSession();
31
+ const { handleGetRequest, handlePostRequest, handleDeleteRequest } =
32
+ useAxios();
33
+ const reloadData = async (params?: any) => {
34
+ if (apiActionsProps?.commonStoreKey) {
35
+ const storeKeys = Object.keys(CommonStores);
36
+ for (const storeKey of storeKeys) {
37
+ if (storeKey === apiActionsProps.commonStoreKey) {
38
+ if (
39
+ (CommonStores[storeKey]?.authority === undefined ||
40
+ CommonStores[storeKey]?.authority === null ||
41
+ session.isUserAuthorized(CommonStores[storeKey]?.authority)) &&
42
+ CommonStores[storeKey]?.url != ""
43
+ ) {
44
+ await handleGetRequest({
45
+ endPointURI: CommonStores[storeKey].url,
46
+ showMask: false,
47
+ successCallBkFn: (response: any) => {
48
+ dispatch(setStoreData({ storeKey, data: response.data }));
49
+ apiActionsProps.setData(response.data);
50
+ },
51
+ failureCallBkFn: () => {
52
+ dispatch(setStoreData({ storeKey, data: [] }));
53
+ apiActionsProps.setData([]);
54
+ },
55
+ });
56
+ break;
57
+ }
58
+ }
59
+ }
60
+ } else if (apiActionsProps?.findAll) {
61
+ await handleGetRequest({
62
+ endPointURI: apiActionsProps.findAll,
63
+ showMask: true,
64
+ parameters: params || {},
65
+ successCallBkFn: (response: any) => {
66
+ apiActionsProps.setData(response.data);
67
+ },
68
+ });
69
+ }
70
+ };
71
+ const saveRecord = async (record: any) => {
72
+ let savedRecord = null;
73
+ if (apiActionsProps?.save) {
74
+ await handlePostRequest({
75
+ endPointURI: apiActionsProps.save,
76
+ data: record,
77
+ showMask: true,
78
+ successCallBkFn: (response: any) => {
79
+ savedRecord = response.data;
80
+ },
81
+ });
82
+ }
83
+ return savedRecord;
84
+ };
85
+ const loadRecordById = async (recordId: any) => {
86
+ let record: any = null;
87
+ if (apiActionsProps?.findById) {
88
+ const parameters: any = {};
89
+ const keyParameterName = apiActionsProps?.findByIdParamName || "id";
90
+ parameters[keyParameterName] = recordId;
91
+ await handleGetRequest({
92
+ endPointURI: apiActionsProps.findById,
93
+ showMask: true,
94
+ parameters,
95
+ successCallBkFn: (response: any) => {
96
+ record = response.data;
97
+ },
98
+ });
99
+ }
100
+ return record;
101
+ };
102
+ const deleteRecordById = async (recordId: any) => {
103
+ let result = true;
104
+ if (apiActionsProps?.deleteById) {
105
+ const parameters: any = {};
106
+ const keyParameterName = apiActionsProps?.deleteByIdParamName || "id";
107
+ parameters[keyParameterName] = recordId;
108
+ await handleDeleteRequest({
109
+ endPointURI: apiActionsProps.deleteById,
110
+ showMask: true,
111
+ parameters,
112
+ successCallBkFn: () => {
113
+ result = true;
114
+ },
115
+ failureCallBkFn: () => {
116
+ result = false;
117
+ },
118
+ });
119
+ }
120
+ return result;
121
+ };
122
+ return { reloadData, loadRecordById, saveRecord, deleteRecordById };
123
+ };
124
+
125
+ export default useApiActions;