Skip to content

Commit a1c8a88

Browse files
committed
Fix custom API base validation in Config component
1 parent a49c00a commit a1c8a88

2 files changed

Lines changed: 14 additions & 18 deletions

File tree

src/views/pages/Config.tsx

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ const Config = function () {
9797
api_base: (value) =>
9898
value.length > 0 ? null : "Please enter api base",
9999
cumstom_api_base: (value, values) =>
100-
values.providers.devchat.api_base === "custom" && value.length > 0
101-
? null
102-
: "Please enter custom api base",
100+
values.providers.devchat.api_base === "custom" && value.length <= 0
101+
? "Please enter custom api base"
102+
: null,
103103
},
104104
},
105105
},
@@ -127,16 +127,6 @@ const Config = function () {
127127
useEffect(() => {
128128
if (router.currentRoute !== "config") return;
129129
const cloneConfig = cloneDeep(config.config);
130-
if (
131-
cloneConfig?.providers?.devchat?.api_base !== apiSelection[0].value ||
132-
cloneConfig?.providers?.devchat?.api_base !== apiSelection[1].value
133-
) {
134-
cloneConfig.providers.devchat.api_base = "custom";
135-
}
136-
console.log(
137-
"cloneConfig.providers.devchat.api_base: ",
138-
cloneConfig.providers.devchat.api_base
139-
);
140130
form.setValues(cloneConfig);
141131
if (config.settle && loading) {
142132
setTimeout(() => {
@@ -149,12 +139,15 @@ const Config = function () {
149139
const onSave = (values) => {
150140
config.updateSettle(false);
151141
startLoading();
152-
const writeConfig = cloneDeep(self.config);
153-
if (writeConfig.providers.devchat.cumstom_api_base) {
142+
const writeConfig = cloneDeep(values);
143+
if (
144+
writeConfig.providers.devchat.api_base === "custom" &&
145+
writeConfig.providers.devchat.cumstom_api_base
146+
) {
154147
writeConfig.providers.devchat.api_base =
155148
writeConfig.providers.devchat.cumstom_api_base;
156-
delete writeConfig.providers.devchat.cumstom_api_base;
157149
}
150+
delete writeConfig.providers.devchat.cumstom_api_base;
158151
MessageUtil.sendMessage({
159152
command: "writeConfig",
160153
value: writeConfig,

src/views/stores/ConfigStore.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,14 @@ export const ConfigStore = types
110110
self.config = cloneConfig;
111111

112112
const writeConfig = cloneDeep(self.config);
113-
if (writeConfig.providers.devchat.cumstom_api_base) {
113+
if (
114+
writeConfig.providers.devchat.api_base === "custom" &&
115+
writeConfig.providers.devchat.cumstom_api_base
116+
) {
114117
writeConfig.providers.devchat.api_base =
115118
writeConfig.providers.devchat.cumstom_api_base;
116-
delete writeConfig.providers.devchat.cumstom_api_base;
117119
}
120+
delete writeConfig.providers.devchat.cumstom_api_base;
118121

119122
MessageUtil.sendMessage({
120123
command: "writeConfig",

0 commit comments

Comments
 (0)