admin_lsac 2.0.0 → 2.0.2

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/README.md CHANGED
@@ -33,8 +33,9 @@ Import the component from above where you want to write your schemas! (See below
33
33
  element={
34
34
  <AdminPage
35
35
  pages={your_array}
36
- selectedPage={page}
36
+ selectedPage={page} // 'page' param from above
37
37
  basePath={your_url_to_admin_panel}
38
+ apiURL={your_url_to_backend} // optional, for websockets
38
39
  />
39
40
  }
40
41
  />
@@ -47,6 +48,7 @@ Import the component from above where you want to write your schemas! (See below
47
48
  pages={your_array}
48
49
  selectedPage={your_array[0]}
49
50
  basePath={your_url_to_admin_panel}
51
+ apiURL={your_url_to_backend} // optional, for websockets
50
52
  />
51
53
  }
52
54
  />
@@ -193,7 +195,7 @@ const companies: PageSchema = {
193
195
  name: "name",
194
196
  label: "Quiz Name",
195
197
  type: "string", // for every FormField, type must be specified
196
- validationSchema: Yup.string().required(),
198
+ validationSchema: Yup.string().required(), // you can also require 'boolean' values with Yup
197
199
  },
198
200
  {
199
201
  name: "questions",
@@ -309,6 +311,12 @@ const your_array: PageSchema[] = [
309
311
  ];
310
312
  ```
311
313
 
314
+ ## Websockets Support
315
+
316
+ For real-time changes, this NPM module uses socket.io-client library to implement WebSockets. So, on the server-side, you will have to use socket.io library, and provide an `apiURL` as shown above.
317
+
318
+ In order for it to work, emit an event 'updateData' from the server for every route associated with an action/rowAction. You can also send a message that the client will receive (the message will be shown in the web console).
319
+
312
320
  ## Other Specifications
313
321
 
314
322
  Due to some corrupt dependencies, you will need a Node version >= 20.5.0 to use this NPM package (it may work in some cases, but we still recommend updating Node to a newer version).
@@ -36,7 +36,23 @@ function exportToCSV(data, filename) {
36
36
  }
37
37
  return formattedObj;
38
38
  };
39
- const formattedData = data.map(formatImageData);
39
+ const removeTimestamps = (obj) => {
40
+ const { createdAt, updatedAt, ...rest } = obj;
41
+ return rest;
42
+ };
43
+ const allKeys = new Set();
44
+ data.forEach((item) => {
45
+ Object.keys(formatImageData(removeTimestamps(item))).forEach((key) => allKeys.add(key));
46
+ });
47
+ const formattedData = data.map((item) => {
48
+ const newItem = formatImageData(removeTimestamps(item));
49
+ allKeys.forEach((key) => {
50
+ if (!(key in newItem)) {
51
+ newItem[key] = '';
52
+ }
53
+ });
54
+ return newItem;
55
+ });
40
56
  const csvConfig = mkConfig({
41
57
  useKeysAsHeaders: true,
42
58
  filename: filename,
@@ -37,7 +37,7 @@ function generateSingleField(formfield, fieldName, key) {
37
37
  if (event.currentTarget.files != null) {
38
38
  form.setFieldValue(fieldName, event.currentTarget.files[0]);
39
39
  }
40
- } })) : (_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));
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));
41
41
  }
42
42
  function parseFields(fields, previous) {
43
43
  if (!fields) {
@@ -135,7 +135,7 @@ export function GenericForm({ action, onClose, rowId }) {
135
135
  await action.onSubmit(values);
136
136
  if (onClose)
137
137
  onClose();
138
- Swal.fire('Ok');
138
+ Swal.fire('Action/RowAction executed successfully');
139
139
  }
140
140
  catch (e) {
141
141
  if (onClose)
@@ -145,5 +145,5 @@ export function GenericForm({ action, onClose, rowId }) {
145
145
  text: 'Error: ' + err,
146
146
  });
147
147
  }
148
- }, children: ({ isSubmitting }) => (_jsxs(Form, { children: [formFields, _jsx(Button, { mt: 4, colorScheme: "teal", isLoading: isSubmitting, type: "submit", children: "Submit" }), _jsx(Button, { mt: 4, colorScheme: "teal", type: "reset", children: "Initialise Form" })] })) }) }));
148
+ }, children: ({ isSubmitting }) => (_jsxs(Form, { children: [formFields, _jsx(Button, { mt: 4, mb: 2, colorScheme: "teal", isLoading: isSubmitting, type: "submit", children: "Submit" }), action.initialise && (_jsx(Button, { mt: 4, mb: 2, ml: 4, colorScheme: "teal", type: "reset", children: "Initialise Form" }))] })) }) }));
149
149
  }
@@ -6,7 +6,7 @@ export interface TableField {
6
6
  export interface SimpleField {
7
7
  name: string;
8
8
  label: string;
9
- type: 'string' | 'number' | 'file';
9
+ type: 'string' | 'number' | 'file' | 'date';
10
10
  validationSchema: any;
11
11
  }
12
12
  export interface Option {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "admin_lsac",
3
3
  "private": false,
4
- "version": "2.0.0",
4
+ "version": "2.0.2",
5
5
  "description": "Generic Admin Panel created for storing events' data",
6
6
  "scripts": {
7
7
  "dev": "vite",