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

Function onSubmit

web/src/pages/Setting/Operation/SettingsCreditLimit.js:24–57  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

compareObjectsFunction · 0.90
showWarningFunction · 0.90
showErrorFunction · 0.90
showSuccessFunction · 0.90
tFunction · 0.70

Tested by

no test coverage detected