mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-23 04:46:07 +00:00
fix: bug in plugin form
This commit is contained in:
@@ -26,7 +26,7 @@ export default function PluginForm({
|
|||||||
}) {
|
}) {
|
||||||
const [pluginInfo, setPluginInfo] = useState<Plugin>();
|
const [pluginInfo, setPluginInfo] = useState<Plugin>();
|
||||||
const [pluginConfig, setPluginConfig] = useState<ApiRespPluginConfig>();
|
const [pluginConfig, setPluginConfig] = useState<ApiRespPluginConfig>();
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isSaving, setIsLoading] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// 获取插件信息
|
// 获取插件信息
|
||||||
@@ -57,26 +57,42 @@ export default function PluginForm({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="space-y-4">
|
<div className="space-y-2">
|
||||||
<div className="text-lg font-medium">插件配置</div>
|
<div className="text-lg font-medium">{pluginInfo.name}</div>
|
||||||
<div className="text-sm text-gray-500">
|
<div className="text-sm text-gray-500 pb-2">
|
||||||
{pluginInfo.description.zh_CN}
|
{pluginInfo.description.zh_CN}
|
||||||
</div>
|
</div>
|
||||||
<DynamicFormComponent
|
{pluginInfo.config_schema.length > 0 && (
|
||||||
itemConfigList={pluginInfo.config_schema}
|
<DynamicFormComponent
|
||||||
initialValues={pluginConfig.config}
|
itemConfigList={pluginInfo.config_schema}
|
||||||
onSubmit={handleSubmit}
|
initialValues={pluginConfig.config}
|
||||||
/>
|
onSubmit={(values) => {
|
||||||
|
let config = pluginConfig.config;
|
||||||
|
config = {
|
||||||
|
...config,
|
||||||
|
...values,
|
||||||
|
};
|
||||||
|
setPluginConfig({
|
||||||
|
config: config,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{pluginInfo.config_schema.length === 0 && (
|
||||||
|
<div className="text-sm text-gray-500">
|
||||||
|
该插件没有配置项。
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="sticky bottom-0 left-0 right-0 bg-background border-t p-4 mt-4">
|
<div className="sticky bottom-0 left-0 right-0 bg-background border-t p-4 mt-4">
|
||||||
<div className="flex justify-end gap-2">
|
<div className="flex justify-end gap-2">
|
||||||
<Button
|
<Button
|
||||||
type="submit"
|
type="submit"
|
||||||
onClick={() => handleSubmit(pluginConfig.config)}
|
onClick={() => handleSubmit(pluginConfig.config)}
|
||||||
disabled={isLoading}
|
disabled={isSaving}
|
||||||
>
|
>
|
||||||
{isLoading ? '保存中...' : '保存配置'}
|
{isSaving ? '保存中...' : '保存配置'}
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="button" variant="outline" onClick={onFormCancel}>
|
<Button type="button" variant="outline" onClick={onFormCancel}>
|
||||||
取消
|
取消
|
||||||
|
|||||||
Reference in New Issue
Block a user