admin_lsac 1.3.2 → 1.4.0
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/.eslintrc.cjs +18 -0
- package/README.md +162 -162
- package/index.html +13 -0
- package/package.json +42 -73
- package/tsconfig.app.json +27 -0
- package/tsconfig.json +11 -31
- package/tsconfig.node.json +13 -0
- package/vite.config.ts +7 -0
- package/dist/App.d.ts +0 -76
- package/dist/App.js +0 -12
- package/dist/cjs/App.js +0 -12
- package/dist/cjs/components/GenericForm.js +0 -305
- package/dist/cjs/components/Page.js +0 -119
- package/dist/cjs/index.js +0 -18
- package/dist/cjs/pages/event.js +0 -134
- package/dist/cjs/pages/page.js +0 -375
- package/dist/cjs/reportWebVitals.js +0 -38
- package/dist/cjs/schema/schema.config.js +0 -9
- package/dist/cjs/schema/schema.js +0 -2
- package/dist/cjs/setupTests.js +0 -7
- package/dist/cjs/utils/websockets.js +0 -22
- package/dist/components/GenericForm.js +0 -305
- package/dist/components/Page.js +0 -119
- package/dist/esm/App.js +0 -10
- package/dist/esm/components/GenericForm.js +0 -275
- package/dist/esm/components/Page.js +0 -111
- package/dist/esm/index.js +0 -13
- package/dist/esm/pages/event.js +0 -128
- package/dist/esm/pages/page.js +0 -349
- package/dist/esm/reportWebVitals.js +0 -13
- package/dist/esm/schema/schema.config.js +0 -6
- package/dist/esm/schema/schema.js +0 -1
- package/dist/esm/setupTests.js +0 -5
- package/dist/esm/utils/websockets.js +0 -15
- package/dist/index.js +0 -18
- package/dist/pages/event.js +0 -134
- package/dist/pages/page.js +0 -375
- package/dist/reportWebVitals.js +0 -38
- package/dist/schema/schema.config.js +0 -9
- package/dist/schema/schema.js +0 -2
- package/dist/setupTests.js +0 -7
- package/dist/utils/websockets.js +0 -22
- package/public/favicon.ico +0 -0
- package/public/index.html +0 -43
- package/public/logo192.png +0 -0
- package/public/logo512.png +0 -0
- package/public/manifest.json +0 -25
- package/public/robots.txt +0 -3
- package/server/.env.example +0 -3
- package/server/deploy.js +0 -29
- package/server/package-lock.json +0 -712
- package/server/package.json +0 -18
- package/src/App.css +0 -38
- package/src/App.tsx +0 -50
- package/src/components/GenericForm.tsx +0 -308
- package/src/components/Page.tsx +0 -243
- package/src/index.css +0 -13
- package/src/index.tsx +0 -20
- package/src/logo.svg +0 -1
- package/src/pages/event.ts +0 -93
- package/src/pages/page.ts +0 -336
- package/src/react-app-env.d.ts +0 -1
- package/src/reportWebVitals.ts +0 -15
- package/src/schema/schema.config.ts +0 -8
- package/src/schema/schema.ts +0 -63
- package/src/setupTests.ts +0 -5
- package/src/utils/websockets.tsx +0 -17
- package/tsconfig.esm.json +0 -7
- package/webpack.config.js +0 -22
|
@@ -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
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useState } from "react";
|
|
3
|
-
import { ChakraProvider } from "@chakra-ui/react";
|
|
4
|
-
import { Button, Modal, ModalHeader, ModalBody, useDisclosure, ModalOverlay, ModalContent, ModalCloseButton, Box, Stack, } from "@chakra-ui/react";
|
|
5
|
-
import { GenericForm } from "./GenericForm";
|
|
6
|
-
import { ThemeProvider } from "@emotion/react";
|
|
7
|
-
import { createTheme } from "@mui/material/styles";
|
|
8
|
-
import { MaterialReactTable } from "material-react-table";
|
|
9
|
-
import { mkConfig, generateCsv, download } from "export-to-csv";
|
|
10
|
-
import Swal from "sweetalert2";
|
|
11
|
-
import MenuItem from "@mui/material/MenuItem";
|
|
12
|
-
import { io } from "socket.io-client";
|
|
13
|
-
import { newSocket } from "../utils/websockets";
|
|
14
|
-
export function pageToUrl(page) {
|
|
15
|
-
return "".concat(page.name.toLowerCase().replace(" ", "_"));
|
|
16
|
-
}
|
|
17
|
-
function Header(_a) {
|
|
18
|
-
var pages = _a.pages, data = _a.data, basePath = _a.basePath;
|
|
19
|
-
return (_jsx(Box, { background: "blue.50", padding: 1, children: _jsxs(Stack, { margin: 3, direction: "row", justifyContent: "space-between", alignItems: "center", children: [_jsx(Stack, { margin: 4, gap: 10, direction: "row", alignItems: "center", children: pages.map(function (p) { return (_jsx(Box, { as: "a", href: "".concat(basePath, "/").concat(pageToUrl(p)), children: p.name })); }) }), _jsx(Stack, { direction: "row", children: _jsx(Button, { colorScheme: "red", onClick: function () {
|
|
20
|
-
var filename = prompt("Enter filename:");
|
|
21
|
-
if (filename)
|
|
22
|
-
exportToCSV(data, filename);
|
|
23
|
-
}, children: "Export Data" }) })] }) }));
|
|
24
|
-
}
|
|
25
|
-
function exportToCSV(data, filename) {
|
|
26
|
-
var formatImageData = function (obj) {
|
|
27
|
-
var formattedObj = {};
|
|
28
|
-
var _loop_1 = function (key) {
|
|
29
|
-
if (typeof obj[key] !== "object") {
|
|
30
|
-
formattedObj[key] = obj[key];
|
|
31
|
-
}
|
|
32
|
-
else if (typeof obj[key] === "object" && obj[key] != null) {
|
|
33
|
-
Object.keys(obj[key]).forEach(function (k) {
|
|
34
|
-
formattedObj["".concat(key, ".").concat(k)] = obj[key][k];
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
for (var key in obj) {
|
|
39
|
-
_loop_1(key);
|
|
40
|
-
}
|
|
41
|
-
return formattedObj;
|
|
42
|
-
};
|
|
43
|
-
var formattedData = data.map(formatImageData);
|
|
44
|
-
var csvConfig = mkConfig({
|
|
45
|
-
useKeysAsHeaders: true,
|
|
46
|
-
filename: filename,
|
|
47
|
-
});
|
|
48
|
-
if (formattedData.length > 0) {
|
|
49
|
-
var csv = generateCsv(csvConfig)(formattedData);
|
|
50
|
-
download(csvConfig)(csv);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
Swal.fire({
|
|
54
|
-
title: "Error while exporting CSV!",
|
|
55
|
-
text: "There is no data to export.",
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
export function AdminPage(_a) {
|
|
60
|
-
var _b;
|
|
61
|
-
var pages = _a.pages, selectedPage = _a.selectedPage, basePath = _a.basePath, _c = _a.apiURL, apiURL = _c === void 0 ? '' : _c;
|
|
62
|
-
var _d = useDisclosure(), isOpen = _d.isOpen, onOpen = _d.onOpen, onClose = _d.onClose;
|
|
63
|
-
var _e = useState({}), selectedAction = _e[0], setSelectedAction = _e[1];
|
|
64
|
-
var _f = useState([]), data = _f[0], setData = _f[1];
|
|
65
|
-
var _g = useState([]), displayData = _g[0], setDisplayData = _g[1];
|
|
66
|
-
var _h = useState(), rowId = _h[0], setRowId = _h[1];
|
|
67
|
-
var _j = useState(false), refetch = _j[0], setRefetch = _j[1];
|
|
68
|
-
var _k = useState(io), socket = _k[0], setSocket = _k[1];
|
|
69
|
-
newSocket(setSocket, apiURL);
|
|
70
|
-
useEffect(function () {
|
|
71
|
-
selectedPage.getRequest().then(function (resArray) {
|
|
72
|
-
setData(resArray);
|
|
73
|
-
setRefetch(false);
|
|
74
|
-
});
|
|
75
|
-
}, [refetch]); // Do not remove 'refetch' from here !!!
|
|
76
|
-
useEffect(function () {
|
|
77
|
-
socket.on("updateData", function (message) {
|
|
78
|
-
console.log("Message emitted from socket: " + message);
|
|
79
|
-
setRefetch(true);
|
|
80
|
-
var rowActionsMenu = document.querySelector(".MuiPaper-root.MuiPopover-paper.MuiMenu-paper");
|
|
81
|
-
if (rowActionsMenu) {
|
|
82
|
-
rowActionsMenu.remove();
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}, [socket, selectedPage]);
|
|
86
|
-
useEffect(function () {
|
|
87
|
-
setDisplayData(data.map(function (table_data) {
|
|
88
|
-
return selectedPage.tableFields.map(function (field) { return field.access(table_data); });
|
|
89
|
-
}));
|
|
90
|
-
}, [data]);
|
|
91
|
-
return (_jsxs(_Fragment, { children: [_jsx(Header, { pages: pages, data: data, basePath: basePath }), _jsx(ThemeProvider, { theme: createTheme(), children: _jsx(MaterialReactTable, { columns: selectedPage.tableFields.map(function (field, index) { return ({
|
|
92
|
-
accessorFn: function (row) { return row[index]; },
|
|
93
|
-
header: field.name,
|
|
94
|
-
}); }), data: displayData, muiTableContainerProps: { sx: { maxHeight: "70vh" } }, enableColumnResizing: true, enableColumnPinning: true, enableGlobalFilterModes: true, enablePagination: true, paginationDisplayMode: "pages", enableRowVirtualization: true, rowVirtualizerOptions: { overscan: 20 }, renderTopToolbarCustomActions: function () { return (_jsx(ChakraProvider, { children: _jsx(Stack, { margin: 0, padding: 3, direction: "row", children: selectedPage.actions.map(function (action) { return (_jsx(Button, { colorScheme: "blue", onClick: function () {
|
|
95
|
-
setSelectedAction(action);
|
|
96
|
-
onOpen();
|
|
97
|
-
}, children: action.name })); }) }) })); }, enableRowActions: true, renderRowActionMenuItems: function (obj) {
|
|
98
|
-
return selectedPage.rowActions.map(function (rowAction) { return (_jsx(MenuItem, { onClick: function () {
|
|
99
|
-
setSelectedAction(rowAction);
|
|
100
|
-
setRowId(obj.row.original[0]);
|
|
101
|
-
onOpen();
|
|
102
|
-
var rowActionsMenu = document.querySelector(".MuiPaper-root.MuiPopover-paper.MuiMenu-paper");
|
|
103
|
-
if (rowActionsMenu) {
|
|
104
|
-
rowActionsMenu.remove();
|
|
105
|
-
}
|
|
106
|
-
}, children: rowAction.name + " " + obj.row.original[0] })); });
|
|
107
|
-
} }) }), _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 && ((_b = selectedAction.fields) === null || _b === void 0 ? void 0 : _b.length) > 0 ? (_jsx(GenericForm, { action: selectedAction, onClose: onClose, rowId: rowId })) : (_jsx(Button, { colorScheme: "blue", mr: 3, onClick: function () {
|
|
108
|
-
selectedAction.onSubmit(rowId);
|
|
109
|
-
onClose();
|
|
110
|
-
}, children: "Confirm Action" })), _jsx(Button, { colorScheme: "red", mr: 3, onClick: onClose, children: "Close" })] })] })] })] }));
|
|
111
|
-
}
|
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();
|
package/dist/esm/pages/event.js
DELETED
|
@@ -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
|
-
};
|