[chore/frogend] Restructure form data default values / update from Query data (#1422)

* eslint: set console use to error to catch debug littering in CI

* remove debug logging

* some form field restructuring, fixes submitted updates not being reflected

* more form field restructuring

* remove debug logger

* simplify field updates

* fix react state set during render when submitting import file

* className instead of class

* show Select hints again
This commit is contained in:
f0x52
2023-02-06 09:19:56 +01:00
committed by GitHub
parent 0a9874329d
commit 47daddc10c
19 changed files with 153 additions and 86 deletions

View File

@ -18,7 +18,6 @@
"use strict";
const Promise = require("bluebird");
const React = require("react");
const syncpipe = require("syncpipe");
@ -27,7 +26,7 @@ module.exports = function useFormSubmit(form, mutationQuery, { changedOnly = tru
throw new ("useFormSubmit: mutationQuery was not an Array. Is a valid useMutation RTK Query provided?");
}
const [runMutation, result] = mutationQuery;
const [usedAction, setUsedAction] = React.useState();
const usedAction = React.useRef(null);
return [
function submitForm(e) {
let action;
@ -41,7 +40,7 @@ module.exports = function useFormSubmit(form, mutationQuery, { changedOnly = tru
if (action == "") {
action = undefined;
}
setUsedAction(action);
usedAction.current = action;
// transform the field definitions into an object with just their values
let updatedFields = [];
const mutationData = syncpipe(form, [
@ -65,19 +64,11 @@ module.exports = function useFormSubmit(form, mutationQuery, { changedOnly = tru
mutationData.action = action;
return Promise.try(() => {
return runMutation(mutationData);
}).then((res) => {
if (res.error == undefined) {
updatedFields.forEach((field) => {
field.reset();
});
}
});
return runMutation(mutationData);
},
{
...result,
action: usedAction
action: usedAction.current
}
];
};