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

Function onSubmit

web/src/pages/Setting/Model/SettingGeminiModel.js:37–73  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

35 const [inputsRow, setInputsRow] = useState(inputs);
36
37 async function onSubmit() {
38 await refForm.current
39 .validate()
40 .then(() => {
41 const updateArray = compareObjects(inputs, inputsRow);
42 if (!updateArray.length) return showWarning(t('你似乎并没有修改什么'));
43 const requestQueue = updateArray.map((item) => {
44 let value = String(inputs[item.key]);
45 return API.put('/api/option/', {
46 key: item.key,
47 value,
48 });
49 });
50 setLoading(true);
51 Promise.all(requestQueue)
52 .then((res) => {
53 if (requestQueue.length === 1) {
54 if (res.includes(undefined)) return;
55 } else if (requestQueue.length > 1) {
56 if (res.includes(undefined))
57 return showError(t('部分保存失败,请重试'));
58 }
59 showSuccess(t('保存成功'));
60 props.refresh();
61 })
62 .catch(() => {
63 showError(t('保存失败,请重试'));
64 })
65 .finally(() => {
66 setLoading(false);
67 });
68 })
69 .catch((error) => {
70 console.error('Validation failed:', error);
71 showError(t('请检查输入'));
72 });
73 }
74
75 useEffect(() => {
76 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