admin_lsac 1.3.2 → 1.4.1

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 (79) hide show
  1. package/.eslintrc.cjs +18 -0
  2. package/README.md +162 -162
  3. package/dist/src/App.d.ts +7 -0
  4. package/dist/src/App.js +10 -0
  5. package/dist/src/components/AdminPage.d.ts +8 -0
  6. package/dist/{esm/components/Page.js → src/components/AdminPage.js} +35 -43
  7. package/dist/src/components/GenericForm.d.ts +8 -0
  8. package/dist/src/components/GenericForm.js +151 -0
  9. package/dist/src/main.d.ts +1 -0
  10. package/dist/src/main.js +7 -0
  11. package/dist/{App.d.ts → src/schema.d.ts} +53 -76
  12. package/dist/src/testSchemas/event.d.ts +2 -0
  13. package/dist/src/testSchemas/event.js +86 -0
  14. package/dist/src/utils/websockets.d.ts +1 -0
  15. package/dist/{esm → src}/utils/websockets.js +5 -5
  16. package/index.html +13 -0
  17. package/package.json +42 -73
  18. package/tsconfig.app.json +27 -0
  19. package/tsconfig.json +11 -31
  20. package/tsconfig.node.json +13 -0
  21. package/vite.config.ts +7 -0
  22. package/dist/App.js +0 -12
  23. package/dist/cjs/App.js +0 -12
  24. package/dist/cjs/components/GenericForm.js +0 -305
  25. package/dist/cjs/components/Page.js +0 -119
  26. package/dist/cjs/index.js +0 -18
  27. package/dist/cjs/pages/event.js +0 -134
  28. package/dist/cjs/pages/page.js +0 -375
  29. package/dist/cjs/reportWebVitals.js +0 -38
  30. package/dist/cjs/schema/schema.config.js +0 -9
  31. package/dist/cjs/schema/schema.js +0 -2
  32. package/dist/cjs/setupTests.js +0 -7
  33. package/dist/cjs/utils/websockets.js +0 -22
  34. package/dist/components/GenericForm.js +0 -305
  35. package/dist/components/Page.js +0 -119
  36. package/dist/esm/App.js +0 -10
  37. package/dist/esm/components/GenericForm.js +0 -275
  38. package/dist/esm/index.js +0 -13
  39. package/dist/esm/pages/event.js +0 -128
  40. package/dist/esm/pages/page.js +0 -349
  41. package/dist/esm/reportWebVitals.js +0 -13
  42. package/dist/esm/schema/schema.config.js +0 -6
  43. package/dist/esm/setupTests.js +0 -5
  44. package/dist/index.js +0 -18
  45. package/dist/pages/event.js +0 -134
  46. package/dist/pages/page.js +0 -375
  47. package/dist/reportWebVitals.js +0 -38
  48. package/dist/schema/schema.config.js +0 -9
  49. package/dist/schema/schema.js +0 -2
  50. package/dist/setupTests.js +0 -7
  51. package/dist/utils/websockets.js +0 -22
  52. package/public/favicon.ico +0 -0
  53. package/public/index.html +0 -43
  54. package/public/logo192.png +0 -0
  55. package/public/logo512.png +0 -0
  56. package/public/manifest.json +0 -25
  57. package/public/robots.txt +0 -3
  58. package/server/.env.example +0 -3
  59. package/server/deploy.js +0 -29
  60. package/server/package-lock.json +0 -712
  61. package/server/package.json +0 -18
  62. package/src/App.css +0 -38
  63. package/src/App.tsx +0 -50
  64. package/src/components/GenericForm.tsx +0 -308
  65. package/src/components/Page.tsx +0 -243
  66. package/src/index.css +0 -13
  67. package/src/index.tsx +0 -20
  68. package/src/logo.svg +0 -1
  69. package/src/pages/event.ts +0 -93
  70. package/src/pages/page.ts +0 -336
  71. package/src/react-app-env.d.ts +0 -1
  72. package/src/reportWebVitals.ts +0 -15
  73. package/src/schema/schema.config.ts +0 -8
  74. package/src/schema/schema.ts +0 -63
  75. package/src/setupTests.ts +0 -5
  76. package/src/utils/websockets.tsx +0 -17
  77. package/tsconfig.esm.json +0 -7
  78. package/webpack.config.js +0 -22
  79. /package/dist/{esm/schema → src}/schema.js +0 -0
