@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.
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/App.tsx +31 -0
- package/src/components/admin/AttachmentGrid.tsx +116 -0
- package/src/components/admin/AuthorityGrid.tsx +88 -0
- package/src/components/admin/BluePrintGrid.tsx +55 -0
- package/src/components/admin/BluePrintPageGrid.tsx +85 -0
- package/src/components/admin/BluePrintPointGrid.tsx +85 -0
- package/src/components/admin/DashboardGrid.tsx +95 -0
- package/src/components/admin/DashboardWidgetGrid.tsx +75 -0
- package/src/components/admin/DataQueryGrid.tsx +75 -0
- package/src/components/admin/DataQueryParameterGrid.tsx +98 -0
- package/src/components/admin/DatasourceConnectionGrid.tsx +98 -0
- package/src/components/admin/EmployeeGrid.tsx +105 -0
- package/src/components/admin/EntityParameterGrid.tsx +125 -0
- package/src/components/admin/ExcelUploaderDetailGrid.tsx +78 -0
- package/src/components/admin/ExcelUploaderHeaderGrid.tsx +78 -0
- package/src/components/admin/LookupGrid.tsx +95 -0
- package/src/components/admin/MailAttachmentGrid.tsx +65 -0
- package/src/components/admin/MailBodyGrid.tsx +105 -0
- package/src/components/admin/MailNotificationQueueGrid.tsx +131 -0
- package/src/components/admin/MailRecipientGrid.tsx +75 -0
- package/src/components/admin/MailTemplateGrid.tsx +145 -0
- package/src/components/admin/NewTableGrid.tsx +65 -0
- package/src/components/admin/NotificationGrid.tsx +115 -0
- package/src/components/admin/NotificationQueueGrid.tsx +125 -0
- package/src/components/admin/OrganizationApplicationGrid.tsx +81 -0
- package/src/components/admin/OrganizationGrid.tsx +65 -0
- package/src/components/admin/OrganizationRankGrid.tsx +85 -0
- package/src/components/admin/OrganizationUnitGrid.tsx +85 -0
- package/src/components/admin/OrganizationUserGrid.tsx +75 -0
- package/src/components/admin/OrganizationUserRoleGrid.tsx +98 -0
- package/src/components/admin/ReportGrid.tsx +155 -0
- package/src/components/admin/ReportParameterGrid.tsx +95 -0
- package/src/components/admin/RoleAuthorityGrid.tsx +65 -0
- package/src/components/admin/RoleGrid.tsx +78 -0
- package/src/components/admin/UserAccountGrid.tsx +65 -0
- package/src/components/admin/UserRequestGrid.tsx +145 -0
- package/src/components/admin/WidgetGrid.tsx +175 -0
- package/src/components/admin/WorkflowDocumentActionGrid.tsx +111 -0
- package/src/components/admin/WorkflowDocumentActionHistoryGrid.tsx +111 -0
- package/src/components/admin/WorkflowDocumentActionMailGrid.tsx +71 -0
- package/src/components/admin/WorkflowDocumentGrid.tsx +185 -0
- package/src/components/admin/WorkflowDocumentMailLogGrid.tsx +141 -0
- package/src/components/admin/WorkflowDocumentStatusGrid.tsx +121 -0
- package/src/components/common/Home.tsx +31 -0
- package/src/components/common/LanguageSwitcher.tsx +25 -0
- package/src/components/common/LayoutHandlers.tsx +12 -0
- package/src/components/common/LoadingMask.tsx +19 -0
- package/src/components/common/Login.tsx +183 -0
- package/src/components/templates/DataEntryTemplates/DataEntryTypes.ts +288 -0
- package/src/components/templates/DataEntryTemplates/DataEntryUtil.ts +201 -0
- package/src/components/templates/DataEntryTemplates/TemplateDataForm/FormAction.tsx +60 -0
- package/src/components/templates/DataEntryTemplates/TemplateDataForm/FormElementField.tsx +194 -0
- package/src/components/templates/DataEntryTemplates/TemplateDataForm/FormElementGroup.tsx +98 -0
- package/src/components/templates/DataEntryTemplates/TemplateDataForm/FormFields/CheckBox.tsx +64 -0
- package/src/components/templates/DataEntryTemplates/TemplateDataForm/FormFields/ComboBox.tsx +94 -0
- package/src/components/templates/DataEntryTemplates/TemplateDataForm/FormFields/Datefield.tsx +65 -0
- package/src/components/templates/DataEntryTemplates/TemplateDataForm/FormFields/DatetimeField.tsx +64 -0
- package/src/components/templates/DataEntryTemplates/TemplateDataForm/FormFields/FiltersPanel.tsx +237 -0
- package/src/components/templates/DataEntryTemplates/TemplateDataForm/FormFields/TemplateTextField.tsx +9 -0
- package/src/components/templates/DataEntryTemplates/TemplateDataForm/TemplateForm.tsx +256 -0
- package/src/components/templates/DataEntryTemplates/TemplateDataGrid/DataGridColumnsUtil.tsx +188 -0
- package/src/components/templates/DataEntryTemplates/TemplateDataGrid/TemplateGrid.tsx +844 -0
- package/src/components/templates/DataEntryTemplates/TemplateDataGrid/TemplateGridMultiRecordAction.tsx +89 -0
- package/src/components/templates/DataEntryTemplates/TemplateDataGrid/TemplateGridRecordAction.tsx +92 -0
- package/src/components/templates/DataEntryTemplates/TemplateDataGrid/TemplateGridTopBar.tsx +228 -0
- package/src/components/templates/DataEntryTemplates/useApiActions.ts +125 -0
- package/src/components/templates/TransferList.tsx +250 -0
- package/src/components/templates/Window/ConfirmationWindow.tsx +55 -0
- package/src/components/templates/visuals/TemplateDashboard.tsx +126 -0
- package/src/components/templates/visuals/charts/TemplateBarChart.tsx +16 -0
- package/src/components/templates/visuals/charts/TemplateDataCard.tsx +60 -0
- package/src/components/templates/visuals/charts/TemplateGauge.tsx +16 -0
- package/src/components/templates/visuals/charts/TemplateLineChart.tsx +16 -0
- package/src/components/templates/visuals/charts/TemplateLineProgress.tsx +40 -0
- package/src/components/templates/visuals/charts/TemplatePieChart.tsx +25 -0
- package/src/hooks/UseConfirmationWindow.tsx +54 -0
- package/src/hooks/UseMobile.tsx +13 -0
- package/src/hooks/UseSession.tsx +26 -0
- package/src/hooks/UseWindow.tsx +106 -0
- package/src/hooks/useAxios.tsx +271 -0
- package/src/hooks/useLoadingMask.tsx +16 -0
- package/src/layout/DrawerHeader.tsx +10 -0
- package/src/layout/Layout.tsx +122 -0
- package/src/layout/MainContent.tsx +43 -0
- package/src/layout/MobileDrawer.tsx +103 -0
- package/src/layout/NavigationTree.tsx +284 -0
- package/src/layout/SideBar.tsx +80 -0
- package/src/layout/TopBar.tsx +142 -0
- package/src/locales/arabic/adminLocalsAr.json +356 -0
- package/src/locales/arabic/common.json +34 -0
- package/src/locales/arabic/index.ts +7 -0
- package/src/locales/english/adminLocalsEn.json +356 -0
- package/src/locales/english/common.json +33 -0
- package/src/locales/english/index.ts +6 -0
- package/src/locales/english/index.tsx +0 -0
- package/src/locales/i18n.ts +15 -0
- package/src/locales/index.ts +9 -0
- package/src/navigationItems/Administration/adminNavigationItems.tsx +182 -0
- package/src/navigationItems/Administration/index.tsx +71 -0
- package/src/navigationItems/common/CommonNavigationItems.tsx +12 -0
- package/src/navigationItems/common/index.tsx +7 -0
- package/src/navigationItems/index.tsx +34 -0
- package/src/redux/features/administration/AdministrationStoresMetaData.ts +72 -0
- package/src/redux/features/business/BusinessStoresMetaData.ts +3 -0
- package/src/redux/features/business/CommonStoreSlice.ts +37 -0
- package/src/redux/features/common/AppInfoSlice.ts +30 -0
- package/src/redux/features/common/AppLayoutSlice.ts +37 -0
- package/src/redux/features/common/LoadingMaskSlice.ts +30 -0
- package/src/redux/features/common/UserSessionSlice.ts +62 -0
- package/src/redux/store.ts +10 -10
- package/src/routes/administration/adminRoutes.tsx +259 -0
- package/src/routes/administration/index.ts +4 -0
- package/src/routes/index.ts +11 -0
- package/src/routes/types/index.ts +5 -0
- package/src/theme/DarkThemeOptions.ts +30 -0
- package/src/theme/LightThemeOptions.ts +34 -0
- package/src/util/AppUtils.ts +18 -0
- package/src/util/constants.ts +2 -0
- package/tsconfig.json +2 -2
- package/src/redux/CounterSlice.ts +0 -17
package/src/components/templates/DataEntryTemplates/TemplateDataForm/FormFields/FiltersPanel.tsx
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Accordion,
|
|
3
|
+
AccordionActions,
|
|
4
|
+
AccordionDetails,
|
|
5
|
+
AccordionSummary,
|
|
6
|
+
Box,
|
|
7
|
+
Button,
|
|
8
|
+
Grid,
|
|
9
|
+
TextField,
|
|
10
|
+
} from "@mui/material";
|
|
11
|
+
|
|
12
|
+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
13
|
+
import { useEffect } from "react";
|
|
14
|
+
import Datefield from "./Datefield";
|
|
15
|
+
import DatetimeField from "./DatetimeField";
|
|
16
|
+
import CheckBox from "./CheckBox";
|
|
17
|
+
import ComboBox from "./ComboBox";
|
|
18
|
+
import * as z from "zod";
|
|
19
|
+
import { useForm } from "react-hook-form";
|
|
20
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
21
|
+
|
|
22
|
+
export interface FilterProp {
|
|
23
|
+
type: "text" | "number" | "date" | "datetime" | "boolean" | "droplist";
|
|
24
|
+
label?: string;
|
|
25
|
+
field: string;
|
|
26
|
+
defaultValue?: any;
|
|
27
|
+
options?: any;
|
|
28
|
+
displayField?: any;
|
|
29
|
+
valueField?: any;
|
|
30
|
+
mandatory?: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface FilterPanelProp {
|
|
34
|
+
filters: Array<FilterProp>;
|
|
35
|
+
filterValueState: any;
|
|
36
|
+
setFilterValueState: any;
|
|
37
|
+
submitAction: any;
|
|
38
|
+
actionButtonLabel?: string;
|
|
39
|
+
actionButtonIcon?: any;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const FiltersPanel: React.FC<FilterPanelProp> = (props) => {
|
|
43
|
+
const validationObject: any = {};
|
|
44
|
+
const initialValues: any = {};
|
|
45
|
+
const submitAction = () => {
|
|
46
|
+
if (props.submitAction !== undefined && props.submitAction != null) {
|
|
47
|
+
props.submitAction();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
for (let filter of props.filters) {
|
|
51
|
+
initialValues[filter.field] = filter.defaultValue;
|
|
52
|
+
let x = null;
|
|
53
|
+
if (filter.mandatory === true) {
|
|
54
|
+
x = z
|
|
55
|
+
.string({ message: "This field is required" })
|
|
56
|
+
.min(1, { message: "This field is required" });
|
|
57
|
+
} else {
|
|
58
|
+
x = z.string().optional;
|
|
59
|
+
}
|
|
60
|
+
validationObject[filter.field] = x;
|
|
61
|
+
}
|
|
62
|
+
const schema = z.object(validationObject);
|
|
63
|
+
type FormData = z.infer<typeof schema>;
|
|
64
|
+
const handleFieldChange = (fieldName, fieldValue) => {
|
|
65
|
+
setValue(fieldName, fieldValue);
|
|
66
|
+
if (props.setFilterValueState) {
|
|
67
|
+
props.setFilterValueState((oldState) => {
|
|
68
|
+
let newState = structuredClone(oldState);
|
|
69
|
+
newState[fieldName] = fieldValue;
|
|
70
|
+
return newState;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const {
|
|
75
|
+
handleSubmit,
|
|
76
|
+
watch,
|
|
77
|
+
setValue,
|
|
78
|
+
formState: { errors },
|
|
79
|
+
} = useForm<FormData>({
|
|
80
|
+
resolver: zodResolver(schema),
|
|
81
|
+
});
|
|
82
|
+
const formValues = watch();
|
|
83
|
+
return (
|
|
84
|
+
<Accordion
|
|
85
|
+
sx={{ width: "100%", marginBottom: 2 }}
|
|
86
|
+
disableGutters
|
|
87
|
+
square
|
|
88
|
+
defaultExpanded={true}
|
|
89
|
+
>
|
|
90
|
+
<AccordionSummary expandIcon={<FontAwesomeIcon icon="caret-down" />}>
|
|
91
|
+
<Box
|
|
92
|
+
sx={{
|
|
93
|
+
display: "flex",
|
|
94
|
+
alignItems: "center",
|
|
95
|
+
justifyContent: "center",
|
|
96
|
+
}}
|
|
97
|
+
>
|
|
98
|
+
<FontAwesomeIcon
|
|
99
|
+
icon="magnifying-glass"
|
|
100
|
+
style={{ marginLeft: 4, marginRight: 4 }}
|
|
101
|
+
/>
|
|
102
|
+
Filters
|
|
103
|
+
</Box>
|
|
104
|
+
</AccordionSummary>
|
|
105
|
+
<AccordionDetails>
|
|
106
|
+
<Grid container spacing={2}>
|
|
107
|
+
{props.filters !== undefined &&
|
|
108
|
+
props.filters != null &&
|
|
109
|
+
props.filters.map((filter, index) => {
|
|
110
|
+
if (filter.type === "text" || filter.type === "number") {
|
|
111
|
+
return (
|
|
112
|
+
<Grid item>
|
|
113
|
+
<TextField
|
|
114
|
+
sx={{ width: 300 }}
|
|
115
|
+
type={filter.type}
|
|
116
|
+
label={filter?.label || ""}
|
|
117
|
+
helperText={<>{errors[filter.field]?.message || ""}</>}
|
|
118
|
+
// value={props.filterValueState[filter.field]}
|
|
119
|
+
// onChange={(e: any) => {
|
|
120
|
+
// handleFieldChange(filter.field, e.target.value);
|
|
121
|
+
// }}
|
|
122
|
+
value={props?.filterValueState[filter.field]}
|
|
123
|
+
onChange={(e: any) => {
|
|
124
|
+
handleFieldChange(filter.field, e.target.value);
|
|
125
|
+
}}
|
|
126
|
+
/>
|
|
127
|
+
</Grid>
|
|
128
|
+
);
|
|
129
|
+
} else if (filter.type === "date") {
|
|
130
|
+
return (
|
|
131
|
+
<Grid item>
|
|
132
|
+
<Datefield
|
|
133
|
+
sx={{ width: 300 }}
|
|
134
|
+
label={filter?.label || ""}
|
|
135
|
+
// value={props.filterValueState[filter.field]}
|
|
136
|
+
// onChangeCallBack={(v: any) => {
|
|
137
|
+
// handleFieldChange(filter.field, v);
|
|
138
|
+
// }}
|
|
139
|
+
helperText={<>{errors[filter.field]?.message || ""}</>}
|
|
140
|
+
// value={formValues[filter.field]}
|
|
141
|
+
value={props?.filterValueState[filter.field]}
|
|
142
|
+
onChangeCallBack={(v: any) => {
|
|
143
|
+
handleFieldChange(filter.field, v);
|
|
144
|
+
}}
|
|
145
|
+
/>
|
|
146
|
+
</Grid>
|
|
147
|
+
);
|
|
148
|
+
} else if (filter.type === "datetime") {
|
|
149
|
+
return (
|
|
150
|
+
<Grid item>
|
|
151
|
+
<DatetimeField
|
|
152
|
+
sx={{ width: 300 }}
|
|
153
|
+
label={filter?.label || ""}
|
|
154
|
+
// value={props.filterValueState[filter.field]}
|
|
155
|
+
// onChangeCallBack={(v: any) => {
|
|
156
|
+
// handleFieldChange(filter.field, v);
|
|
157
|
+
// }}
|
|
158
|
+
helperText={<>{errors[filter.field]?.message || ""}</>}
|
|
159
|
+
// value={formValues[filter.field]}
|
|
160
|
+
value={props?.filterValueState[filter.field]}
|
|
161
|
+
onChangeCallBack={(v: any) => {
|
|
162
|
+
handleFieldChange(filter.field, v);
|
|
163
|
+
}}
|
|
164
|
+
/>
|
|
165
|
+
</Grid>
|
|
166
|
+
);
|
|
167
|
+
} else if (filter.type === "boolean") {
|
|
168
|
+
return (
|
|
169
|
+
<Grid item>
|
|
170
|
+
<CheckBox
|
|
171
|
+
sx={{ width: 300 }}
|
|
172
|
+
label={filter?.label || ""}
|
|
173
|
+
// value={props.filterValueState[filter.field]}
|
|
174
|
+
// onChangeCallBack={(v: any) => {
|
|
175
|
+
// handleFieldChange(filter.field, v);
|
|
176
|
+
// }}
|
|
177
|
+
// value={formValues[filter.field]}
|
|
178
|
+
value={props?.filterValueState[filter.field]}
|
|
179
|
+
onChangeCallBack={(v: any) => {
|
|
180
|
+
handleFieldChange(filter.field, v);
|
|
181
|
+
}}
|
|
182
|
+
/>
|
|
183
|
+
</Grid>
|
|
184
|
+
);
|
|
185
|
+
} else if (filter.type === "droplist") {
|
|
186
|
+
return (
|
|
187
|
+
<Grid item>
|
|
188
|
+
<ComboBox
|
|
189
|
+
sx={{ width: 300 }}
|
|
190
|
+
label={filter?.label || ""}
|
|
191
|
+
options={filter.options}
|
|
192
|
+
displayField={filter.displayField}
|
|
193
|
+
valueField={filter.valueField}
|
|
194
|
+
// value={props.filterValueState[filter.field]}
|
|
195
|
+
// onChangeCallBack={(v: any) => {
|
|
196
|
+
// handleFieldChange(filter.field, v);
|
|
197
|
+
// }}
|
|
198
|
+
errorMessage={errors[filter.field]?.message}
|
|
199
|
+
// value={formValues[filter.field]}
|
|
200
|
+
value={props?.filterValueState[filter.field]}
|
|
201
|
+
onChangeCallBack={(v: any) => {
|
|
202
|
+
handleFieldChange(filter.field, v);
|
|
203
|
+
}}
|
|
204
|
+
/>
|
|
205
|
+
</Grid>
|
|
206
|
+
);
|
|
207
|
+
} else {
|
|
208
|
+
return <></>;
|
|
209
|
+
}
|
|
210
|
+
})}
|
|
211
|
+
</Grid>
|
|
212
|
+
</AccordionDetails>
|
|
213
|
+
<AccordionActions>
|
|
214
|
+
<Button
|
|
215
|
+
variant="contained"
|
|
216
|
+
onClick={handleSubmit(
|
|
217
|
+
(values) => {
|
|
218
|
+
submitAction();
|
|
219
|
+
},
|
|
220
|
+
(errors) => {
|
|
221
|
+
console.log("errors", errors);
|
|
222
|
+
}
|
|
223
|
+
)}
|
|
224
|
+
startIcon={
|
|
225
|
+
<FontAwesomeIcon
|
|
226
|
+
icon={props?.actionButtonIcon || "magnifying-glass"}
|
|
227
|
+
/>
|
|
228
|
+
}
|
|
229
|
+
>
|
|
230
|
+
{props?.actionButtonLabel || "Search"}
|
|
231
|
+
</Button>
|
|
232
|
+
</AccordionActions>
|
|
233
|
+
</Accordion>
|
|
234
|
+
);
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
export default FiltersPanel;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TextField, TextFieldProps } from "@mui/material";
|
|
2
|
+
|
|
3
|
+
const TemplateTextField: React.FC<Omit<TextFieldProps, "outlined">> = (
|
|
4
|
+
props
|
|
5
|
+
) => {
|
|
6
|
+
return <TextField {...props} slotProps={{ inputLabel: { shrink: true } }} />;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default TemplateTextField;
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { Box } from "@mui/system";
|
|
2
|
+
import React, { useEffect, useState } from "react";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
import { useForm } from "react-hook-form";
|
|
5
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
6
|
+
import { useParams } from "react-router-dom";
|
|
7
|
+
import { Button, Grid2 } from "@mui/material";
|
|
8
|
+
import { toast } from "react-toastify";
|
|
9
|
+
import FormElementGroup from "./FormElementGroup";
|
|
10
|
+
import FormElementField from "./FormElementField";
|
|
11
|
+
import FormAction from "./FormAction";
|
|
12
|
+
import { constructValidationSchema, getAllFields } from "../DataEntryUtil";
|
|
13
|
+
import {
|
|
14
|
+
FormElementProps,
|
|
15
|
+
RecordAction,
|
|
16
|
+
TemplateFormProps,
|
|
17
|
+
} from "../DataEntryTypes";
|
|
18
|
+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
19
|
+
|
|
20
|
+
const TemplateForm: React.FC<TemplateFormProps> = (
|
|
21
|
+
props: TemplateFormProps
|
|
22
|
+
) => {
|
|
23
|
+
const fields = getAllFields(props.elements);
|
|
24
|
+
const [hiddenFields, setHiddenFields] = useState<string[]>([]);
|
|
25
|
+
const [disabledFields, setDisabledFields] = useState<string[]>([]);
|
|
26
|
+
const formSchema = z.object(constructValidationSchema(fields));
|
|
27
|
+
type FormData = z.infer<typeof formSchema>;
|
|
28
|
+
const formManager = useForm<FormData>({
|
|
29
|
+
resolver: zodResolver(formSchema),
|
|
30
|
+
});
|
|
31
|
+
const formValues = formManager.watch();
|
|
32
|
+
const pathParameters = useParams();
|
|
33
|
+
const formRouteRecordIdParamName: any = props?.formRouteRecordIdParamName;
|
|
34
|
+
|
|
35
|
+
const loadRecord = async () => {
|
|
36
|
+
let idToLoad = null;
|
|
37
|
+
if (props?.recordIdToEdit) {
|
|
38
|
+
idToLoad = props.recordIdToEdit;
|
|
39
|
+
} else if (
|
|
40
|
+
formRouteRecordIdParamName &&
|
|
41
|
+
pathParameters[formRouteRecordIdParamName]
|
|
42
|
+
) {
|
|
43
|
+
idToLoad = pathParameters[formRouteRecordIdParamName];
|
|
44
|
+
}
|
|
45
|
+
if (idToLoad) {
|
|
46
|
+
const retrievedRecord: any = await props.apiActions.loadRecordById(
|
|
47
|
+
idToLoad
|
|
48
|
+
);
|
|
49
|
+
if (retrievedRecord) {
|
|
50
|
+
formManager.reset({ ...retrievedRecord });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const saveRecord = async (record: any) => {
|
|
56
|
+
if (props?.preSaveValidation && !props.preSaveValidation(record)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (record) {
|
|
60
|
+
const savedRecord: any = await props.apiActions.saveRecord(record);
|
|
61
|
+
if (savedRecord) {
|
|
62
|
+
formManager.reset({ ...savedRecord });
|
|
63
|
+
if (props?.formSavedSuccessfullyCallBk) {
|
|
64
|
+
props.formSavedSuccessfullyCallBk(savedRecord);
|
|
65
|
+
}
|
|
66
|
+
if (props?.formCloseCallBk) {
|
|
67
|
+
props.formCloseCallBk();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const formActions = {
|
|
74
|
+
setFieldValue: (fieldName: string, fieldValue: any) => {
|
|
75
|
+
formManager.setValue(fieldName, fieldValue);
|
|
76
|
+
},
|
|
77
|
+
hideField: (fieldName: string) => {
|
|
78
|
+
setHiddenFields((oldValues) => {
|
|
79
|
+
const newValues = [...oldValues, fieldName];
|
|
80
|
+
return newValues;
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
showField: (fieldName: string) => {
|
|
84
|
+
setHiddenFields((oldValues) => {
|
|
85
|
+
const newValues = oldValues.filter((x) => x !== fieldName);
|
|
86
|
+
return newValues;
|
|
87
|
+
});
|
|
88
|
+
},
|
|
89
|
+
disableField: (fieldName: string) => {
|
|
90
|
+
setDisabledFields((oldValues) => {
|
|
91
|
+
const newValues = [...oldValues, fieldName];
|
|
92
|
+
return newValues;
|
|
93
|
+
});
|
|
94
|
+
},
|
|
95
|
+
enableField: (fieldName: string) => {
|
|
96
|
+
setDisabledFields((oldValues) => {
|
|
97
|
+
const newValues = oldValues.filter((x) => x !== fieldName);
|
|
98
|
+
return newValues;
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
loadRecord();
|
|
105
|
+
}, [props?.recordIdToEdit]);
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<>
|
|
109
|
+
<Box
|
|
110
|
+
sx={{
|
|
111
|
+
display: "flex",
|
|
112
|
+
flex: 1,
|
|
113
|
+
width: "100%",
|
|
114
|
+
height: "fit-content",
|
|
115
|
+
flexDirection: "column",
|
|
116
|
+
alignItems: "center",
|
|
117
|
+
overflow: "auto",
|
|
118
|
+
}}
|
|
119
|
+
>
|
|
120
|
+
<Grid2 sx={{ width: "100%" }} container>
|
|
121
|
+
{props.elements.map((formElement: FormElementProps) => {
|
|
122
|
+
if (formElement.type === "group") {
|
|
123
|
+
return (
|
|
124
|
+
<FormElementGroup
|
|
125
|
+
{...formElement.props}
|
|
126
|
+
formManager={formManager}
|
|
127
|
+
formValues={formValues}
|
|
128
|
+
formActions={formActions}
|
|
129
|
+
hiddenFields={hiddenFields}
|
|
130
|
+
disabledFields={disabledFields}
|
|
131
|
+
/>
|
|
132
|
+
);
|
|
133
|
+
} else if (
|
|
134
|
+
formElement.type === "field" &&
|
|
135
|
+
formElement.mode === "props"
|
|
136
|
+
) {
|
|
137
|
+
return (
|
|
138
|
+
<FormElementField
|
|
139
|
+
fieldInfo={formElement.props}
|
|
140
|
+
formManager={formManager}
|
|
141
|
+
formValues={formValues}
|
|
142
|
+
formActions={formActions}
|
|
143
|
+
hiddenFields={hiddenFields}
|
|
144
|
+
disabledFields={disabledFields}
|
|
145
|
+
/>
|
|
146
|
+
);
|
|
147
|
+
} else if (
|
|
148
|
+
formElement.type === "field" &&
|
|
149
|
+
formElement.mode === "node"
|
|
150
|
+
) {
|
|
151
|
+
return (
|
|
152
|
+
<Grid2
|
|
153
|
+
size={
|
|
154
|
+
formElement?.props?.formProps?.fieldSize || {
|
|
155
|
+
lg: 3,
|
|
156
|
+
md: 6,
|
|
157
|
+
xs: 12,
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
sx={{ padding: 1, width: "100%" }}
|
|
161
|
+
>
|
|
162
|
+
<formElement.node
|
|
163
|
+
formManager={formManager}
|
|
164
|
+
formValues={formValues}
|
|
165
|
+
/>
|
|
166
|
+
</Grid2>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
})}
|
|
170
|
+
</Grid2>
|
|
171
|
+
</Box>
|
|
172
|
+
|
|
173
|
+
<Box
|
|
174
|
+
sx={{
|
|
175
|
+
display: "flex",
|
|
176
|
+
width: "100%",
|
|
177
|
+
alignItems: "center",
|
|
178
|
+
justifyContent: "flex-start",
|
|
179
|
+
}}
|
|
180
|
+
>
|
|
181
|
+
{props?.actions ? (
|
|
182
|
+
props.actions.map((action: RecordAction) => {
|
|
183
|
+
if (action?.formActionProps?.enabled === true) {
|
|
184
|
+
return <FormAction {...action} record={formValues} />;
|
|
185
|
+
} else {
|
|
186
|
+
return <></>;
|
|
187
|
+
}
|
|
188
|
+
})
|
|
189
|
+
) : (
|
|
190
|
+
<></>
|
|
191
|
+
)}
|
|
192
|
+
<div style={{ flex: 1 }}></div>
|
|
193
|
+
<Button
|
|
194
|
+
variant={
|
|
195
|
+
props?.saveButtonSpecs?.actionButtonVariant
|
|
196
|
+
? props.saveButtonSpecs.actionButtonVariant
|
|
197
|
+
: "contained"
|
|
198
|
+
}
|
|
199
|
+
sx={{ m: 1 }}
|
|
200
|
+
startIcon={
|
|
201
|
+
props?.saveButtonSpecs?.icon ? (
|
|
202
|
+
<FontAwesomeIcon icon={props.saveButtonSpecs.icon} />
|
|
203
|
+
) : null
|
|
204
|
+
}
|
|
205
|
+
color={
|
|
206
|
+
props?.saveButtonSpecs?.actionButtonColor
|
|
207
|
+
? props.saveButtonSpecs.actionButtonColor
|
|
208
|
+
: "primary"
|
|
209
|
+
}
|
|
210
|
+
onClick={formManager.handleSubmit(
|
|
211
|
+
(values) => {
|
|
212
|
+
console.log("form values", values);
|
|
213
|
+
saveRecord(values);
|
|
214
|
+
},
|
|
215
|
+
(errors) => {
|
|
216
|
+
toast.error(
|
|
217
|
+
"Form Data is not valid, make sure you have all field with valid data"
|
|
218
|
+
);
|
|
219
|
+
console.log("form validation error", errors);
|
|
220
|
+
}
|
|
221
|
+
)}
|
|
222
|
+
>
|
|
223
|
+
{props?.saveButtonSpecs?.label || "save"}
|
|
224
|
+
</Button>
|
|
225
|
+
<Button
|
|
226
|
+
variant={
|
|
227
|
+
props?.cancelButtonSpecs?.actionButtonVariant
|
|
228
|
+
? props.cancelButtonSpecs.actionButtonVariant
|
|
229
|
+
: "contained"
|
|
230
|
+
}
|
|
231
|
+
startIcon={
|
|
232
|
+
props?.cancelButtonSpecs?.icon ? (
|
|
233
|
+
<FontAwesomeIcon icon={props.cancelButtonSpecs.icon} />
|
|
234
|
+
) : null
|
|
235
|
+
}
|
|
236
|
+
color={
|
|
237
|
+
props?.cancelButtonSpecs?.actionButtonColor
|
|
238
|
+
? props.cancelButtonSpecs.actionButtonColor
|
|
239
|
+
: "error"
|
|
240
|
+
}
|
|
241
|
+
sx={{ m: 1 }}
|
|
242
|
+
onClick={() => {
|
|
243
|
+
if (props?.formCloseCallBk) {
|
|
244
|
+
props.formCloseCallBk();
|
|
245
|
+
}
|
|
246
|
+
formManager.reset({});
|
|
247
|
+
}}
|
|
248
|
+
>
|
|
249
|
+
{props?.cancelButtonSpecs?.label || "cancel"}
|
|
250
|
+
</Button>
|
|
251
|
+
</Box>
|
|
252
|
+
</>
|
|
253
|
+
);
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
export default TemplateForm;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import moment from "moment";
|
|
2
|
+
import { TemplateGridColDef } from "../DataEntryTypes";
|
|
3
|
+
import Datefield from "../TemplateDataForm/FormFields/Datefield";
|
|
4
|
+
import { DATE_FORMAT, DATE_TIME_FORMAT } from "../../../../util/constants";
|
|
5
|
+
import DatetimeField from "../TemplateDataForm/FormFields/DatetimeField";
|
|
6
|
+
import ComboBox from "../TemplateDataForm/FormFields/ComboBox";
|
|
7
|
+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
8
|
+
import CheckBox from "../TemplateDataForm/FormFields/CheckBox";
|
|
9
|
+
|
|
10
|
+
export const generateDateColumn: any = (colDef: TemplateGridColDef) => {
|
|
11
|
+
const column: TemplateGridColDef = {
|
|
12
|
+
...colDef,
|
|
13
|
+
type: "string",
|
|
14
|
+
renderEditCell: (params: any) => {
|
|
15
|
+
return (
|
|
16
|
+
<Datefield
|
|
17
|
+
sx={{ width: "100%" }}
|
|
18
|
+
label=""
|
|
19
|
+
value={params.value}
|
|
20
|
+
onChangeCallBack={(v: any) => {
|
|
21
|
+
params.api.setEditCellValue({
|
|
22
|
+
id: params.id,
|
|
23
|
+
field: params.field,
|
|
24
|
+
value: v,
|
|
25
|
+
});
|
|
26
|
+
}}
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
|
+
},
|
|
30
|
+
valueParser: (value: any, row: any, column: any) => {
|
|
31
|
+
let v = null;
|
|
32
|
+
if (value !== null) {
|
|
33
|
+
v = moment(value).format(DATE_FORMAT);
|
|
34
|
+
}
|
|
35
|
+
return v;
|
|
36
|
+
},
|
|
37
|
+
valueFormatter: (value: any, row: any, column: any) => {
|
|
38
|
+
return row[column.field];
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
return column;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const generateDateTimeColumn: any = (colDef: TemplateGridColDef) => {
|
|
45
|
+
const column: TemplateGridColDef = {
|
|
46
|
+
...colDef,
|
|
47
|
+
type: "string",
|
|
48
|
+
renderEditCell: (params: any) => {
|
|
49
|
+
return (
|
|
50
|
+
<DatetimeField
|
|
51
|
+
sx={{ width: "100%" }}
|
|
52
|
+
label=""
|
|
53
|
+
value={params.value}
|
|
54
|
+
onChangeCallBack={(v: any) => {
|
|
55
|
+
params.api.setEditCellValue({
|
|
56
|
+
id: params.id,
|
|
57
|
+
field: params.field,
|
|
58
|
+
value: v,
|
|
59
|
+
});
|
|
60
|
+
}}
|
|
61
|
+
/>
|
|
62
|
+
);
|
|
63
|
+
},
|
|
64
|
+
valueParser: (value: any, row: any, column: any) => {
|
|
65
|
+
let v = null;
|
|
66
|
+
if (value !== null) {
|
|
67
|
+
v = moment(value).format(DATE_TIME_FORMAT);
|
|
68
|
+
}
|
|
69
|
+
return v;
|
|
70
|
+
},
|
|
71
|
+
valueFormatter: (value: any, row: any, column: any) => {
|
|
72
|
+
return row[column.field];
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
return column;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
type ComboBoxColumnProps = TemplateGridColDef & {
|
|
79
|
+
options: Array<any>;
|
|
80
|
+
displayField: string;
|
|
81
|
+
valueField: string;
|
|
82
|
+
};
|
|
83
|
+
export const generateComboColumn: (
|
|
84
|
+
props: ComboBoxColumnProps
|
|
85
|
+
) => TemplateGridColDef = (colDef: ComboBoxColumnProps) => {
|
|
86
|
+
const column: TemplateGridColDef = {
|
|
87
|
+
...colDef,
|
|
88
|
+
type: "custom",
|
|
89
|
+
valueGetter: (value) => {
|
|
90
|
+
if (value) {
|
|
91
|
+
return value + "";
|
|
92
|
+
}
|
|
93
|
+
return value;
|
|
94
|
+
},
|
|
95
|
+
renderCell: (parameters: any) => {
|
|
96
|
+
let record = null;
|
|
97
|
+
try {
|
|
98
|
+
record = parameters.colDef.options.find(
|
|
99
|
+
(item: any) => item[parameters.colDef.valueField] == parameters.value
|
|
100
|
+
);
|
|
101
|
+
} catch (e) {}
|
|
102
|
+
return (
|
|
103
|
+
<div>
|
|
104
|
+
{record != null
|
|
105
|
+
? record[parameters.colDef.displayField]
|
|
106
|
+
: parameters.value}
|
|
107
|
+
</div>
|
|
108
|
+
);
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
renderEditCell: (params: any) => {
|
|
112
|
+
return (
|
|
113
|
+
<ComboBox
|
|
114
|
+
{...params}
|
|
115
|
+
sx={{ width: "100%" }}
|
|
116
|
+
options={colDef.options}
|
|
117
|
+
valueField={colDef.valueField}
|
|
118
|
+
displayField={colDef.displayField}
|
|
119
|
+
onChangeCallBack={(v: any, selectedRecord: any) => {
|
|
120
|
+
if (v === null) {
|
|
121
|
+
params.api.setEditCellValue({
|
|
122
|
+
id: params.id,
|
|
123
|
+
field: params.field,
|
|
124
|
+
value: null,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
params.api.setEditCellValue({
|
|
128
|
+
id: params.id,
|
|
129
|
+
field: params.field,
|
|
130
|
+
value: v + "",
|
|
131
|
+
});
|
|
132
|
+
}}
|
|
133
|
+
/>
|
|
134
|
+
);
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
return column;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
type CheckBoxColumnProps = TemplateGridColDef & {
|
|
141
|
+
checkedValue?: string;
|
|
142
|
+
unCheckedValue?: string;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
export const generateCheckBoxColumn: (
|
|
146
|
+
props: CheckBoxColumnProps
|
|
147
|
+
) => TemplateGridColDef = (colDef: CheckBoxColumnProps) => {
|
|
148
|
+
return {
|
|
149
|
+
...colDef,
|
|
150
|
+
type: "custom",
|
|
151
|
+
valueGetter: (value) => {
|
|
152
|
+
if (value == null || value == undefined) {
|
|
153
|
+
return null;
|
|
154
|
+
} else {
|
|
155
|
+
return value + "";
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
renderCell: (parameters: any) => {
|
|
159
|
+
const value = parameters?.value;
|
|
160
|
+
if (
|
|
161
|
+
value === colDef.checkedValue ||
|
|
162
|
+
value === "true" ||
|
|
163
|
+
value === 1 ||
|
|
164
|
+
value === true
|
|
165
|
+
) {
|
|
166
|
+
return <FontAwesomeIcon icon="check" color="green" />;
|
|
167
|
+
} else {
|
|
168
|
+
return <FontAwesomeIcon icon="xmark" color="red" />;
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
renderEditCell: (params: any) => {
|
|
172
|
+
return (
|
|
173
|
+
<CheckBox
|
|
174
|
+
{...params}
|
|
175
|
+
checkedValue={colDef?.checkedValue || "true"}
|
|
176
|
+
unCheckedValue={colDef?.unCheckedValue || "false"}
|
|
177
|
+
onChangeCallBack={(v: any) => {
|
|
178
|
+
params.api.setEditCellValue({
|
|
179
|
+
id: params.id,
|
|
180
|
+
field: params.field,
|
|
181
|
+
value: v + "",
|
|
182
|
+
});
|
|
183
|
+
}}
|
|
184
|
+
/>
|
|
185
|
+
);
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
};
|