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

Function onSubmit

web/src/pages/Setting/Model/SettingGlobalModel.js:25–54  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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