mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-02 03:55:55 +00:00
fix(botForm): default value not set to adapter_config while creating bot
This commit is contained in:
@@ -3,6 +3,7 @@ import { IChooseAdapterEntity } from '@/app/home/bots/components/bot-form/Choose
|
||||
import {
|
||||
DynamicFormItemConfig,
|
||||
IDynamicFormItemConfig,
|
||||
getDefaultValues,
|
||||
parseDynamicFormItemType,
|
||||
} from '@/app/home/components/dynamic-form/DynamicFormItemConfig';
|
||||
import { UUID } from 'uuidjs';
|
||||
@@ -182,6 +183,9 @@ export default function BotForm({
|
||||
console.log(dynamicFormConfigList);
|
||||
if (dynamicFormConfigList) {
|
||||
setDynamicFormConfigList(dynamicFormConfigList);
|
||||
if (!initBotId) {
|
||||
form.setValue('adapter_config', getDefaultValues(dynamicFormConfigList));
|
||||
}
|
||||
}
|
||||
setShowDynamicForm(true);
|
||||
} else {
|
||||
@@ -209,7 +213,7 @@ export default function BotForm({
|
||||
name: form.getValues().name,
|
||||
description: form.getValues().description,
|
||||
adapter: form.getValues().adapter,
|
||||
adapter_config: value,
|
||||
adapter_config: form.getValues().adapter_config,
|
||||
};
|
||||
httpClient
|
||||
.updateBot(initBotId, updateBot)
|
||||
@@ -241,7 +245,7 @@ export default function BotForm({
|
||||
name: form.getValues().name,
|
||||
description: form.getValues().description,
|
||||
adapter: form.getValues().adapter,
|
||||
adapter_config: value,
|
||||
adapter_config: form.getValues().adapter_config,
|
||||
};
|
||||
httpClient
|
||||
.createBot(newBot)
|
||||
|
||||
@@ -54,3 +54,10 @@ export function isDynamicFormItemType(
|
||||
export function parseDynamicFormItemType(value: string): DynamicFormItemType {
|
||||
return isDynamicFormItemType(value) ? value : DynamicFormItemType.UNKNOWN;
|
||||
}
|
||||
|
||||
export function getDefaultValues(itemConfigList: IDynamicFormItemConfig[]): Record<string, any> {
|
||||
return itemConfigList.reduce((acc, item) => {
|
||||
acc[item.name] = item.default;
|
||||
return acc;
|
||||
}, {} as Record<string, any>);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user