admin_lsac 1.2.7 → 1.2.8

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.
@@ -140,10 +140,10 @@ function parseFields(fields, previous) {
140
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
141
  var value = undefined;
142
142
  if (formfield.element.type === "object") {
143
- value = getInitialValues(formfield.element.fields);
143
+ value = getCustomInitialValues(formfield.element.fields);
144
144
  }
145
145
  else {
146
- value = getInitialValues([formfield.element])[0];
146
+ value = getCustomInitialValues([formfield.element])[0];
147
147
  }
148
148
  push(value);
149
149
  }, children: ["Add ", fieldName] })] }));
@@ -155,7 +155,7 @@ function parseFields(fields, previous) {
155
155
  });
156
156
  return computedFields;
157
157
  }
158
- function getInitialValues(fields) {
158
+ function getCustomInitialValues(fields) {
159
159
  var obj = {};
160
160
  if (!fields) {
161
161
  return obj;
@@ -164,7 +164,7 @@ function getInitialValues(fields) {
164
164
  if (field.type === "array")
165
165
  obj[field.name] = [];
166
166
  else if (field.type === "object")
167
- obj[field.name] = getInitialValues(field.fields);
167
+ obj[field.name] = getCustomInitialValues(field.fields);
168
168
  else if (field.type === "string")
169
169
  obj[field.name] = "";
170
170
  else if (field.type === "number")
@@ -174,6 +174,25 @@ function getInitialValues(fields) {
174
174
  });
175
175
  return obj;
176
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
+ }
177
196
  function setOptions(fields) {
178
197
  return __awaiter(this, void 0, void 0, function () {
179
198
  var promises;
@@ -223,16 +242,29 @@ function GenericForm(_a) {
223
242
  var _this = this;
224
243
  var action = _a.action, onClose = _a.onClose, rowId = _a.rowId;
225
244
  var _b = (0, react_2.useState)(parseFields(action.fields)), formFields = _b[0], setFormFields = _b[1];
226
- var initialValues = (0, react_2.useState)(getInitialValues(action.fields))[0];
227
- var validationSchema = (0, react_2.useState)(parseValidation(action.fields))[0];
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];
228
247
  (0, react_2.useEffect)(function () {
229
248
  setOptions(action.fields).then(function () {
230
249
  setFormFields(parseFields(action.fields));
231
250
  });
232
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
+ }); };
233
265
  if (!action.fields)
234
266
  return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {});
235
- return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(formik_1.Formik, { initialValues: initialValues, validationSchema: Yup.object(validationSchema), onSubmit: function (values) { return __awaiter(_this, void 0, void 0, function () {
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 () {
236
268
  var res, e_1, err;
237
269
  return __generator(this, function (_a) {
238
270
  switch (_a.label) {
@@ -267,7 +299,7 @@ function GenericForm(_a) {
267
299
  });
268
300
  }); }, children: function (_a) {
269
301
  var isSubmitting = _a.isSubmitting;
270
- 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" })] }));
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" })] }));
271
303
  } }) }));
272
304
  }
273
305
  exports.GenericForm = GenericForm;
@@ -45,7 +45,31 @@ var domain = "http://localhost:3001";
45
45
  exports.event = {
46
46
  name: "Events",
47
47
  actions: [],
48
- rowActions: [],
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
+ ],
49
73
  getRequest: function () { return __awaiter(void 0, void 0, void 0, function () {
50
74
  return __generator(this, function (_a) {
51
75
  // const res = await axios.get(domain + "/events");
@@ -140,10 +140,10 @@ function parseFields(fields, previous) {
140
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
141
  var value = undefined;
142
142
  if (formfield.element.type === "object") {
143
- value = getInitialValues(formfield.element.fields);
143
+ value = getCustomInitialValues(formfield.element.fields);
144
144
  }
145
145
  else {
146
- value = getInitialValues([formfield.element])[0];
146
+ value = getCustomInitialValues([formfield.element])[0];
147
147
  }
148
148
  push(value);
149
149
  }, children: ["Add ", fieldName] })] }));
@@ -155,7 +155,7 @@ function parseFields(fields, previous) {
155
155
  });
156
156
  return computedFields;
157
157
  }
