admin_lsac 2.0.6 → 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
|
@@ -20,7 +20,7 @@ declare module 'admin_lsac' {
|
|
|
20
20
|
type: 'dropdown';
|
|
21
21
|
validationSchema?: any;
|
|
22
22
|
options?: Option[] | undefined;
|
|
23
|
-
getOptions
|
|
23
|
+
getOptions?: () => Promise<Option[]>;
|
|
24
24
|
}
|
|
25
25
|
export interface ObjectField {
|
|
26
26
|
name: string;
|
|
@@ -38,13 +38,13 @@ declare module 'admin_lsac' {
|
|
|
38
38
|
export interface Action {
|
|
39
39
|
name: string;
|
|
40
40
|
fields?: FormField[];
|
|
41
|
-
onSubmit: (obj1: any, obj2?: any) => Promise<any>;
|
|
41
|
+
onSubmit: (obj1: any, obj2?: any, obj3?: any) => Promise<any>;
|
|
42
42
|
}
|
|
43
43
|
export interface RowAction {
|
|
44
44
|
name: string;
|
|
45
45
|
fields?: FormField[];
|
|
46
46
|
initialise?: (obj: any) => any;
|
|
47
|
-
onSubmit: (obj1: any, obj2?: any) => Promise<any>;
|
|
47
|
+
onSubmit: (obj1: any, obj2?: any, obj3?: any) => Promise<any>;
|
|
48
48
|
}
|
|
49
49
|
export interface PageSchema {
|
|
50
50
|
name: string;
|
|
@@ -20,7 +20,7 @@ declare module 'admin_lsac' {
|
|
|
20
20
|
type: 'dropdown';
|
|
21
21
|
validationSchema?: any;
|
|
22
22
|
options?: Option[] | undefined;
|
|
23
|
-
getOptions
|
|
23
|
+
getOptions?: () => Promise<Option[]>;
|
|
24
24
|
}
|
|
25
25
|
export interface ObjectField {
|
|
26
26
|
name: string;
|
|
@@ -38,13 +38,13 @@ declare module 'admin_lsac' {
|
|
|
38
38
|
export interface Action {
|
|
39
39
|
name: string;
|
|
40
40
|
fields?: FormField[];
|
|
41
|
-
onSubmit: (obj1: any, obj2?: any) => Promise<any>;
|
|
41
|
+
onSubmit: (obj1: any, obj2?: any, obj3?: any) => Promise<any>;
|
|
42
42
|
}
|
|
43
43
|
export interface RowAction {
|
|
44
44
|
name: string;
|
|
45
45
|
fields?: FormField[];
|
|
46
46
|
initialise?: (obj: any) => any;
|
|
47
|
-
onSubmit: (obj1: any, obj2?: any) => Promise<any>;
|
|
47
|
+
onSubmit: (obj1: any, obj2?: any, obj3?: any) => Promise<any>;
|
|
48
48
|
}
|
|
49
49
|
export interface PageSchema {
|
|
50
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 {};
|
|
@@ -36,7 +36,7 @@ function generateSingleField(formfield, fieldName, key) {
|
|
|
36
36
|
if (event.currentTarget.files != null) {
|
|
37
37
|
form.setFieldValue(fieldName, event.currentTarget.files[0]);
|
|
38
38
|
}
|
|
39
|
-
} })) : formfield.type === 'date' ? (_jsx(Input, { ...field, type: "date", placeholder: "" })) : (_jsxs(Select, { ...field,
|
|
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));
|
|
40
40
|
}
|
|
41
41
|
function parseFields(fields, previous) {
|
|
42
42
|
if (!fields) {
|
|
@@ -102,7 +102,7 @@ async function setOptions(fields) {
|
|
|
102
102
|
}
|
|
103
103
|
const promises = fields.map(async (field) => {
|
|
104
104
|
if (field.type === 'dropdown')
|
|
105
|
-
field.options = await field.getOptions();
|
|
105
|
+
field.options = field.options || (field.getOptions && (await field.getOptions()));
|
|
106
106
|
else if (field.type === 'array')
|
|
107
107
|
await setOptions([field.element]);
|
|
108
108
|
else if (field.type === 'object')
|
|
@@ -110,7 +110,7 @@ async function setOptions(fields) {
|
|
|
110
110
|
});
|
|
111
111
|
await Promise.all(promises);
|
|
112
112
|
}
|
|
113
|
-
export function GenericForm({ action, onClose, rowId }) {
|
|
113
|
+
export function GenericForm({ action, onClose, rowId, rowObject }) {
|
|
114
114
|
const [formFields, setFormFields] = useState(parseFields(action.fields));
|
|
115
115
|
const [initialValues, setInitialValues] = useState(getCustomInitialValues(action.fields));
|
|
116
116
|
const [validationSchema, _] = useState(parseValidation(action.fields));
|
|
@@ -127,7 +127,9 @@ export function GenericForm({ action, onClose, rowId }) {
|
|
|
127
127
|
return _jsx(_Fragment, {});
|
|
128
128
|
return (_jsx(_Fragment, { children: _jsx(Formik, { enableReinitialize: true, initialValues: initialValues, validationSchema: Yup.object(validationSchema), onReset: handleFormReset, onSubmit: async (values) => {
|
|
129
129
|
try {
|
|
130
|
-
if (
|
|
130
|
+
if (rowObject !== undefined)
|
|
131
|
+
await action.onSubmit(values, rowId, rowObject);
|
|
132
|
+
else if (rowId !== undefined)
|
|
131
133
|
await action.onSubmit(values, rowId);
|
|
132
134
|
else
|
|
133
135
|
await action.onSubmit(values);
|
|
@@ -138,7 +140,7 @@ export function GenericForm({ action, onClose, rowId }) {
|
|
|
138
140
|
catch (e) {
|
|
139
141
|
if (onClose)
|
|
140
142
|
onClose();
|
|
141
|
-
const err = e.
|
|
143
|
+
const err = e.message;
|
|
142
144
|
Swal.fire({
|
|
143
145
|
text: 'Error: ' + err,
|
|
144
146
|
});
|
package/dist/esm/src/schema.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export interface DropdownField {
|
|
|
19
19
|
type: 'dropdown';
|
|
20
20
|
validationSchema?: any;
|
|
21
21
|
options?: Option[] | undefined;
|
|
22
|
-
getOptions
|
|
22
|
+
getOptions?: () => Promise<Option[]>;
|
|
23
23
|
}
|
|
24
24
|
export interface ObjectField {
|
|
25
25
|
name: string;
|
|
@@ -37,13 +37,13 @@ export type FormField = SimpleField | DropdownField | ObjectField | ArrayField;
|
|
|
37
37
|
export interface Action {
|
|
38
38
|
name: string;
|
|
39
39
|
fields?: FormField[];
|
|
40
|
-
onSubmit: (obj1: any, obj2?: any) => Promise<any>;
|
|
40
|
+
onSubmit: (obj1: any, obj2?: any, obj3?: any) => Promise<any>;
|
|
41
41
|
}
|
|
42
42
|
export interface RowAction {
|
|
43
43
|
name: string;
|
|
44
44
|
fields?: FormField[];
|
|
45
45
|
initialise?: (obj: any) => any;
|
|
46
|
-
onSubmit: (obj1: any, obj2?: any) => Promise<any>;
|
|
46
|
+
onSubmit: (obj1: any, obj2?: any, obj3?: any) => Promise<any>;
|
|
47
47
|
}
|
|
48
48
|
export interface PageSchema {
|
|
49
49
|
name: string;
|