admin_lsac 2.0.9 → 2.0.11

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.
@@ -91,7 +91,7 @@ export function AdminPage({ pages, selectedPage, basePath, apiURL = '', }) {
91
91
  rowActionsMenu.remove();
92
92
  }
93
93
  }, children: rowAction.name }, index)));
94
- } }) }), _jsxs(Modal, { size: '6xl', isOpen: isOpen, onClose: onClose, children: [_jsx(ModalOverlay, {}), _jsxs(ModalContent, { children: [_jsx(ModalHeader, { children: selectedAction.name }), _jsx(ModalCloseButton, {}), _jsxs(ModalBody, { children: [selectedAction.fields && selectedAction.fields?.length > 0 ? (_jsx(GenericForm, { action: selectedAction, onClose: onClose, rowId: rowId, rowObject: rowObject })) : (_jsx(Button, { colorScheme: "blue", mr: 3, onClick: () => {
94
+ } }) }), _jsxs(Modal, { size: '6xl', isOpen: isOpen, onClose: onClose, children: [_jsx(ModalOverlay, {}), _jsxs(ModalContent, { children: [_jsx(ModalHeader, { children: selectedAction.name }), _jsx(ModalCloseButton, {}), _jsxs(ModalBody, { children: [selectedAction.fields ? (_jsx(GenericForm, { action: selectedAction, onClose: onClose, rowId: rowId, rowObject: rowObject })) : (_jsx(Button, { colorScheme: "blue", mr: 3, onClick: () => {
95
95
  selectedAction.onSubmit(rowId);
96
96
  onClose();
97
97
  }, children: "Confirm Action" })), _jsx(Button, { colorScheme: "red", mr: 3, onClick: onClose, children: "Close" })] })] })] })] }));
@@ -32,11 +32,16 @@ function parseValidation(fields) {
32
32
  }, {});
33
33
  }
34
34
  function generateSingleField(formfield, fieldName, key) {
35
- return (_jsx(Field, { name: fieldName, children: ({ field, form }) => (_jsxs(FormControl, { isInvalid: getIn(form.touched, fieldName) && getIn(form.errors, fieldName), children: [_jsx(FormLabel, { marginTop: 2, children: formfield.label }), formfield.type === 'string' || formfield.type === 'number' ? (_jsx(Input, { ...field, type: formfield.type === 'number' ? 'number' : 'text', placeholder: "" })) : formfield.type === 'file' ? (_jsx(Input, { type: "file", name: fieldName, onChange: (event) => {
35
+ return (_jsx(Field, { name: fieldName, children: ({ field, form }) => (_jsxs(FormControl, { isInvalid: getIn(form.touched, fieldName) && getIn(form.errors, fieldName), children: [_jsx(FormLabel, { marginTop: 2, children: formfield.label }), formfield.type === 'string' ||
36
+ formfield.type === 'number' ||
37
+ formfield.type === 'date' ? (_jsx(Input, { ...field, value: field.value || '', type: formfield.type === 'number' || formfield.type === 'date' ? formfield.type : 'text' })) : formfield.type === 'file' ? (_jsx(Input, { type: "file", name: fieldName, onChange: (event) => {
36
38
  if (event.currentTarget.files != null) {
37
39
  form.setFieldValue(fieldName, event.currentTarget.files[0]);
38
40
  }
39
- } })) : formfield.type === 'date' ? (_jsx(Input, { ...field, type: "date", placeholder: "" })) : (_jsxs(Select, { ...field, value: field.value || '', children: [_jsx("option", { disabled: true, value: "", children: "Select an option!" }), formfield.options?.map((option, key) => (_jsx("option", { value: `${option.value}`, children: option.display }, key)))] })), _jsx(FormErrorMessage, { children: getIn(form.errors, fieldName) })] })) }, key));
41
+ } })) : (_jsxs(Select, { ...field, value: field.value || '', onChange: (e) => {
42
+ const selectedOption = formfield.options?.find((option) => option.value.toString() === e.target.value);
43
+ form.setFieldValue(fieldName, selectedOption?.value);
44
+ }, children: [_jsx("option", { disabled: true, value: "", children: "Select an option!" }), formfield.options?.map((option, key) => (_jsx("option", { value: `${option.value}`, children: option.display }, key)))] })), _jsx(FormErrorMessage, { children: getIn(form.errors, fieldName) })] })) }, key));
40
45
  }
41
46
  function parseFields(fields, previous) {
42
47
  if (!fields) {
@@ -75,16 +80,10 @@ function getCustomInitialValues(fields) {
75
80
  return obj;
76
81
  }
77
82
  fields.forEach((field) => {
78
- if (field.type === 'array')
79
- obj[field.name] = [];
80
- else if (field.type === 'object')
83
+ if (field.type === 'object')
81
84
  obj[field.name] = getCustomInitialValues(field.fields);
82
- else if (field.type === 'string')
83
- obj[field.name] = '';
84
- else if (field.type === 'number')
85
- obj[field.name] = 0;
86
85
  else
87
- obj[field.name] = null;
86
+ obj[field.name] = undefined;
88
87
  });
89
88
  return obj;
90
89
  }
@@ -123,8 +122,6 @@ export function GenericForm({ action, onClose, rowId, rowObject }) {
123
122
  const newInitialValues = await getInitialValues(action, rowId);
124
123
  setInitialValues(newInitialValues);
125
124
  };
126
- if (!action.fields)
127
- return _jsx(_Fragment, {});
128
125
  return (_jsx(_Fragment, { children: _jsx(Formik, { enableReinitialize: true, initialValues: initialValues, validationSchema: Yup.object(validationSchema), onReset: handleFormReset, onSubmit: async (values) => {
129
126
  try {
130
127
  if (rowObject !== undefined)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "admin_lsac",
3
3
  "private": false,
4
- "version": "2.0.9",
4
+ "version": "2.0.11",
5
5
  "description": "Generic Admin Panel created for storing events' data",
6
6
  "scripts": {
7
7
  "dev": "vite",