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

Function onSubmit

web/src/pages/Setting/Operation/SettingsSensitiveWords.js:23–56  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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