@asaleh37/ui-base 25.12.122 → 25.12.171

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 (29) hide show
  1. package/__ODockerfile +14 -14
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.js +108 -108
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +112 -112
  6. package/dist/index.mjs.map +1 -1
  7. package/package-lock.json/342/200/216 +9039 -9039
  8. package/package.json +122 -122
  9. package/src/components/administration/admin/CustomPersonGrid.tsx +361 -0
  10. package/src/components/administration/admin/OrgProvidedPersonGrid.tsx +347 -0
  11. package/src/components/administration/admin/OrganizationMemberGrid.tsx +63 -49
  12. package/src/components/administration/admin/PersonGrid.tsx +10 -344
  13. package/src/components/administration/dev/WorkflowDocumentGrid.tsx +2 -1
  14. package/src/components/templates/DataEntryTemplates/TemplateDataForm/FormElementField.tsx +238 -238
  15. package/src/components/templates/DataEntryTemplates/TemplateDataForm/TemplateForm.tsx +427 -427
  16. package/src/components/templates/DataEntryTemplates/TemplateDataGrid/DataGridColumnsUtil.tsx +198 -198
  17. package/src/components/templates/DataEntryTemplates/TemplateDataGrid/TemplateGrid.tsx +1047 -1047
  18. package/src/components/templates/report/ExcelReportViewer.tsx +72 -72
  19. package/src/components/templates/report/ReportViewer.tsx +272 -272
  20. package/src/components/templates/workflow/WorkflowDocumentPanel.tsx +6 -2
  21. package/src/hooks/UseWindow.tsx +111 -111
  22. package/src/hooks/index.ts +22 -22
  23. package/src/hooks/useCommonStore.tsx +29 -29
  24. package/src/hooks/useParameterPanel.tsx +159 -159
  25. package/src/layout/NavigationTree.tsx +8 -1
  26. package/src/layout/TopBar.tsx +72 -55
  27. package/src/main.tsx +2 -1
  28. package/src/navigationItems/Administration/adminNavigationItems.tsx +1 -1
  29. package/src/redux/features/common/AppInfoSlice.ts +4 -0
