admin_lsac 2.0.5 → 2.0.7

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/admin_lsac.d.ts CHANGED
@@ -18,8 +18,9 @@ declare module 'admin_lsac' {
18
18
  name: string;
19
19
  label: string;
20
20
  type: 'dropdown';
21
+ validationSchema?: any;
21
22
  options?: Option[] | undefined;
22
- getOptions: () => Promise<Option[]>;
23
+ getOptions?: () => Promise<Option[]>;
23
24
  }
24
25
  export interface ObjectField {
25
26
  name: string;
@@ -37,13 +38,13 @@ declare module 'admin_lsac' {
37
38
  export interface Action {
38
39
  name: string;
39
40
  fields?: FormField[];
40
- onSubmit: (obj1: any, obj2?: any) => Promise<any>;
41
+ onSubmit: (obj1: any, obj2?: any, obj3?: any) => Promise<any>;
41
42
  }
42
43
  export interface RowAction {
43
44
  name: string;
44
45
  fields?: FormField[];
45
46
  initialise?: (obj: any) => any;
46
- onSubmit: (obj1: any, obj2?: any) => Promise<any>;
47
+ onSubmit: (obj1: any, obj2?: any, obj3?: any) => Promise<any>;
47
48
  }
48
49
  export interface PageSchema {
49
50
  name: string;
@@ -18,8 +18,9 @@ declare module 'admin_lsac' {
18
18
  name: string;
19
19
  label: string;
20
20
  type: 'dropdown';
21
+ validationSchema?: any;
21
22
  options?: Option[] | undefined;
22
- getOptions: () => Promise<Option[]>;
23
+ getOptions?: () => Promise<Option[]>;
23
24
  }
24
25
  export interface ObjectField {
25
26
  name: string;
@@ -37,13 +38,13 @@ declare module 'admin_lsac' {
37
38
  export interface Action {
38
39
  name: string;
39
40
  fields?: FormField[];
40
- onSubmit: (obj1: any, obj2?: any) => Promise<any>;
41
+ onSubmit: (obj1: any, obj2?: any, obj3?: any) => Promise<any>;
41
42
  }
42
43
  export interface RowAction {
43
44
  name: string;
44
45
  fields?: FormField[];
45
46
  initialise?: (obj: any) => any;
46
- onSubmit: (obj1: any, obj2?: any) => Promise<any>;
47
+ onSubmit: (obj1: any, obj2?: any, obj3?: any) => Promise<any>;
47
48
  }
48
49
  export interface PageSchema {
49
50
  name: string;
@@ -74,6 +74,7 @@ export function AdminPage({ pages, selectedPage, basePath, apiURL = '', }) {
74
74
  const [data, setData] = useState([]);
75
75
  const [displayData, setDisplayData] = useState([]);
76
76
  const [rowId, setRowId] = useState();
77
+ const [rowObject, setRowObject] = useState([]);
77
78
  const [refetch, setRefetch] = useState(false);
78
79
  const [socket, setSocket] = useState(io);
79
80
  newSocket(setSocket, apiURL);
@@ -111,13 +112,16 @@ export function AdminPage({ pages, selectedPage, basePath, apiURL = '', }) {
111
112
  return selectedPage.rowActions.map((rowAction, index) => (_jsx(MenuItem, { onClick: () => {
112
113
  setSelectedAction(rowAction);
113
114
  setRowId(obj.row.original[0]);
115
+ if (obj.staticRowIndex !== undefined) {
116
+ setRowObject(data[obj.staticRowIndex]);
117
+ }
114
118
  onOpen();
115
119
  const rowActionsMenu = document.querySelector('.MuiPaper-root.MuiPopover-paper.MuiMenu-paper');
116
120
  if (rowActionsMenu) {
117
121
  rowActionsMenu.remove();
118
122
  }
119
123
  }, children: rowAction.name + ' ' + obj.row.original[0] }, index)));
120
- } }) }), _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 })) : (_jsx(Button, { colorScheme: "blue", mr: 3, onClick: () => {
124
+ } }) }), _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: () => {
121
125
  selectedAction.onSubmit(rowId);
122
126
  onClose();
123
127
  }, children: "Confirm Action" })), _jsx(Button, { colorScheme: "red", mr: 3, onClick: onClose, children: "Close" })] })] })] })] }));
@@ -3,6 +3,7 @@ interface GenericFormProps {
3
3
  action: Action | RowAction;
4
4
  onClose?: () => void;
5
5
  rowId?: number;
6
+ rowObject?: any;
6
7
  }
7
- export declare function GenericForm({ action, onClose, rowId }: GenericFormProps): import("react/jsx-runtime").JSX.Element;
8
+ export declare function GenericForm({ action, onClose, rowId, rowObject }: GenericFormProps): import("react/jsx-runtime").JSX.Element;
8
9
  export {};
@@ -9,12 +9,14 @@ function parseValidation(fields) {
9
9
  return {};
10
10
  }