158
- function getInitialValues(fields) {
158
+ function getCustomInitialValues(fields) {
159
159
  var obj = {};
160
160
  if (!fields) {
161
161
  return obj;
@@ -164,7 +164,7 @@ function getInitialValues(fields) {
164
164
  if (field.type === "array")
165
165
  obj[field.name] = [];
166
166
  else if (field.type === "object")
167
- obj[field.name] = getInitialValues(field.fields);
167
+ obj[field.name] = getCustomInitialValues(field.fields);
168
168
  else if (field.type === "string")
169
169
  obj[field.name] = "";
170
170
  else if (field.type === "number")
@@ -174,6 +174,25 @@ function getInitialValues(fields) {
174
174
  });
175
175
  return obj;
176
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
+ }
177
196
  function setOptions(fields) {
178
197
  return __awaiter(this, void 0, void 0, function () {
179
198
  var promises;
@@ -223,16 +242,29 @@ function GenericForm(_a) {
223
242
  var _this = this;
224
243
  var action = _a.action, onClose = _a.onClose, rowId = _a.rowId;
225
244
  var _b = (0, react_2.useState)(parseFields(action.fields)), formFields = _b[0], setFormFields = _b[1];
226
- var initialValues = (0, react_2.useState)(getInitialValues(action.fields))[0];
227
- var validationSchema = (0, react_2.useState)(parseValidation(action.fields))[0];
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];
228
247
  (0, react_2.useEffect)(function () {
229
248
  setOptions(action.fields).then(function () {
230
249
  setFormFields(parseFields(action.fields));
231
250
  });
232
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
+ }); };
233
265
  if (!action.fields)
234
266
  return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {});
235
- return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(formik_1.Formik, { initialValues: initialValues, validationSchema: Yup.object(validationSchema), onSubmit: function (values) { return __awaiter(_this, void 0, void 0, function () {
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 () {
236
268
  var res, e_1, err;
237
269
  return __generator(this, function (_a) {
238
270
  switch (_a.label) {
@@ -267,7 +299,7 @@ function GenericForm(_a) {
267
299
  });
268
300
  }); }, children: function (_a) {
269
301
  var isSubmitting = _a.isSubmitting;
270
- 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" })] }));
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" })] }));
271
303
  } }) }));
272
304
  }
273
305
  exports.GenericForm = GenericForm;
@@ -111,10 +111,10 @@ function parseFields(fields, previous) {
111
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
112
  var value = undefined;
113
113
  if (formfield.element.type === "object") {
114
- value = getInitialValues(formfield.element.fields);
114
+ value = getCustomInitialValues(formfield.element.fields);
115
115
  }
116
116
  else {
117
- value = getInitialValues([formfield.element])[0];
117
+ value = getCustomInitialValues([formfield.element])[0];
118
118
  }
119
119
  push(value);
120
120
  }, children: ["Add ", fieldName] })] }));
@@ -126,7 +126,7 @@ function parseFields(fields, previous) {
126
126
  });
127
127
  return computedFields;
128
128
  }
