MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / onSubmit

Function onSubmit

web/src/pages/Setting/Dashboard/SettingsDataDashboard.js:29–62  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

27 const [inputsRow, setInputsRow] = useState(inputs);
28
29 function onSubmit() {
30 const updateArray = compareObjects(inputs, inputsRow);
31 if (!updateArray.length) return showWarning(t('你似乎并没有修改什么'));
32 const requestQueue = updateArray.map((item) => {
33 let value = '';
34 if (typeof inputs[item.key] === 'boolean') {
35 value = String(inputs[item.key]);
36 } else {
37 value = inputs[item.key];
38 }
39 return API.put('/api/option/', {
40 key: item.key,
41 value,
42 });
43 });
44 setLoading(true);
45 Promise.all(requestQueue)
46 .then((res) => {
47 if (requestQueue.length === 1) {
48 if (res.includes(undefined)) return;
49 } else if (requestQueue.length > 1) {
50 if (res.includes(undefined))
51 return showError(t('部分保存失败,请重试'));
52 }
53 showSuccess(t('保存成功'));
54 props.refresh();
55 })
56 .catch(() => {
57 showError(t('保存失败,请重试'));
58 })
59 .finally(() => {
60 setLoading(false);
61 });
62 }
63
64 useEffect(() => {
65 const currentInputs = {};

Callers

nothing calls this directly

Calls 5

compareObjectsFunction · 0.90
showWarningFunction · 0.90
showErrorFunction · 0.90
showSuccessFunction · 0.90
tFunction · 0.50

Tested by

no test coverage detected