@@ -1,427 +1,427 @@
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, Icon, IconButton, Tooltip } 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
- import { useTranslation } from "react-i18next";
20
- import { useWindow } from "../../../../hooks";
21
- import AttachmentPanel from "../../attachment/AttachmentPanel";
22
- import WorkflowDocumentPanel from "../../workflow/WorkflowDocumentPanel";
23
-
24
- const TemplateForm: React.FC<TemplateFormProps> = (
25
- props: TemplateFormProps
26
- ) => {
27
- const { Window: AttachmentWindow, setWindowState: setAttachmentWindowState } =
28
- useWindow({
29
- windowTitle: "Attachments",
30
- windowIcon: "paperclip",
31
- width: "fit-content",
32
- height: "fit-content",
33
- minHeight: 500,
34
- minWidth: 400,
35
- });
36
-
37
- const [attachmentPanelEnabledForRecord, setAttachmentPanelEnabledForRecord] =
38
- useState<boolean>(true);
39
- const { t } = useTranslation();
40
- const fields = getAllFields(props.elements);
41
-
42
- const [disabledFields, setDisabledFields] = useState<string[]>([]);
43
- const [hiddenFields, setHiddenFields] = useState<string[]>([]);
44
- const initialValues: any = {};
45
- for (const element of props.elements) {
46
- if (
47
- element?.type === "field" &&
48
- element?.mode === "props" &&
49
- element?.props?.defaultValue
50
- ) {
51
- initialValues[element.props.fieldName] = element.props.defaultValue;
52
- }
53
- }
54
-
55
- let formSchema = null;
56
- if (props?.validationSchema) {
57
- formSchema = props.validationSchema;
58
- } else {
59
- formSchema = z.object(constructValidationSchema(fields));
60
- }
61
- type FormData = z.infer<typeof formSchema>;
62
- const formManager = useForm<FormData>({
63
- resolver: zodResolver(formSchema),
64
- defaultValues: initialValues,
65
- });
66
- const formValues = formManager.watch();
67
- const pathParameters = useParams();
68
- const formRouteRecordIdParamName: any = props?.formRouteRecordIdParamName;
69
-
70
- const loadRecord = async () => {
71
- let idToLoad = null;
72
- if (props?.recordIdToEdit) {
73
- idToLoad = props.recordIdToEdit;
74
- } else if (
75
- formRouteRecordIdParamName &&
76
- pathParameters[formRouteRecordIdParamName]
77
- ) {
78
- idToLoad = pathParameters[formRouteRecordIdParamName];
79
- }
80
- if (idToLoad) {
81
- const retrievedRecord: any = await props.apiActions.loadRecordById(
82
- idToLoad
83
- );
84
- if (retrievedRecord) {
85
- formManager.reset({ ...retrievedRecord });
86
- for (const field of fields) {
87
- if (
88
- field?.fieldType === "combobox" &&
89
- retrievedRecord[field.fieldName]
90
- ) {
91
- if (
92
- field?.comboboxValueDataType &&
93
- field?.comboboxValueDataType === "string"
94
- ) {
95
- formManager.setValue(
96
- field.fieldName,
97
- retrievedRecord[field.fieldName] + ""
98
- );
99
- } else {
100
- formManager.setValue(
101
- field.fieldName,
102
- retrievedRecord[field.fieldName]
103
- );
104
- }
105
- }
106
- }
107
- if (props?.formValuesChangeCallBk) {
108
- props?.formValuesChangeCallBk(formValues, formActions, formManager);
109
- }
110
- }
111
- } else {
112
- formManager.reset({});
113
- props.formValuesChangeCallBk(formValues, formActions, formManager);
114
- }
115
- };
116
-
117
- const saveRecord = async (record: any) => {
118
- if (props?.preSaveValidation && !props.preSaveValidation(record)) {
119
- return;
120
- }
121
- if (record) {
122
- const savedRecord: any = await props.apiActions.saveRecord(record);
123
- if (savedRecord) {
124
- formManager.reset({ ...savedRecord });
125
- if (props?.formSavedSuccessfullyCallBk) {
126
- props.formSavedSuccessfullyCallBk(savedRecord);
127
- }
128
- if (props?.formCloseCallBk) {
129
- props.formCloseCallBk();
130
- }
131
- }
132
- }
133
- };
134
-
135
- const { Window: WorkflowWindow, setWindowState: setWorkflowWindowState } =
136
- useWindow({
137
- windowTitle: "Approvals",
138
- windowIcon: "stamp",
139
- height: "fit-content",
140
- minHeight: 500,
141
- width: "fit-content",
142
- // width: 1100,
143
- onCloseCallBack: async () => {
144
- await loadRecord();
145
- },
146
- });
147
-
148
- const formActions = {
149
- setFieldValue: (fieldName: string, fieldValue: any) => {
150
- formManager.setValue(fieldName, fieldValue);
151
- },
152
- hideField: (fieldName: string) => {
153
- setHiddenFields((oldValues) => {
154
- const newValues = [...oldValues, fieldName];
155
- return newValues;
156
- });
157
- },
158
- showField: (fieldName: string) => {
159
- setHiddenFields((oldValues) => {
160
- const newValues = oldValues.filter((x) => x !== fieldName);
161
- return newValues;
162
- });
163
- },
164
- disableField: (fieldName: string) => {
165
- setDisabledFields((oldValues) => {
166
- const newValues = [...oldValues, fieldName];
167
- return newValues;
168
- });
169
- },
170
- enableField: (fieldName: string) => {
171
- setDisabledFields((oldValues) => {
172
- const newValues = oldValues.filter((x) => x !== fieldName);
173
- return newValues;
174
- });
175
- },
176
- };
177
-
178
- useEffect(() => {
179
- const initiallyHiddenFields = [];
180
- const initiallyDisabledFields = [];
181
- for (const field of fields) {
182
- if (field?.hidden) {
183
- initiallyHiddenFields.push(field.fieldName);
184
- }
185
- if (field?.disabled) {
186
- initiallyDisabledFields.push(field.fieldName);
187
- }
188
- }
189
- setHiddenFields(initiallyHiddenFields);
190
- setDisabledFields(initiallyDisabledFields);
191
- }, [props.elements]);
192
- useEffect(() => {
193
- loadRecord();
194
- }, [props?.recordIdToEdit]);
195
-
196
- useEffect(() => {
197
- if (props?.attachment && props?.attachment?.enableAttachFn) {
198
- setAttachmentPanelEnabledForRecord(
199
- props.attachment.enableAttachFn(formValues)
200
- );
201
- } else {
202
- setAttachmentPanelEnabledForRecord(true);
203
- }
204
- }, [formValues]);
205
- return (
206
- <>
207
- {props?.attachment ? (
208
- <AttachmentWindow>
209
- <AttachmentPanel
210
- attachmentCode={props.attachment.attachmentCode}
211
- refKey={formValues[props?.keyColumnName || "id"]}
212
- enableAttachment={attachmentPanelEnabledForRecord}
213
- />
214
- </AttachmentWindow>
215
- ) : (
216
- <></>
217
- )}
218
- {props?.workFlowDocumentCode ? (
219
- <WorkflowWindow>
220
- <WorkflowDocumentPanel
221
- workFlowDocumentCode={props.workFlowDocumentCode}
222
- refDocumentId={formValues[props?.keyColumnName || "id"]}
223
- postActionCallBk={() => {
224
- setWorkflowWindowState(false);
225
- loadRecord();
226
- }}
227
- cancelActionCallBk={() => {
228
- setWorkflowWindowState(false);
229
- loadRecord();
230
- }}
231
- />
232
- </WorkflowWindow>
233
- ) : (
234
- <></>
235
- )}
236
-
237
- <Box
238
- sx={{
239
- display: "flex",
240
- flex: 1,
241
- width: "100%",
242
- height: "fit-content",
243
- flexDirection: "column",
244
- alignItems: "center",
245
- overflow: "auto",
246
- }}
247
- >
248
- <Grid2 sx={{ width: "100%" }} container>
249
- {props.elements.map((formElement: FormElementProps, index) => {
250
- if (formElement.type === "group") {
251
- return (
252
- <FormElementGroup
253
- key={index}
254
- {...formElement.props}
255
- formManager={formManager}
256
- formValues={formValues}
257
- formActions={formActions}
258
- hiddenFields={hiddenFields}
259
- disabledFields={disabledFields}
260
- formValuesChangeCallBk={props.formValuesChangeCallBk}
261
- />
262
- );
263
- } else if (
264
- formElement.type === "field" &&
265
- formElement.mode === "props"
266
- ) {
267
- return (
268
- <FormElementField
269
- key={index}
270
- fieldInfo={formElement.props}
271
- formManager={formManager}
272
- formValues={formValues}
273
- formActions={formActions}
274
- hiddenFields={hiddenFields}
275
- disabledFields={disabledFields}
276
- formValuesChangeCallBk={props.formValuesChangeCallBk}
277
- />
278
- );
279
- } else if (
280
- formElement.type === "field" &&
281
- formElement.mode === "node"
282
- ) {
283
- return (
284
- <Grid2
285
- key={index}
286
- size={
287
- formElement?.props?.formProps?.fieldSize || {
288
- lg: 3,
289
- md: 6,
290
- xs: 12,
291
- }
292
- }
293
- sx={{ padding: 1, width: "100%" }}
294
- >
295
- <formElement.node
296
- formManager={formManager}
297
- formValues={formValues}
298
- />
299
- </Grid2>
300
- );
301
- }
302
- })}
303
- </Grid2>
304
- </Box>
305
-
306
- <Box
307
- sx={{
308
- display: "flex",
309
- width: "100%",
310
- alignItems: "center",
311
- justifyContent: "flex-start",
312
- }}
313
- >
314
- {formValues[props?.keyColumnName || "id"] ? (
315
- props?.attachment ? (
316
- <Tooltip title="Attachments">
317
- <IconButton
318
- onClick={() => {
319
- setAttachmentWindowState(true);
320
- }}
321
- >
322
- <FontAwesomeIcon icon="paperclip" />
323
- </IconButton>
324
- </Tooltip>
325
- ) : null
326
- ) : null}
327
- {formValues[props?.keyColumnName || "id"] ? (
328
- props?.workFlowDocumentCode ? (
329
- <Tooltip title="Approvals">
330
- <IconButton
331
- onClick={() => {
332
- setWorkflowWindowState(true);
333
- }}
334
- >
335
- <FontAwesomeIcon icon="stamp" />
336
- </IconButton>
337
- </Tooltip>
338
- ) : null
339
- ) : null}
340
- {props?.actions ? (
341
- props.actions.map((action: RecordAction) => {
342
- if (action?.isIdRequired === false) {
343
- return <FormAction {...action} record={formValues} />;
344
- } else if (formValues[props?.keyColumnName || "id"]) {
345
- if (action?.formActionProps?.enabled === true) {
346
- return <FormAction {...action} record={formValues} />;
347
- } else {
348
- return <></>;
349
- }
350
- }
351
- })
352
- ) : (
353
- <></>
354
- )}
355
- <div style={{ flex: 1 }}></div>
356
- {props?.saveButtonSpecs?.hidden ? (
357
- <></>
358
- ) : (
359
- <Button
360
- variant={
361
- props?.saveButtonSpecs?.actionButtonVariant
362
- ? props.saveButtonSpecs.actionButtonVariant
363
- : "contained"
364
- }
365
- sx={{ m: 1 }}
366
- startIcon={
367
- props?.saveButtonSpecs?.icon ? (
368
- <FontAwesomeIcon icon={props.saveButtonSpecs.icon} />
369
- ) : null
370
- }
371
- color={
372
- props?.saveButtonSpecs?.actionButtonColor
373
- ? props.saveButtonSpecs.actionButtonColor
374
- : "primary"
375
- }
376
- onClick={formManager.handleSubmit(
377
- (values) => {
378
- saveRecord(values);
379
- },
380
- (errors) => {
381
- toast.error(
382
- "Form Data is not valid, make sure you have all field with valid data"
383
- );
384
- console.log("form validation error", errors);
385
- }
386
- )}
387
- >
388
- {t(props?.saveButtonSpecs?.label || "SAVE_BTN_LABEL")}
389
- </Button>
390
- )}
391
-
392
- {props?.cancelButtonSpecs?.hidden ? (
393
- <></>
394
- ) : (
395
- <Button
396
- variant={
397
- props?.cancelButtonSpecs?.actionButtonVariant
398
- ? props.cancelButtonSpecs.actionButtonVariant
399
- : "contained"
400
- }
401
- startIcon={
402
- props?.cancelButtonSpecs?.icon ? (
403
- <FontAwesomeIcon icon={props.cancelButtonSpecs.icon} />
404
- ) : null
405
- }
406
- color={
407
- props?.cancelButtonSpecs?.actionButtonColor
408
- ? props.cancelButtonSpecs.actionButtonColor
409
- : "error"
410
- }
411
- sx={{ m: 1 }}
412
- onClick={() => {
413
- if (props?.formCloseCallBk) {
414
- props.formCloseCallBk();
415
- }
416
- formManager.reset(initialValues);
417
- }}
418
- >
419
- {t(props?.cancelButtonSpecs?.label || "CANCEL_BTN_LABEL")}
420
- </Button>
421
- )}
422
- </Box>
423
- </>
424
- );
425
- };
426
-
427
- export default TemplateForm;
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, Icon, IconButton, Tooltip } 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
+ import { useTranslation } from "react-i18next";
20
+ import { useWindow } from "../../../../hooks";
21
+ import AttachmentPanel from "../../attachment/AttachmentPanel";
22
+ import WorkflowDocumentPanel from "../../workflow/WorkflowDocumentPanel";
23
+
24
+ const TemplateForm: React.FC<TemplateFormProps> = (
25
+ props: TemplateFormProps
26
+ ) => {
27
+ const { Window: AttachmentWindow, setWindowState: setAttachmentWindowState } =
28
+ useWindow({
29
+ windowTitle: "Attachments",
30
+ windowIcon: "paperclip",
31
+ width: "fit-content",
32
+ height: "fit-content",
33
+ minHeight: 500,
34
+ minWidth: 400,
35
+ });
36
+
37
+ const [attachmentPanelEnabledForRecord, setAttachmentPanelEnabledForRecord] =
38
+ useState<boolean>(true);
39
+ const { t } = useTranslation();
40
+ const fields = getAllFields(props.elements);
41
+
42
+ const [disabledFields, setDisabledFields] = useState<string[]>([]);
43
+ const [hiddenFields, setHiddenFields] = useState<string[]>([]);
44
+ const initialValues: any = {};
45
+ for (const element of props.elements) {
46
+ if (
47
+ element?.type === "field" &&
48
+ element?.mode === "props" &&
49
+ element?.props?.defaultValue
50
+ ) {
51
+ initialValues[element.props.fieldName] = element.props.defaultValue;
52
+ }
53
+ }
54
+
55
+ let formSchema = null;
56
+ if (props?.validationSchema) {
57
+ formSchema = props.validationSchema;
58
+ } else {
59
+ formSchema = z.object(constructValidationSchema(fields));
60
+ }
61
+ type FormData = z.infer<typeof formSchema>;
62
+ const formManager = useForm<FormData>({
63
+ resolver: zodResolver(formSchema),
64
+ defaultValues: initialValues,
65
+ });
66
+ const formValues = formManager.watch();
67
+ const pathParameters = useParams();
68
+ const formRouteRecordIdParamName: any = props?.formRouteRecordIdParamName;
69
+
70
+ const loadRecord = async () => {
71
+ let idToLoad = null;
72
+ if (props?.recordIdToEdit) {
73
+ idToLoad = props.recordIdToEdit;
74
+ } else if (
75
+ formRouteRecordIdParamName &&
76
+ pathParameters[formRouteRecordIdParamName]
77
+ ) {
78
+ idToLoad = pathParameters[formRouteRecordIdParamName];
79
+ }
80
+ if (idToLoad) {
81
+ const retrievedRecord: any = await props.apiActions.loadRecordById(
82
+ idToLoad
83
+ );
84
+ if (retrievedRecord) {
85
+ formManager.reset({ ...retrievedRecord });
86
+ for (const field of fields) {
87
+ if (
88
+ field?.fieldType === "combobox" &&
89
+ retrievedRecord[field.fieldName]
90
+ ) {
91
+ if (
92
+ field?.comboboxValueDataType &&
93
+ field?.comboboxValueDataType === "string"
94
+ ) {
95
+ formManager.setValue(
96
+ field.fieldName,
97
+ retrievedRecord[field.fieldName] + ""
98
+ );
99
+ } else {
100
+ formManager.setValue(
101
+ field.fieldName,
102
+ retrievedRecord[field.fieldName]
103
+ );
104
+ }
105
+ }
106
+ }
107
+ if (props?.formValuesChangeCallBk) {
108
+ props?.formValuesChangeCallBk(formValues, formActions, formManager);
109
+ }
110
+ }
111
+ } else {
112
+ formManager.reset({});
113
+ props.formValuesChangeCallBk(formValues, formActions, formManager);
114
+ }
115
+ };
116
+
117
+ const saveRecord = async (record: any) => {
118
+ if (props?.preSaveValidation && !props.preSaveValidation(record)) {
119
+ return;
120
+ }
121
+ if (record) {
122
+ const savedRecord: any = await props.apiActions.saveRecord(record);
123
+ if (savedRecord) {
124
+ formManager.reset({ ...savedRecord });
125
+ if (props?.formSavedSuccessfullyCallBk) {
126
+ props.formSavedSuccessfullyCallBk(savedRecord);
127
+ }
128
+ if (props?.formCloseCallBk) {
129
+ props.formCloseCallBk();
130
+ }
131
+ }
132
+ }
133
+ };
134
+
135
+ const { Window: WorkflowWindow, setWindowState: setWorkflowWindowState } =
136
+ useWindow({
137
+ windowTitle: "Approvals",
138
+ windowIcon: "stamp",
139
+ height: "fit-content",
140
+ minHeight: 500,
141
+ width: "fit-content",
142
+ // width: 1100,
143
+ onCloseCallBack: async () => {
144
+ await loadRecord();
145
+ },
146
+ });
147
+
148
+ const formActions = {
149
+ setFieldValue: (fieldName: string, fieldValue: any) => {
150
+ formManager.setValue(fieldName, fieldValue);
151
+ },
152
+ hideField: (fieldName: string) => {
153
+ setHiddenFields((oldValues) => {
154
+ const newValues = [...oldValues, fieldName];
155
+ return newValues;
156
+ });
157
+ },
158
+ showField: (fieldName: string) => {
159
+ setHiddenFields((oldValues) => {
160
+ const newValues = oldValues.filter((x) => x !== fieldName);
161
+ return newValues;
162
+ });
163
+ },
164
+ disableField: (fieldName: string) => {
165
+ setDisabledFields((oldValues) => {
166
+ const newValues = [...oldValues, fieldName];
167
+ return newValues;
168
+ });
169
+ },
170
+ enableField: (fieldName: string) => {
171
+ setDisabledFields((oldValues) => {
172
+ const newValues = oldValues.filter((x) => x !== fieldName);
173
+ return newValues;
174
+ });
175
+ },
176
+ };
177
+
178
+ useEffect(() => {
179
+ const initiallyHiddenFields = [];
180
+ const initiallyDisabledFields = [];
181
+ for (const field of fields) {
182
+ if (field?.hidden) {
183
+ initiallyHiddenFields.push(field.fieldName);
184
+ }
185
+ if (field?.disabled) {
186
+ initiallyDisabledFields.push(field.fieldName);
187
+ }
188
+ }
189
+ setHiddenFields(initiallyHiddenFields);
190
+ setDisabledFields(initiallyDisabledFields);
191
+ }, [props.elements]);
192
+ useEffect(() => {
193
+ loadRecord();
194
+ }, [props?.recordIdToEdit]);
195
+
196
+ useEffect(() => {
197
+ if (props?.attachment && props?.attachment?.enableAttachFn) {
198
+ setAttachmentPanelEnabledForRecord(
199
+ props.attachment.enableAttachFn(formValues)
200
+ );
201
+ } else {
202
+ setAttachmentPanelEnabledForRecord(true);
203
+ }
204
+ }, [formValues]);
205
+ return (
206
+ <>
207
+ {props?.attachment ? (
208
+ <AttachmentWindow>
209
+ <AttachmentPanel
210
+ attachmentCode={props.attachment.attachmentCode}
211
+ refKey={formValues[props?.keyColumnName || "id"]}
212
+ enableAttachment={attachmentPanelEnabledForRecord}
213
+ />
214
+ </AttachmentWindow>
215
+ ) : (
216
+ <></>
217
+ )}
218
+ {props?.workFlowDocumentCode ? (
219
+ <WorkflowWindow>
220
+ <WorkflowDocumentPanel
221
+ workFlowDocumentCode={props.workFlowDocumentCode}
222
+ refDocumentId={formValues[props?.keyColumnName || "id"]}
223
+ postActionCallBk={() => {
224
+ setWorkflowWindowState(false);
225
+ loadRecord();
226
+ }}
227
+ cancelActionCallBk={() => {
228
+ setWorkflowWindowState(false);
229
+ loadRecord();
230
+ }}
231
+ />
232
+ </WorkflowWindow>
233
+ ) : (
234
+ <></>
235
+ )}
236
+
237
+ <Box
238
+ sx={{
239
+ display: "flex",
240
+ flex: 1,
241
+ width: "100%",
242
+ height: "fit-content",
243
+ flexDirection: "column",
244
+ alignItems: "center",
245
+ overflow: "auto",
246
+ }}
247
+ >
248
+ <Grid2 sx={{ width: "100%" }} container>
249
+ {props.elements.map((formElement: FormElementProps, index) => {
250
+ if (formElement.type === "group") {
251
+ return (
252
+ <FormElementGroup
253
+ key={index}
254
+ {...formElement.props}
255
+ formManager={formManager}
256
+ formValues={formValues}
257
+ formActions={formActions}
258
+ hiddenFields={hiddenFields}
259
+ disabledFields={disabledFields}
260
+ formValuesChangeCallBk={props.formValuesChangeCallBk}
261
+ />
262
+ );
263
+ } else if (
264
+ formElement.type === "field" &&
265
+ formElement.mode === "props"
266
+ ) {
267
+ return (
268
+ <FormElementField
269
+ key={index}
270
+ fieldInfo={formElement.props}
271
+ formManager={formManager}
272
+ formValues={formValues}
273
+ formActions={formActions}
274
+ hiddenFields={hiddenFields}
275
+ disabledFields={disabledFields}
276
+ formValuesChangeCallBk={props.formValuesChangeCallBk}
277
+ />
278
+ );
279
+ } else if (
280
+ formElement.type === "field" &&
281
+ formElement.mode === "node"
282
+ ) {
283
+ return (
284
+ <Grid2
285
+ key={index}
286
+ size={
287
+ formElement?.props?.formProps?.fieldSize || {
288
+ lg: 3,
289
+ md: 6,
290
+ xs: 12,
291
+ }
292
+ }
293
+ sx={{ padding: 1, width: "100%" }}
294
+ >
295
+ <formElement.node
296
+ formManager={formManager}
297
+ formValues={formValues}
298
+ />
299
+ </Grid2>
300
+ );
301
+ }
302
+ })}
303
+ </Grid2>
304
+ </Box>
305
+
306
+ <Box
307
+ sx={{
308
+ display: "flex",
309
+ width: "100%",
310
+ alignItems: "center",
311
+ justifyContent: "flex-start",
312
+ }}
313
+ >
314
+ {formValues[props?.keyColumnName || "id"] ? (
315
+ props?.attachment ? (
316
+ <Tooltip title="Attachments">
317
+ <IconButton
318
+ onClick={() => {
319
+ setAttachmentWindowState(true);
320
+ }}
321
+ >
322
+ <FontAwesomeIcon icon="paperclip" />
323
+ </IconButton>
324
+ </Tooltip>
325
+ ) : null
326
+ ) : null}
327
+ {formValues[props?.keyColumnName || "id"] ? (
328
+ props?.workFlowDocumentCode ? (
329
+ <Tooltip title="Approvals">
330
+ <IconButton
331
+ onClick={() => {
332
+ setWorkflowWindowState(true);
333
+ }}
334
+ >
335
+ <FontAwesomeIcon icon="stamp" />
336
+ </IconButton>
337
+ </Tooltip>
338
+ ) : null
339
+ ) : null}
340
+ {props?.actions ? (
341
+ props.actions.map((action: RecordAction) => {
342
+ if (action?.isIdRequired === false) {
343
+ return <FormAction {...action} record={formValues} />;
344
+ } else if (formValues[props?.keyColumnName || "id"]) {
345
+ if (action?.formActionProps?.enabled === true) {
346
+ return <FormAction {...action} record={formValues} />;
347
+ } else {
348
+ return <></>;
349
+ }
350
+ }
351
+ })
352
+ ) : (
353
+ <></>
354
+ )}
355
+ <div style={{ flex: 1 }}></div>
356
+ {props?.saveButtonSpecs?.hidden ? (
357
+ <></>
358
+ ) : (
359
+ <Button
360
+ variant={
361
+ props?.saveButtonSpecs?.actionButtonVariant
362
+ ? props.saveButtonSpecs.actionButtonVariant
363
+ : "contained"
364
+ }
365
+ sx={{ m: 1 }}
366
+ startIcon={
367
+ props?.saveButtonSpecs?.icon ? (
368
+ <FontAwesomeIcon icon={props.saveButtonSpecs.icon} />
369
+ ) : null
370
+ }
371
+ color={
372
+ props?.saveButtonSpecs?.actionButtonColor
373
+ ? props.saveButtonSpecs.actionButtonColor
374
+ : "primary"
375
+ }
376
+ onClick={formManager.handleSubmit(
377
+ (values) => {
378
+ saveRecord(values);
379
+ },
380
+ (errors) => {
381
+ toast.error(
382
+ "Form Data is not valid, make sure you have all field with valid data"
383
+ );
384
+ console.log("form validation error", errors);
385
+ }
386
+ )}
387
+ >
388
+ {t(props?.saveButtonSpecs?.label || "SAVE_BTN_LABEL")}
389
+ </Button>
390
+ )}
391
+
392
+ {props?.cancelButtonSpecs?.hidden ? (
393
+ <></>
394
+ ) : (
395
+ <Button
396
+ variant={
397
+ props?.cancelButtonSpecs?.actionButtonVariant
398
+ ? props.cancelButtonSpecs.actionButtonVariant
399
+ : "contained"
400
+ }
401
+ startIcon={
402
+ props?.cancelButtonSpecs?.icon ? (
403
+ <FontAwesomeIcon icon={props.cancelButtonSpecs.icon} />
404
+ ) : null
405
+ }
406
+ color={
407
+ props?.cancelButtonSpecs?.actionButtonColor
408
+ ? props.cancelButtonSpecs.actionButtonColor
409
+ : "error"
410
+ }
411
+ sx={{ m: 1 }}
412
+ onClick={() => {
413
+ if (props?.formCloseCallBk) {
414
+ props.formCloseCallBk();
415
+ }
416
+ formManager.reset(initialValues);
417
+ }}
418
+ >
419
+ {t(props?.cancelButtonSpecs?.label || "CANCEL_BTN_LABEL")}
420
+ </Button>
421
+ )}
422
+ </Box>
423
+ </>
424
+ );
425
+ };
426
+
427
+ export default TemplateForm;