129
- function getInitialValues(fields) {
129
+ function getCustomInitialValues(fields) {
130
130
  var obj = {};
131
131
  if (!fields) {
132
132
  return obj;
@@ -135,7 +135,7 @@ function getInitialValues(fields) {
135
135
  if (field.type === "array")
136
136
  obj[field.name] = [];
137
137
  else if (field.type === "object")
138
- obj[field.name] = getInitialValues(field.fields);
138
+ obj[field.name] = getCustomInitialValues(field.fields);
139
139
  else if (field.type === "string")
140
140
  obj[field.name] = "";
141
141
  else if (field.type === "number")
@@ -145,6 +145,25 @@ function getInitialValues(fields) {
145
145
  });
146
146
  return obj;
147
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
+ }
148
167
  function setOptions(fields) {
149
168
  return __awaiter(this, void 0, void 0, function () {
150
169
  var promises;
@@ -194,16 +213,29 @@ export function GenericForm(_a) {
194
213
  var _this = this;
195
214
  var action = _a.action, onClose = _a.onClose, rowId = _a.rowId;
196
215
  var _b = useState(parseFields(action.fields)), formFields = _b[0], setFormFields = _b[1];
197
- var initialValues = useState(getInitialValues(action.fields))[0];
198
- var validationSchema = useState(parseValidation(action.fields))[0];
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];
199
218
  useEffect(function () {
200
219
  setOptions(action.fields).then(function () {
201
220
  setFormFields(parseFields(action.fields));
202
221
  });
203
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
+ }); };
204
236
  if (!action.fields)
205
237
  return _jsx(_Fragment, {});
206
- return (_jsx(_Fragment, { children: _jsx(Formik, { initialValues: initialValues, validationSchema: Yup.object(validationSchema), onSubmit: function (values) { return __awaiter(_this, void 0, void 0, function () {
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 () {
207
239
  var res, e_1, err;
208
240
  return __generator(this, function (_a) {
209
241
  switch (_a.label) {
@@ -238,6 +270,6 @@ export function GenericForm(_a) {
238
270
  });
239
271
  }); }, children: function (_a) {
240
272
  var isSubmitting = _a.isSubmitting;
241
- return (_jsxs(Form, { children: [formFields, _jsx(Button, { mt: 4, colorScheme: "teal", isLoading: isSubmitting, type: "submit", children: "Submit" })] }));
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" })] }));
242
274
  } }) }));
243
275
  }
@@ -39,7 +39,31 @@ var domain = "http://localhost:3001";
39
39
  export var event = {
40
40
  name: "Events",
41
41
  actions: [],
42
- rowActions: [],
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
+ ],
43
67
  getRequest: function () { return __awaiter(void 0, void 0, void 0, function () {
44
68
  return __generator(this, function (_a) {
45
69
  // const res = await axios.get(domain + "/events");
@@ -45,7 +45,31 @@ var domain = "http://localhost:3001";
45
45
  exports.event = {
46
46
  name: "Events",
47
47
  actions: [],
48
- rowActions: [],
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
+ ],
49
73
  getRequest: function () { return __awaiter(void 0, void 0, void 0, function () {
50
74
  return __generator(this, function (_a) {
51
75
  // const res = await axios.get(domain + "/events");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "admin_lsac",
3
- "version": "1.2.7",
3
+ "version": "1.2.8",
4
4
  "description": "Generic Admin Panel created for storing events' data",
5
5
  "private": false,
6
6
  "dependencies": {
package/src/App.tsx CHANGED
@@ -54,7 +54,7 @@ interface Action {
54
54
  interface RowAction {
55
55
  name: string;
56
56
  fields?: FormField[];
57
- initialise?: (obj: any) => any;
57
+ initialise: (obj: any) => any;
58
58
  onSubmit: (obj1: any, obj2?: any) => Promise<any>;
59
59
  }
60
60
 
@@ -69,7 +69,6 @@ function generateSingleField(
69
69
  isInvalid={
70
70
  getIn(form.touched, fieldName) && getIn(form.errors, fieldName)
71
71
  }
72
- // paddingLeft={40 * countIndent(fieldName)}
73
72
  >
74
73
  <FormLabel marginTop={2}>{formfield.label}</FormLabel>
75
74
 
@@ -169,9 +168,9 @@ function parseFields(
169
168
  let value = undefined;
170
169
 
171
170
  if (formfield.element.type === "object") {
172
- value = getInitialValues(formfield.element.fields);
171
+ value = getCustomInitialValues(formfield.element.fields);
173
172
  } else {
174
- value = getInitialValues([formfield.element])[0];
173
+ value = getCustomInitialValues([formfield.element])[0];
175
174
  }
176
175
 
177
176
  push(value);
@@ -191,7 +190,7 @@ function parseFields(
191
190
  return computedFields;
192
191
  }
193
192
 
194
- function getInitialValues(fields: FormField[] | undefined) {
193
+ function getCustomInitialValues(fields: FormField[] | undefined) {
195
194
  let obj: any = {};
196
195
 
197
196
  if (!fields) {
@@ -201,7 +200,7 @@ function getInitialValues(fields: FormField[] | undefined) {
201
200
  fields.forEach((field) => {
202
201
  if (field.type === "array") obj[field.name] = [];
203
202
  else if (field.type === "object")
204
- obj[field.name] = getInitialValues(field.fields);
203
+ obj[field.name] = getCustomInitialValues(field.fields);
205
204
  else if (field.type === "string") obj[field.name] = "";
206
205
  else if (field.type === "number") obj[field.name] = 0;
207
206
  else obj[field.name] = null;
@@ -210,6 +209,15 @@ function getInitialValues(fields: FormField[] | undefined) {
210
209
  return obj;
211
210
  }
212
211
 
212
+ async function getInitialValues(action: Action | RowAction, rowId: number | undefined) {
213
+ let obj: any = {};
214
+ if ((action as RowAction).initialise) {
215
+ obj = await (action as RowAction).initialise(rowId);
216
+ }
217
+ const customInitialValues = getCustomInitialValues(action.fields);
218
+ return Object.assign({}, customInitialValues, obj);
219
+ }
220
+
213
221
  async function setOptions(fields: FormField[] | undefined) {
214
222
  if (!fields) {
215
223
  return;
@@ -228,8 +236,8 @@ export function GenericForm({ action, onClose, rowId }: GenericFormProps) {
228
236
  const [formFields, setFormFields] = useState<any[]>(
229
237
  parseFields(action.fields)
230
238
  );
231
- const [initialValues] = useState<any>(getInitialValues(action.fields));
232
- const [validationSchema] = useState<any>(parseValidation(action.fields));
239
+ const [initialValues, setInitialValues] = useState<any>(getCustomInitialValues(action.fields));
240
+ const [validationSchema, setValidationSchema] = useState<any>(parseValidation(action.fields));
233
241
 
234
242
  useEffect(() => {
235
243
  setOptions(action.fields).then(() => {
@@ -237,12 +245,20 @@ export function GenericForm({ action, onClose, rowId }: GenericFormProps) {
237
245
  });
238
246
  }, []);
239
247
 
248
+ const handleFormReset = async () => {
249
+ const newInitialValues = await getInitialValues(action, rowId);
250
+ console.log(newInitialValues)
251
+ setInitialValues(newInitialValues);
252
+ };
253
+
240
254
  if (!action.fields) return <></>;
241
255
  return (
242
256
  <>
243
257
  <Formik
258
+ enableReinitialize={true}
244
259
  initialValues={initialValues}
245
260
  validationSchema={Yup.object(validationSchema)}
261
+ onReset={handleFormReset}
246
262
  onSubmit={async (values) => {
247
263
  try {
248
264
  let res;
@@ -273,6 +289,13 @@ export function GenericForm({ action, onClose, rowId }: GenericFormProps) {
273
289
  >
274
290
  Submit
275
291
  </Button>
292
+ <Button
293
+ mt={4}
294
+ colorScheme="teal"
295
+ type="reset"
296
+ >
297
+ Initialise Form
298
+ </Button>
276
299
  </Form>
277
300
  )}
278
301
  </Formik>
@@ -7,7 +7,31 @@ const domain = "http://localhost:3001";
7
7
  export const event: PageSchema = {
8
8
  name: "Events",
9
9
  actions: [],
10
- rowActions: [],
10
+ rowActions: [
11
+ // {
12
+ // name: "Delete Event",
13
+ // fields: [
14
+ // {
15
+ // name: "input",
16
+ // label: "Mock Field",
17
+ // type: "string",
18
+ // validationSchema: "",
19
+ // },
20
+ // ],
21
+ // initialise: async (eventId: number) => {
22
+ // const res = await axios.get(domain + "/events/" + eventId);
23
+ // let obj: any = {};
24
+ // obj.input = res.data.name;
25
+ // return obj;
26
+ // },
27
+ // onSubmit: async (formValues: any, eventId: number) => {
28
+ // const res = await axios.delete(
29
+ // domain + "/events/" + eventId
30
+ // );
31
+ // return res.data;
32
+ // },
33
+ // }
34
+ ],
11
35
  getRequest: async () => {
12
36
  // const res = await axios.get(domain + "/events");
13
37
  // return res.data;
@@ -50,7 +50,7 @@ export interface Action {
50
50
  export interface RowAction {
51
51
  name: string;
52
52
  fields?: FormField[];
53
- initialise?: (obj: any) => any;
53
+ initialise: (obj: any) => any;
54
54
  onSubmit: (obj1: any, obj2?: any) => Promise<any>;
55
55
  }
56
56
 
@@ -58,7 +58,6 @@ export interface PageSchema {
58
58
  name: string;
59
59
  actions: Action[];
60
60
  rowActions: RowAction[];
61
-
62
61
  getRequest: () => Promise<any[]>;
63
62
  tableFields: TableField[];
64
63
  }