admin_lsac 1.3.1 → 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
package/dist/cjs/App.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
|
-
var react_1 = require("@chakra-ui/react");
|
|
5
|
-
var react_router_dom_1 = require("react-router-dom");
|
|
6
|
-
var Page_1 = require("./components/Page");
|
|
7
|
-
var Page_2 = require("./components/Page");
|
|
8
|
-
function App(_a) {
|
|
9
|
-
var pages = _a.pages, basePath = _a.basePath;
|
|
10
|
-
return ((0, jsx_runtime_1.jsx)(react_1.ChakraProvider, { children: (0, jsx_runtime_1.jsx)(react_router_dom_1.BrowserRouter, { children: (0, jsx_runtime_1.jsxs)(react_router_dom_1.Routes, { children: [pages.map(function (page) { return ((0, jsx_runtime_1.jsx)(react_router_dom_1.Route, { path: "".concat(basePath, "/").concat((0, Page_2.pageToUrl)(page)), element: (0, jsx_runtime_1.jsx)(Page_1.AdminPage, { pages: pages, selectedPage: page, basePath: basePath, apiURL: "http://localhost:3001" }) })); }), pages[0] ? ((0, jsx_runtime_1.jsx)(react_router_dom_1.Route, { path: "".concat(basePath, "/*"), element: (0, jsx_runtime_1.jsx)(Page_1.AdminPage, { pages: pages, selectedPage: pages[0], basePath: basePath, apiURL: "http://localhost:3001" }) })) : null] }) }) }));
|
|
11
|
-
}
|
|
12
|
-
exports.default = App;
|
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
-
if (k2 === undefined) k2 = k;
|
|
15
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
-
}
|
|
19
|
-
Object.defineProperty(o, k2, desc);
|
|
20
|
-
}) : (function(o, m, k, k2) {
|
|
21
|
-
if (k2 === undefined) k2 = k;
|
|
22
|
-
o[k2] = m[k];
|
|
23
|
-
}));
|
|
24
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
-
}) : function(o, v) {
|
|
27
|
-
o["default"] = v;
|
|
28
|
-
});
|
|
29
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
30
|
-
if (mod && mod.__esModule) return mod;
|
|
31
|
-
var result = {};
|
|
32
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
33
|
-
__setModuleDefault(result, mod);
|
|
34
|
-
return result;
|
|
35
|
-
};
|
|
36
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
39
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
40
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
41
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
42
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
46
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
47
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
48
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
49
|
-
function step(op) {
|
|
50
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
51
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
52
|
-
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;
|
|
53
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
54
|
-
switch (op[0]) {
|
|
55
|
-
case 0: case 1: t = op; break;
|
|
56
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
57
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
58
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
59
|
-
default:
|
|
60
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
61
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
62
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
63
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
64
|
-
if (t[2]) _.ops.pop();
|
|
65
|
-
_.trys.pop(); continue;
|
|
66
|
-
}
|
|
67
|
-
op = body.call(thisArg, _);
|
|
68
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
69
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
73
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
74
|
-
};
|
|
75
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
76
|
-
exports.GenericForm = void 0;
|
|
77
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
78
|
-
var react_1 = require("@chakra-ui/react");
|
|
79
|
-
var formik_1 = require("formik");
|
|
80
|
-
var Yup = __importStar(require("yup"));
|
|
81
|
-
var sweetalert2_1 = __importDefault(require("sweetalert2"));
|
|
82
|
-
var react_2 = require("react");
|
|
83
|
-
function parseValidation(fields) {
|
|
84
|
-
if (!fields) {
|
|
85
|
-
return {};
|
|
86
|
-
}
|
|
87
|
-
return fields.reduce(function (acc, field) {
|
|
88
|
-
if (field.type !== "dropdown" &&
|
|
89
|
-
field.type !== "object" &&
|
|
90
|
-
field.type !== "array") {
|
|
91
|
-
acc[field.name] = field.validationSchema;
|
|
92
|
-
}
|
|
93
|
-
else if (field.type === "array") {
|
|
94
|
-
if (field.element.type === "dropdown") {
|
|
95
|
-
acc[field.name] = Yup.array().of(Yup.string().required());
|
|
96
|
-
}
|
|
97
|
-
else if (field.element.type === "object") {
|
|
98
|
-
acc[field.name] = Yup.array().of(Yup.object(parseValidation(field.element.fields)));
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
acc[field.name] = Yup.array().of(field.element.validationSchema);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
else if (field.type === "object") {
|
|
105
|
-
acc[field.name] = Yup.object(parseValidation(field.fields));
|
|
106
|
-
}
|
|
107
|
-
if (field.type === "dropdown") {
|
|
108
|
-
acc[field.name] = Yup.string().required();
|
|
109
|
-
}
|
|
110
|
-
return acc;
|
|
111
|
-
}, {});
|
|
112
|
-
}
|
|
113
|
-
function generateSingleField(formfield, fieldName, key) {
|
|
114
|
-
return ((0, jsx_runtime_1.jsx)(formik_1.Field, { name: fieldName, children: function (_a) {
|
|
115
|
-
var _b;
|
|
116
|
-
var field = _a.field, form = _a.form;
|
|
117
|
-
return ((0, jsx_runtime_1.jsxs)(react_1.FormControl, { isInvalid: (0, formik_1.getIn)(form.touched, fieldName) && (0, formik_1.getIn)(form.errors, fieldName), children: [(0, jsx_runtime_1.jsx)(react_1.FormLabel, { marginTop: 2, children: formfield.label }), formfield.type === "string" || formfield.type === "number" ? ((0, jsx_runtime_1.jsx)(react_1.Input, __assign({}, field, { type: formfield.type === "number" ? "number" : "text", placeholder: "" }))) : formfield.type === "file" ? ((0, jsx_runtime_1.jsx)(react_1.Input, { type: "file", name: fieldName, onChange: function (event) {
|
|
118
|
-
if (event.currentTarget.files != null) {
|
|
119
|
-
form.setFieldValue(fieldName, event.currentTarget.files[0]);
|
|
120
|
-
}
|
|
121
|
-
} })) : ((0, jsx_runtime_1.jsxs)(react_1.Select, __assign({}, field, { defaultValue: "", children: [(0, jsx_runtime_1.jsx)("option", { disabled: true, value: "", children: "Select an option!" }), (_b = formfield.options) === null || _b === void 0 ? void 0 : _b.map(function (option, key) { return ((0, jsx_runtime_1.jsx)("option", { value: "".concat(option.value), children: option.display }, key)); })] }))), (0, jsx_runtime_1.jsx)(react_1.FormErrorMessage, { children: (0, formik_1.getIn)(form.errors, fieldName) })] }));
|
|
122
|
-
} }, key));
|
|
123
|
-
}
|
|
124
|
-
function parseFields(fields, previous) {
|
|
125
|
-
if (!fields) {
|
|
126
|
-
return [];
|
|
127
|
-
}
|
|
128
|
-
var computedFields = fields.map(function (formfield, key) {
|
|
129
|
-
var fieldName = previous !== undefined ? previous + "." + formfield.name : formfield.name;
|
|
130
|
-
if (formfield.type === "object") {
|
|
131
|
-
var objectFields = parseFields(formfield.fields, fieldName);
|
|
132
|
-
return (0, jsx_runtime_1.jsx)(react_1.FormControl, { children: objectFields }, fieldName);
|
|
133
|
-
}
|
|
134
|
-
else if (formfield.type === "array") {
|
|
135
|
-
return ((0, jsx_runtime_1.jsx)(formik_1.FieldArray, { name: fieldName, children: function (_a) {
|
|
136
|
-
var remove = _a.remove, push = _a.push, form = _a.form;
|
|
137
|
-
return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)(react_1.FormLabel, { marginTop: 2, children: formfield.label }), (0, formik_1.getIn)(form.values, fieldName).length > 0 &&
|
|
138
|
-
(0, formik_1.getIn)(form.values, fieldName).map(function (element, index) { return ((0, jsx_runtime_1.jsxs)(react_1.Box, { paddingLeft: 10, children: [(0, jsx_runtime_1.jsx)("h4", { children: (0, jsx_runtime_1.jsx)("b", { children: "".concat(fieldName, ".").concat(index) }) }), (0, jsx_runtime_1.jsx)(react_1.Box, { paddingLeft: 10, children: formfield.element.type === "object"
|
|
139
|
-
? parseFields(formfield.element.fields, "".concat(fieldName, ".").concat(index))
|
|
140
|
-
: generateSingleField(formfield.element, "".concat(fieldName, ".").concat(index), key) }), (0, jsx_runtime_1.jsxs)(react_1.Button, { type: "button", colorScheme: "red", marginY: 2, onClick: function () { return remove(index); }, children: ["Remove ", "".concat(fieldName, ".").concat(index)] })] })); }), (0, jsx_runtime_1.jsxs)(react_1.Button, { type: "button", marginY: 2, colorScheme: "blue", onClick: function () {
|
|
141
|
-
var value = undefined;
|
|
142
|
-
if (formfield.element.type === "object") {
|
|
143
|
-
value = getCustomInitialValues(formfield.element.fields);
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
value = getCustomInitialValues([formfield.element])[0];
|
|
147
|
-
}
|
|
148
|
-
push(value);
|
|
149
|
-
}, children: ["Add ", fieldName] })] }));
|
|
150
|
-
} }));
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
return generateSingleField(formfield, fieldName, key);
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
return computedFields;
|
|
157
|
-
}
|
|
158
|
-
function getCustomInitialValues(fields) {
|
|
159
|
-
var obj = {};
|
|
160
|
-
if (!fields) {
|
|
161
|
-
return obj;
|
|
162
|
-
}
|
|
163
|
-
fields.forEach(function (field) {
|
|
164
|
-
if (field.type === "array")
|
|
165
|
-
obj[field.name] = [];
|
|
166
|
-
else if (field.type === "object")
|
|
167
|
-
obj[field.name] = getCustomInitialValues(field.fields);
|
|
168
|
-
else if (field.type === "string")
|
|
169
|
-
obj[field.name] = "";
|
|
170
|
-
else if (field.type === "number")
|
|
171
|
-
obj[field.name] = 0;
|
|
172
|
-
else
|
|
173
|
-
obj[field.name] = null;
|
|
174
|
-
});
|
|
175
|
-
return obj;
|
|
176
|
-
}
|
|
177
|
-
function getInitialValues(action, rowId) {
|
|
178
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
179
|
-
var obj, customInitialValues;
|
|
180
|
-
return __generator(this, function (_a) {
|
|
181
|
-
switch (_a.label) {
|
|
182
|
-
case 0:
|
|
183
|
-
obj = {};
|
|
184
|
-
if (!action.initialise) return [3 /*break*/, 2];
|
|
185
|
-
return [4 /*yield*/, action.initialise(rowId)];
|
|
186
|
-
case 1:
|
|
187
|
-
obj = _a.sent();
|
|
188
|
-
_a.label = 2;
|
|
189
|
-
case 2:
|
|
190
|
-
customInitialValues = getCustomInitialValues(action.fields);
|
|
191
|
-
return [2 /*return*/, Object.assign({}, customInitialValues, obj)];
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
function setOptions(fields) {
|
|
197
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
198
|
-
var promises;
|
|
199
|
-
var _this = this;
|
|
200
|
-
return __generator(this, function (_a) {
|
|
201
|
-
switch (_a.label) {
|
|
202
|
-
case 0:
|
|
203
|
-
if (!fields) {
|
|
204
|
-
return [2 /*return*/];
|
|
205
|
-
}
|
|
206
|
-
promises = fields.map(function (field) { return __awaiter(_this, void 0, void 0, function () {
|
|
207
|
-
var _a;
|
|
208
|
-
return __generator(this, function (_b) {
|
|
209
|
-
switch (_b.label) {
|
|
210
|
-
case 0:
|
|
211
|
-
if (!(field.type === "dropdown")) return [3 /*break*/, 2];
|
|
212
|
-
_a = field;
|
|
213
|
-
return [4 /*yield*/, field.getOptions()];
|
|
214
|
-
case 1:
|
|
215
|
-
_a.options = _b.sent();
|
|
216
|
-
return [3 /*break*/, 6];
|
|
217
|
-
case 2:
|
|
218
|
-
if (!(field.type === "array")) return [3 /*break*/, 4];
|
|
219
|
-
return [4 /*yield*/, setOptions([field.element])];
|
|
220
|
-
case 3:
|
|
221
|
-
_b.sent();
|
|
222
|
-
return [3 /*break*/, 6];
|
|
223
|
-
case 4:
|
|
224
|
-
if (!(field.type === "object")) return [3 /*break*/, 6];
|
|
225
|
-
return [4 /*yield*/, setOptions(field.fields)];
|
|
226
|
-
case 5:
|
|
227
|
-
_b.sent();
|
|
228
|
-
_b.label = 6;
|
|
229
|
-
case 6: return [2 /*return*/];
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
}); });
|
|
233
|
-
return [4 /*yield*/, Promise.all(promises)];
|
|
234
|
-
case 1:
|
|
235
|
-
_a.sent();
|
|
236
|
-
return [2 /*return*/];
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
function GenericForm(_a) {
|
|
242
|
-
var _this = this;
|
|
243
|
-
var action = _a.action, onClose = _a.onClose, rowId = _a.rowId;
|
|
244
|
-
var _b = (0, react_2.useState)(parseFields(action.fields)), formFields = _b[0], setFormFields = _b[1];
|
|
245
|
-
var _c = (0, react_2.useState)(getCustomInitialValues(action.fields)), initialValues = _c[0], setInitialValues = _c[1];
|
|
246
|
-
var _d = (0, react_2.useState)(parseValidation(action.fields)), validationSchema = _d[0], setValidationSchema = _d[1];
|
|
247
|
-
(0, react_2.useEffect)(function () {
|
|
248
|
-
setOptions(action.fields).then(function () {
|
|
249
|
-
setFormFields(parseFields(action.fields));
|
|
250
|
-
});
|
|
251
|
-
}, []);
|
|
252
|
-
var handleFormReset = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
253
|
-
var newInitialValues;
|
|
254
|
-
return __generator(this, function (_a) {
|
|
255
|
-
switch (_a.label) {
|
|
256
|
-
case 0: return [4 /*yield*/, getInitialValues(action, rowId)];
|
|
257
|
-
case 1:
|
|
258
|
-
newInitialValues = _a.sent();
|
|
259
|
-
console.log(newInitialValues);
|
|
260
|
-
setInitialValues(newInitialValues);
|
|
261
|
-
return [2 /*return*/];
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
}); };
|
|
265
|
-
if (!action.fields)
|
|
266
|
-
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {});
|
|
267
|
-
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(formik_1.Formik, { enableReinitialize: true, initialValues: initialValues, validationSchema: Yup.object(validationSchema), onReset: handleFormReset, onSubmit: function (values) { return __awaiter(_this, void 0, void 0, function () {
|
|
268
|
-
var res, e_1, err;
|
|
269
|
-
return __generator(this, function (_a) {
|
|
270
|
-
switch (_a.label) {
|
|
271
|
-
case 0:
|
|
272
|
-
_a.trys.push([0, 5, , 6]);
|
|
273
|
-
res = void 0;
|
|
274
|
-
if (!rowId) return [3 /*break*/, 2];
|
|
275
|
-
return [4 /*yield*/, action.onSubmit(values, rowId)];
|
|
276
|
-
case 1:
|
|
277
|
-
res = _a.sent();
|
|
278
|
-
return [3 /*break*/, 4];
|
|
279
|
-
case 2: return [4 /*yield*/, action.onSubmit(values)];
|
|
280
|
-
case 3:
|
|
281
|
-
res = _a.sent();
|
|
282
|
-
_a.label = 4;
|
|
283
|
-
case 4:
|
|
284
|
-
if (onClose)
|
|
285
|
-
onClose();
|
|
286
|
-
sweetalert2_1.default.fire("Ok");
|
|
287
|
-
return [3 /*break*/, 6];
|
|
288
|
-
case 5:
|
|
289
|
-
e_1 = _a.sent();
|
|
290
|
-
if (onClose)
|
|
291
|
-
onClose();
|
|
292
|
-
err = e_1.request.response;
|
|
293
|
-
sweetalert2_1.default.fire({
|
|
294
|
-
text: "Error: " + err,
|
|
295
|
-
});
|
|
296
|
-
return [3 /*break*/, 6];
|
|
297
|
-
case 6: return [2 /*return*/];
|
|
298
|
-
}
|
|
299
|
-
});
|
|
300
|
-
}); }, children: function (_a) {
|
|
301
|
-
var isSubmitting = _a.isSubmitting;
|
|
302
|
-
return ((0, jsx_runtime_1.jsxs)(formik_1.Form, { children: [formFields, (0, jsx_runtime_1.jsx)(react_1.Button, { mt: 4, colorScheme: "teal", isLoading: isSubmitting, type: "submit", children: "Submit" }), (0, jsx_runtime_1.jsx)(react_1.Button, { mt: 4, colorScheme: "teal", type: "reset", children: "Initialise Form" })] }));
|
|
303
|
-
} }) }));
|
|
304
|
-
}
|
|
305
|
-
exports.GenericForm = GenericForm;
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.AdminPage = exports.pageToUrl = void 0;
|
|
7
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
-
var react_1 = require("react");
|
|
9
|
-
var react_2 = require("@chakra-ui/react");
|
|
10
|
-
var react_3 = require("@chakra-ui/react");
|
|
11
|
-
var GenericForm_1 = require("./GenericForm");
|
|
12
|
-
var react_4 = require("@emotion/react");
|
|
13
|
-
var styles_1 = require("@mui/material/styles");
|
|
14
|
-
var material_react_table_1 = require("material-react-table");
|
|
15
|
-
var export_to_csv_1 = require("export-to-csv");
|
|
16
|
-
var sweetalert2_1 = __importDefault(require("sweetalert2"));
|
|
17
|
-
var MenuItem_1 = __importDefault(require("@mui/material/MenuItem"));
|
|
18
|
-
var socket_io_client_1 = require("socket.io-client");
|
|
19
|
-
var websockets_1 = require("../utils/websockets");
|
|
20
|
-
function pageToUrl(page) {
|
|
21
|
-
return "".concat(page.name.toLowerCase().replace(" ", "_"));
|
|
22
|
-
}
|
|
23
|
-
exports.pageToUrl = pageToUrl;
|
|
24
|
-
function Header(_a) {
|
|
25
|
-
var pages = _a.pages, data = _a.data, basePath = _a.basePath;
|
|
26
|
-
return ((0, jsx_runtime_1.jsx)(react_3.Box, { background: "blue.50", padding: 1, children: (0, jsx_runtime_1.jsxs)(react_3.Stack, { margin: 3, direction: "row", justifyContent: "space-between", alignItems: "center", children: [(0, jsx_runtime_1.jsx)(react_3.Stack, { margin: 4, gap: 10, direction: "row", alignItems: "center", children: pages.map(function (p) { return ((0, jsx_runtime_1.jsx)(react_3.Box, { as: "a", href: "".concat(basePath, "/").concat(pageToUrl(p)), children: p.name })); }) }), (0, jsx_runtime_1.jsx)(react_3.Stack, { direction: "row", children: (0, jsx_runtime_1.jsx)(react_3.Button, { colorScheme: "red", onClick: function () {
|
|
27
|
-
var filename = prompt("Enter filename:");
|
|
28
|
-
if (filename)
|
|
29
|
-
exportToCSV(data, filename);
|
|
30
|
-
}, children: "Export Data" }) })] }) }));
|
|
31
|
-
}
|
|
32
|
-
function exportToCSV(data, filename) {
|
|
33
|
-
var formatImageData = function (obj) {
|
|
34
|
-
var formattedObj = {};
|
|
35
|
-
var _loop_1 = function (key) {
|
|
36
|
-
if (typeof obj[key] !== "object") {
|
|
37
|
-
formattedObj[key] = obj[key];
|
|
38
|
-
}
|
|
39
|
-
else if (typeof obj[key] === "object" && obj[key] != null) {
|
|
40
|
-
Object.keys(obj[key]).forEach(function (k) {
|
|
41
|
-
formattedObj["".concat(key, ".").concat(k)] = obj[key][k];
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
for (var key in obj) {
|
|
46
|
-
_loop_1(key);
|
|
47
|
-
}
|
|
48
|
-
return formattedObj;
|
|
49
|
-
};
|
|
50
|
-
var formattedData = data.map(formatImageData);
|
|
51
|
-
var csvConfig = (0, export_to_csv_1.mkConfig)({
|
|
52
|
-
useKeysAsHeaders: true,
|
|
53
|
-
filename: filename,
|
|
54
|
-
});
|
|
55
|
-
if (formattedData.length > 0) {
|
|
56
|
-
var csv = (0, export_to_csv_1.generateCsv)(csvConfig)(formattedData);
|
|
57
|
-
(0, export_to_csv_1.download)(csvConfig)(csv);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
sweetalert2_1.default.fire({
|
|
61
|
-
title: "Error while exporting CSV!",
|
|
62
|
-
text: "There is no data to export.",
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
function AdminPage(_a) {
|
|
67
|
-
var _b;
|
|
68
|
-
var pages = _a.pages, selectedPage = _a.selectedPage, basePath = _a.basePath, _c = _a.apiURL, apiURL = _c === void 0 ? '' : _c;
|
|
69
|
-
var _d = (0, react_3.useDisclosure)(), isOpen = _d.isOpen, onOpen = _d.onOpen, onClose = _d.onClose;
|
|
70
|
-
var _e = (0, react_1.useState)({}), selectedAction = _e[0], setSelectedAction = _e[1];
|
|
71
|
-
var _f = (0, react_1.useState)([]), data = _f[0], setData = _f[1];
|
|
72
|
-
var _g = (0, react_1.useState)([]), displayData = _g[0], setDisplayData = _g[1];
|
|
73
|
-
var _h = (0, react_1.useState)(), rowId = _h[0], setRowId = _h[1];
|
|
74
|
-
var _j = (0, react_1.useState)(false), refetch = _j[0], setRefetch = _j[1];
|
|
75
|
-
var _k = (0, react_1.useState)(socket_io_client_1.io), socket = _k[0], setSocket = _k[1];
|
|
76
|
-
(0, websockets_1.newSocket)(setSocket, apiURL);
|
|
77
|
-
(0, react_1.useEffect)(function () {
|
|
78
|
-
selectedPage.getRequest().then(function (resArray) {
|
|
79
|
-
setData(resArray);
|
|
80
|
-
setRefetch(false);
|
|
81
|
-
});
|
|
82
|
-
}, [refetch]); // Do not remove 'refetch' from here !!!
|
|
83
|
-
(0, react_1.useEffect)(function () {
|
|
84
|
-
socket.on("updateData", function (message) {
|
|
85
|
-
console.log("Message emitted from socket: " + message);
|
|
86
|
-
setRefetch(true);
|
|
87
|
-
var rowActionsMenu = document.querySelector(".MuiPaper-root.MuiPopover-paper.MuiMenu-paper");
|
|
88
|
-
if (rowActionsMenu) {
|
|
89
|
-
rowActionsMenu.remove();
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}, [socket, selectedPage]);
|
|
93
|
-
(0, react_1.useEffect)(function () {
|
|
94
|
-
setDisplayData(data.map(function (table_data) {
|
|
95
|
-
return selectedPage.tableFields.map(function (field) { return field.access(table_data); });
|
|
96
|
-
}));
|
|
97
|
-
}, [data]);
|
|
98
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Header, { pages: pages, data: data, basePath: basePath }), (0, jsx_runtime_1.jsx)(react_4.ThemeProvider, { theme: (0, styles_1.createTheme)(), children: (0, jsx_runtime_1.jsx)(material_react_table_1.MaterialReactTable, { columns: selectedPage.tableFields.map(function (field, index) { return ({
|
|
99
|
-
accessorFn: function (row) { return row[index]; },
|
|
100
|
-
header: field.name,
|
|
101
|
-
}); }), data: displayData, muiTableContainerProps: { sx: { maxHeight: "70vh" } }, enableColumnResizing: true, enableColumnPinning: true, enableGlobalFilterModes: true, enablePagination: true, paginationDisplayMode: "pages", enableRowVirtualization: true, rowVirtualizerOptions: { overscan: 20 }, renderTopToolbarCustomActions: function () { return ((0, jsx_runtime_1.jsx)(react_2.ChakraProvider, { children: (0, jsx_runtime_1.jsx)(react_3.Stack, { margin: 0, padding: 3, direction: "row", children: selectedPage.actions.map(function (action) { return ((0, jsx_runtime_1.jsx)(react_3.Button, { colorScheme: "blue", onClick: function () {
|
|
102
|
-
setSelectedAction(action);
|
|
103
|
-
onOpen();
|
|
104
|
-
}, children: action.name })); }) }) })); }, enableRowActions: true, renderRowActionMenuItems: function (obj) {
|
|
105
|
-
return selectedPage.rowActions.map(function (rowAction) { return ((0, jsx_runtime_1.jsx)(MenuItem_1.default, { onClick: function () {
|
|
106
|
-
setSelectedAction(rowAction);
|
|
107
|
-
setRowId(obj.row.original[0]);
|
|
108
|
-
onOpen();
|
|
109
|
-
var rowActionsMenu = document.querySelector(".MuiPaper-root.MuiPopover-paper.MuiMenu-paper");
|
|
110
|
-
if (rowActionsMenu) {
|
|
111
|
-
rowActionsMenu.remove();
|
|
112
|
-
}
|
|
113
|
-
}, children: rowAction.name + " " + obj.row.original[0] })); });
|
|
114
|
-
} }) }), (0, jsx_runtime_1.jsxs)(react_3.Modal, { size: "6xl", isOpen: isOpen, onClose: onClose, children: [(0, jsx_runtime_1.jsx)(react_3.ModalOverlay, {}), (0, jsx_runtime_1.jsxs)(react_3.ModalContent, { children: [(0, jsx_runtime_1.jsx)(react_3.ModalHeader, { children: selectedAction.name }), (0, jsx_runtime_1.jsx)(react_3.ModalCloseButton, {}), (0, jsx_runtime_1.jsxs)(react_3.ModalBody, { children: [selectedAction.fields && ((_b = selectedAction.fields) === null || _b === void 0 ? void 0 : _b.length) > 0 ? ((0, jsx_runtime_1.jsx)(GenericForm_1.GenericForm, { action: selectedAction, onClose: onClose, rowId: rowId })) : ((0, jsx_runtime_1.jsx)(react_3.Button, { colorScheme: "blue", mr: 3, onClick: function () {
|
|
115
|
-
selectedAction.onSubmit(rowId);
|
|
116
|
-
onClose();
|
|
117
|
-
}, children: "Confirm Action" })), (0, jsx_runtime_1.jsx)(react_3.Button, { colorScheme: "red", mr: 3, onClick: onClose, children: "Close" })] })] })] })] }));
|
|
118
|
-
}
|
|
119
|
-
exports.AdminPage = AdminPage;
|
package/dist/cjs/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
-
var react_1 = __importDefault(require("react"));
|
|
8
|
-
var client_1 = __importDefault(require("react-dom/client"));
|
|
9
|
-
require("./index.css");
|
|
10
|
-
var App_1 = __importDefault(require("./App"));
|
|
11
|
-
var reportWebVitals_1 = __importDefault(require("./reportWebVitals"));
|
|
12
|
-
var schema_config_1 = require("./schema/schema.config");
|
|
13
|
-
var root = client_1.default.createRoot(document.getElementById("root"));
|
|
14
|
-
root.render((0, jsx_runtime_1.jsx)(react_1.default.StrictMode, { children: (0, jsx_runtime_1.jsx)(App_1.default, { pages: schema_config_1.pages, basePath: "" }) }));
|
|
15
|
-
// If you want to start measuring performance in your app, pass a function
|
|
16
|
-
// to log results (for example: reportWebVitals(console.log))
|
|
17
|
-
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
|
18
|
-
(0, reportWebVitals_1.default)();
|
package/dist/cjs/pages/event.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.event = void 0;
|
|
43
|
-
var react_1 = __importDefault(require("react"));
|
|
44
|
-
var domain = "http://localhost:3001";
|
|
45
|
-
exports.event = {
|
|
46
|
-
name: "Events",
|
|
47
|
-
actions: [],
|
|
48
|
-
rowActions: [
|
|
49
|
-
// {
|
|
50
|
-
// name: "Delete Event",
|
|
51
|
-
// fields: [
|
|
52
|
-
// {
|
|
53
|
-
// name: "input",
|
|
54
|
-
// label: "Mock Field",
|
|
55
|
-
// type: "string",
|
|
56
|
-
// validationSchema: "",
|
|
57
|
-
// },
|
|
58
|
-
// ],
|
|
59
|
-
// initialise: async (eventId: number) => {
|
|
60
|
-
// const res = await axios.get(domain + "/events/" + eventId);
|
|
61
|
-
// let obj: any = {};
|
|
62
|
-
// obj.input = res.data.name;
|
|
63
|
-
// return obj;
|
|
64
|
-
// },
|
|
65
|
-
// onSubmit: async (formValues: any, eventId: number) => {
|
|
66
|
-
// const res = await axios.delete(
|
|
67
|
-
// domain + "/events/" + eventId
|
|
68
|
-
// );
|
|
69
|
-
// return res.data;
|
|
70
|
-
// },
|
|
71
|
-
// }
|
|
72
|
-
],
|
|
73
|
-
getRequest: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
74
|
-
return __generator(this, function (_a) {
|
|
75
|
-
// const res = await axios.get(domain + "/events");
|
|
76
|
-
// return res.data;
|
|
77
|
-
return [2 /*return*/, []];
|
|
78
|
-
});
|
|
79
|
-
}); },
|
|
80
|
-
tableFields: [
|
|
81
|
-
{
|
|
82
|
-
name: "Id",
|
|
83
|
-
access: function (obj) { return obj.id; },
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
name: "Event Name",
|
|
87
|
-
access: function (obj) { return obj.name; },
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
name: "Description",
|
|
91
|
-
access: function (obj) { return obj.description; },
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
name: "Category",
|
|
95
|
-
access: function (obj) { return obj.category; },
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
name: "Ticket Type",
|
|
99
|
-
access: function (obj) { return obj.ticketType; },
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
name: "Date",
|
|
103
|
-
access: function (obj) { return obj.date; },
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
name: "Release",
|
|
107
|
-
access: function (obj) { return obj.release; },
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
name: "Is Released",
|
|
111
|
-
access: function (obj) { return (obj.isReleased ? "Is Released" : "Not Released"); },
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
name: "Available Tickets",
|
|
115
|
-
access: function (obj) { return obj.availableTickets; },
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
name: "Max Tickets",
|
|
119
|
-
access: function (obj) { return obj.maxTickets; },
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
name: "Image",
|
|
123
|
-
access: function (obj) {
|
|
124
|
-
return obj.imgUrl
|
|
125
|
-
? react_1.default.createElement("img", {
|
|
126
|
-
src: obj.imgUrl,
|
|
127
|
-
alt: "ERROR",
|
|
128
|
-
style: { width: "100px" },
|
|
129
|
-
})
|
|
130
|
-
: "No Image Available";
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
],
|
|
134
|
-
};
|