11
11
  return fields.reduce((acc, field) => {
12
- if (field.type !== 'dropdown' && field.type !== 'object' && field.type !== 'array') {
13
- acc[field.name] = field.validationSchema;
12
+ if (field.type !== 'object' && field.type !== 'array') {
13
+ acc[field.name] = field.validationSchema ? field.validationSchema : '';
14
14
  }
15
15
  else if (field.type === 'array') {
16
16
  if (field.element.type === 'dropdown') {
17
- acc[field.name] = Yup.array().of(Yup.string().required());
17
+ acc[field.name] = field.element.validationSchema
18
+ ? Yup.array().of(field.element.validationSchema)
19
+ : '';
18
20
  }
19
21
  else if (field.element.type === 'object') {
20
22
  acc[field.name] = Yup.array().of(Yup.object(parseValidation(field.element.fields)));
@@ -26,9 +28,6 @@ function parseValidation(fields) {
26
28
  else if (field.type === 'object') {
27
29
  acc[field.name] = Yup.object(parseValidation(field.fields));
28
30
  }
29
- if (field.type === 'dropdown') {
30
- acc[field.name] = Yup.string().required();
31
- }
32
31
  return acc;
33
32
  }, {});
34
33
  }
@@ -37,7 +36,7 @@ function generateSingleField(formfield, fieldName, key) {
37
36
  if (event.currentTarget.files != null) {
38
37
  form.setFieldValue(fieldName, event.currentTarget.files[0]);
39
38
  }
40
- } })) : formfield.type === 'date' ? (_jsx(Input, { ...field, type: "date", placeholder: "" })) : (_jsxs(Select, { ...field, defaultValue: "", 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));
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
40
  }
42
41
  function parseFields(fields, previous) {
43
42
  if (!fields) {
@@ -103,7 +102,7 @@ async function setOptions(fields) {
103
102
  }
104
103
  const promises = fields.map(async (field) => {
105
104
  if (field.type === 'dropdown')
106
- field.options = await field.getOptions();
105
+ field.options = field.options || (field.getOptions && (await field.getOptions()));
107
106
  else if (field.type === 'array')
108
107
  await setOptions([field.element]);
109
108
  else if (field.type === 'object')
@@ -111,7 +110,7 @@ async function setOptions(fields) {
111
110
  });
112
111
  await Promise.all(promises);
113
112
  }
114
- export function GenericForm({ action, onClose, rowId }) {
113
+ export function GenericForm({ action, onClose, rowId, rowObject }) {
115
114
  const [formFields, setFormFields] = useState(parseFields(action.fields));
116
115
  const [initialValues, setInitialValues] = useState(getCustomInitialValues(action.fields));
117
116
  const [validationSchema, _] = useState(parseValidation(action.fields));
@@ -128,7 +127,9 @@ export function GenericForm({ action, onClose, rowId }) {
128
127
  return _jsx(_Fragment, {});
129
128
  return (_jsx(_Fragment, { children: _jsx(Formik, { enableReinitialize: true, initialValues: initialValues, validationSchema: Yup.object(validationSchema), onReset: handleFormReset, onSubmit: async (values) => {
130
129
  try {
131
- if (rowId)
130
+ if (rowObject !== undefined)
131
+ await action.onSubmit(values, rowId, rowObject);
132
+ else if (rowId !== undefined)
132
133
  await action.onSubmit(values, rowId);
133
134
  else
134
135
  await action.onSubmit(values);
@@ -139,7 +140,7 @@ export function GenericForm({ action, onClose, rowId }) {
139
140
  catch (e) {
140
141
  if (onClose)
141
142
  onClose();
142
- const err = e.request.response;
143
+ const err = e.message;
143
144
  Swal.fire({
144
145
  text: 'Error: ' + err,
145
146
  });
@@ -17,8 +17,9 @@ export interface DropdownField {
17
17
  name: string;
18
18
  label: string;
19
19
  type: 'dropdown';
20
+ validationSchema?: any;
20
21
  options?: Option[] | undefined;
21
- getOptions: () => Promise<Option[]>;
22
+ getOptions?: () => Promise<Option[]>;
22
23
  }
23
24
  export interface ObjectField {
24
25
  name: string;
@@ -36,13 +37,13 @@ export type FormField = SimpleField | DropdownField | ObjectField | ArrayField;
36
37
  export interface Action {
37
38
  name: string;
38
39
  fields?: FormField[];
39
- onSubmit: (obj1: any, obj2?: any) => Promise<any>;
40
+ onSubmit: (obj1: any, obj2?: any, obj3?: any) => Promise<any>;
40
41
  }
41
42
  export interface RowAction {
42
43
  name: string;
43
44
  fields?: FormField[];
44
45
  initialise?: (obj: any) => any;
45
- onSubmit: (obj1: any, obj2?: any) => Promise<any>;
46
+ onSubmit: (obj1: any, obj2?: any, obj3?: any) => Promise<any>;
46
47
  }
47
48
  export interface PageSchema {
48
49
  name: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "admin_lsac",
3
3
  "private": false,
4
- "version": "2.0.5",
4
+ "version": "2.0.7",
5
5
  "description": "Generic Admin Panel created for storing events' data",
6
6
  "scripts": {
7
7
  "dev": "vite",