@@ -1,275 +0,0 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
- return new (P || (P = Promise))(function (resolve, reject) {
15
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
- step((generator = generator.apply(thisArg, _arguments || [])).next());
19
- });
20
- };
21
- var __generator = (this && this.__generator) || function (thisArg, body) {
22
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
- function verb(n) { return function (v) { return step([n, v]); }; }
25
- function step(op) {
26
- if (f) throw new TypeError("Generator is already executing.");
27
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
- if (y = 0, t) op = [op[0] & 2, t.value];
30
- switch (op[0]) {
31
- case 0: case 1: t = op; break;
32
- case 4: _.label++; return { value: op[1], done: false };
33
- case 5: _.label++; y = op[1]; op = [0]; continue;
34
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
- default:
36
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
- if (t[2]) _.ops.pop();
41
- _.trys.pop(); continue;
42
- }
43
- op = body.call(thisArg, _);
44
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
- }
47
- };
48
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
49
- import { Box, Button, FormControl, FormErrorMessage, FormLabel, Input, Select, } from "@chakra-ui/react";
50
- import { Field, Form, Formik, FieldArray, getIn } from "formik";
51
- import * as Yup from "yup";
52
- import Swal from "sweetalert2";
53
- import { useEffect, useState } from "react";
54
- function parseValidation(fields) {
55
- if (!fields) {
56
- return {};
57
- }
58
- return fields.reduce(function (acc, field) {
59
- if (field.type !== "dropdown" &&
60
- field.type !== "object" &&
61
- field.type !== "array") {
62
- acc[field.name] = field.validationSchema;
63
- }
64
- else if (field.type === "array") {
65
- if (field.element.type === "dropdown") {
66
- acc[field.name] = Yup.array().of(Yup.string().required());
67
- }
68
- else if (field.element.type === "object") {
69
- acc[field.name] = Yup.array().of(Yup.object(parseValidation(field.element.fields)));
70
- }
71
- else {
72
- acc[field.name] = Yup.array().of(field.element.validationSchema);
73
- }
74
- }
75
- else if (field.type === "object") {
76
- acc[field.name] = Yup.object(parseValidation(field.fields));
77
- }
78
- if (field.type === "dropdown") {
79
- acc[field.name] = Yup.string().required();
80
- }
81
- return acc;
82
- }, {});
83
- }
84
- function generateSingleField(formfield, fieldName, key) {
85
- return (_jsx(Field, { name: fieldName, children: function (_a) {
86
- var _b;
87
- var field = _a.field, form = _a.form;
88
- return (_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, __assign({}, field, { type: formfield.type === "number" ? "number" : "text", placeholder: "" }))) : formfield.type === "file" ? (_jsx(Input, { type: "file", name: fieldName, onChange: function (event) {
89
- if (event.currentTarget.files != null) {
90
- form.setFieldValue(fieldName, event.currentTarget.files[0]);
91
- }
92
- } })) : (_jsxs(Select, __assign({}, field, { defaultValue: "", children: [_jsx("option", { disabled: true, value: "", children: "Select an option!" }), (_b = formfield.options) === null || _b === void 0 ? void 0 : _b.map(function (option, key) { return (_jsx("option", { value: "".concat(option.value), children: option.display }, key)); })] }))), _jsx(FormErrorMessage, { children: getIn(form.errors, fieldName) })] }));
93
- } }, key));
94
- }
95
- function parseFields(fields, previous) {
96
- if (!fields) {
97
- return [];
98
- }
99
- var computedFields = fields.map(function (formfield, key) {
100
- var fieldName = previous !== undefined ? previous + "." + formfield.name : formfield.name;
101
- if (formfield.type === "object") {
102
- var objectFields = parseFields(formfield.fields, fieldName);
103
- return _jsx(FormControl, { children: objectFields }, fieldName);
104
- }
105
- else if (formfield.type === "array") {
106
- return (_jsx(FieldArray, { name: fieldName, children: function (_a) {
107
- var remove = _a.remove, push = _a.push, form = _a.form;
108
- return (_jsxs("div", { children: [_jsx(FormLabel, { marginTop: 2, children: formfield.label }), getIn(form.values, fieldName).length > 0 &&
109
- getIn(form.values, fieldName).map(function (element, index) { return (_jsxs(Box, { paddingLeft: 10, children: [_jsx("h4", { children: _jsx("b", { children: "".concat(fieldName, ".").concat(index) }) }), _jsx(Box, { paddingLeft: 10, children: formfield.element.type === "object"
110
- ? parseFields(formfield.element.fields, "".concat(fieldName, ".").concat(index))
111
- : generateSingleField(formfield.element, "".concat(fieldName, ".").concat(index), key) }), _jsxs(Button, { type: "button", colorScheme: "red", marginY: 2, onClick: function () { return remove(index); }, children: ["Remove ", "".concat(fieldName, ".").concat(index)] })] })); }), _jsxs(Button, { type: "button", marginY: 2, colorScheme: "blue", onClick: function () {
112
- var value = undefined;
113
- if (formfield.element.type === "object") {
114
- value = getCustomInitialValues(formfield.element.fields);
115
- }
116
- else {
117
- value = getCustomInitialValues([formfield.element])[0];
118
- }
119
- push(value);
120
- }, children: ["Add ", fieldName] })] }));
121
- } }));
122
- }
123
- else {
124
- return generateSingleField(formfield, fieldName, key);
125
- }
126
- });
127
- return computedFields;
128
- }
129
- function getCustomInitialValues(fields) {
130
- var obj = {};
131
- if (!fields) {
132
- return obj;
133
- }
134
- fields.forEach(function (field) {
135
- if (field.type === "array")
136
- obj[field.name] = [];
137
- else if (field.type === "object")
138
- obj[field.name] = getCustomInitialValues(field.fields);
139
- else if (field.type === "string")
140
- obj[field.name] = "";
141
- else if (field.type === "number")
142
- obj[field.name] = 0;
143
- else
144
- obj[field.name] = null;
145
- });
146
- return obj;
147
- }
148
- function getInitialValues(action, rowId) {
149
- return __awaiter(this, void 0, void 0, function () {
150
- var obj, customInitialValues;
151
- return __generator(this, function (_a) {
152
- switch (_a.label) {
153
- case 0:
154
- obj = {};
155
- if (!action.initialise) return [3 /*break*/, 2];
156
- return [4 /*yield*/, action.initialise(rowId)];
157
- case 1:
158
- obj = _a.sent();
159
- _a.label = 2;
160
- case 2:
161
- customInitialValues = getCustomInitialValues(action.fields);
162
- return [2 /*return*/, Object.assign({}, customInitialValues, obj)];
163
- }
164
- });
165
- });
166
- }
167
- function setOptions(fields) {
168
- return __awaiter(this, void 0, void 0, function () {
169
- var promises;
170
- var _this = this;
171
- return __generator(this, function (_a) {
172
- switch (_a.label) {
173
- case 0:
174
- if (!fields) {
175
- return [2 /*return*/];
176
- }
177
- promises = fields.map(function (field) { return __awaiter(_this, void 0, void 0, function () {
178
- var _a;
179
- return __generator(this, function (_b) {
180
- switch (_b.label) {
181
- case 0:
182
- if (!(field.type === "dropdown")) return [3 /*break*/, 2];
183
- _a = field;
184
- return [4 /*yield*/, field.getOptions()];
185
- case 1:
186
- _a.options = _b.sent();
187
- return [3 /*break*/, 6];
188
- case 2:
189
- if (!(field.type === "array")) return [3 /*break*/, 4];
190
- return [4 /*yield*/, setOptions([field.element])];
191
- case 3:
192
- _b.sent();
193
- return [3 /*break*/, 6];
194
- case 4:
195
- if (!(field.type === "object")) return [3 /*break*/, 6];
196
- return [4 /*yield*/, setOptions(field.fields)];
197
- case 5:
198
- _b.sent();
199
- _b.label = 6;
200
- case 6: return [2 /*return*/];
201
- }
202
- });
203
- }); });
204
- return [4 /*yield*/, Promise.all(promises)];
205
- case 1:
206
- _a.sent();
207
- return [2 /*return*/];
208
- }
209
- });
210
- });
211
- }
212
- export function GenericForm(_a) {
213
- var _this = this;
214
- var action = _a.action, onClose = _a.onClose, rowId = _a.rowId;
215
- var _b = useState(parseFields(action.fields)), formFields = _b[0], setFormFields = _b[1];
216
- var _c = useState(getCustomInitialValues(action.fields)), initialValues = _c[0], setInitialValues = _c[1];
217
- var _d = useState(parseValidation(action.fields)), validationSchema = _d[0], setValidationSchema = _d[1];
218
- useEffect(function () {
219
- setOptions(action.fields).then(function () {
220
- setFormFields(parseFields(action.fields));
221
- });
222
- }, []);
223
- var handleFormReset = function () { return __awaiter(_this, void 0, void 0, function () {
224
- var newInitialValues;
225
- return __generator(this, function (_a) {
226
- switch (_a.label) {
227
- case 0: return [4 /*yield*/, getInitialValues(action, rowId)];
228
- case 1:
229
- newInitialValues = _a.sent();
230
- console.log(newInitialValues);
231
- setInitialValues(newInitialValues);
232
- return [2 /*return*/];
233
- }
234
- });
235
- }); };
236
- if (!action.fields)
237
- return _jsx(_Fragment, {});
238
- return (_jsx(_Fragment, { children: _jsx(Formik, { enableReinitialize: true, initialValues: initialValues, validationSchema: Yup.object(validationSchema), onReset: handleFormReset, onSubmit: function (values) { return __awaiter(_this, void 0, void 0, function () {
239
- var res, e_1, err;
240
- return __generator(this, function (_a) {
241
- switch (_a.label) {
242
- case 0:
243
- _a.trys.push([0, 5, , 6]);
244
- res = void 0;
245
- if (!rowId) return [3 /*break*/, 2];
246
- return [4 /*yield*/, action.onSubmit(values, rowId)];
247
- case 1:
248
- res = _a.sent();
249
- return [3 /*break*/, 4];
250
- case 2: return [4 /*yield*/, action.onSubmit(values)];
251
- case 3:
252
- res = _a.sent();
253
- _a.label = 4;
254
- case 4:
255
- if (onClose)
256
- onClose();
257
- Swal.fire("Ok");
258
- return [3 /*break*/, 6];
259
- case 5:
260
- e_1 = _a.sent();
261
- if (onClose)
262
- onClose();
263
- err = e_1.request.response;
264
- Swal.fire({
265
- text: "Error: " + err,
266
- });
267
- return [3 /*break*/, 6];
268
- case 6: return [2 /*return*/];
269
- }
270
- });
271
- }); }, children: function (_a) {
272
- var isSubmitting = _a.isSubmitting;
273
- return (_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" })] }));
274
- } }) }));
275
- }
package/dist/esm/index.js DELETED
@@ -1,13 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import React from "react";
3
- import ReactDOM from "react-dom/client";
4
- import "./index.css";
5
- import App from "./App";
6
- import reportWebVitals from "./reportWebVitals";
7
- import { pages } from "./schema/schema.config";
8
- var root = ReactDOM.createRoot(document.getElementById("root"));
9
- root.render(_jsx(React.StrictMode, { children: _jsx(App, { pages: pages, basePath: "" }) }));
10
- // If you want to start measuring performance in your app, pass a function
11
- // to log results (for example: reportWebVitals(console.log))
12
- // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
13
- reportWebVitals();
@@ -1,128 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- import React from "react";
38
- var domain = "http://localhost:3001";
39
- export var event = {
40
- name: "Events",
41
- actions: [],
42
- rowActions: [
43
- // {
44
- // name: "Delete Event",
45
- // fields: [
46
- // {
47
- // name: "input",
48
- // label: "Mock Field",
49
- // type: "string",
50
- // validationSchema: "",
51
- // },
52
- // ],
53
- // initialise: async (eventId: number) => {
54
- // const res = await axios.get(domain + "/events/" + eventId);
55
- // let obj: any = {};
56
- // obj.input = res.data.name;
57
- // return obj;
58
- // },
59
- // onSubmit: async (formValues: any, eventId: number) => {
60
- // const res = await axios.delete(
61
- // domain + "/events/" + eventId
62
- // );
63
- // return res.data;
64
- // },
65
- // }
66
- ],
67
- getRequest: function () { return __awaiter(void 0, void 0, void 0, function () {
68
- return __generator(this, function (_a) {
69
- // const res = await axios.get(domain + "/events");
70
- // return res.data;
71
- return [2 /*return*/, []];
72
- });
73
- }); },
74
- tableFields: [
75
- {
76
- name: "Id",
77
- access: function (obj) { return obj.id; },
78
- },
79
- {
80
- name: "Event Name",
81
- access: function (obj) { return obj.name; },
82
- },
83
- {
84
- name: "Description",
85
- access: function (obj) { return obj.description; },
86
- },
87
- {
88
- name: "Category",
89
- access: function (obj) { return obj.category; },
90
- },
91
- {
92
- name: "Ticket Type",
93
- access: function (obj) { return obj.ticketType; },
94
- },
95
- {
96
- name: "Date",
97
- access: function (obj) { return obj.date; },
98
- },
99
- {
100
- name: "Release",
101
- access: function (obj) { return obj.release; },
102
- },
103
- {
104
- name: "Is Released",
105
- access: function (obj) { return (obj.isReleased ? "Is Released" : "Not Released"); },
106
- },
107
- {
108
- name: "Available Tickets",
109
- access: function (obj) { return obj.availableTickets; },
110
- },
111
- {
112
- name: "Max Tickets",
113
- access: function (obj) { return obj.maxTickets; },
114
- },
115
- {
116
- name: "Image",
117
- access: function (obj) {
118
- return obj.imgUrl
119
- ? React.createElement("img", {
120
- src: obj.imgUrl,
121
- alt: "ERROR",
122
- style: { width: "100px" },
123
- })
124
- : "No Image Available";
125
- },
126
- },
127
- ],
128
- };