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

Function onSubmit

web/src/pages/Setting/Operation/SettingsLog.js:24–60  ·  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).filter(
26 (item) => item.key !== 'historyTimestamp',
27 );
28
29 if (!updateArray.length) return showWarning(t('你似乎并没有修改什么'));
30 const requestQueue = updateArray.map((item) => {
31 let value = '';
32 if (typeof inputs[item.key] === 'boolean') {
33 value = String(inputs[item.key]);
34 } else {
35 value = inputs[item.key];
36 }
37 return API.put('/api/option/', {
38 key: item.key,
39 value,
40 });
41 });
42 setLoading(true);
43 Promise.all(requestQueue)
44 .then((res) => {
45 if (requestQueue.length === 1) {
46 if (res.includes(undefined)) return;
47 } else if (requestQueue.length > 1) {
48 if (res.includes(undefined))
49 return showError(t('部分保存失败,请重试'));
50 }
51 showSuccess(t('保存成功'));
52 props.refresh();
53 })
54 .catch(() => {
55 showError(t('保存失败,请重试'));
56 })
57 .finally(() => {
58 setLoading(false);
59 });
60 }
61 async function onCleanHistoryLog() {
62 try {
63 setLoadingCleanHistoryLog(true);

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