feat: open bot edit dialog after creating

This commit is contained in:
Junyan Qin
2025-05-11 18:51:28 +08:00
parent 8da45b1ed8
commit 686002bf3a
3 changed files with 30 additions and 19 deletions

View File

@@ -61,11 +61,13 @@ export default function BotForm({
onFormSubmit,
onFormCancel,
onBotDeleted,
onNewBotCreated,
}: {
initBotId?: string;
onFormSubmit: (value: z.infer<typeof formSchema>) => void;
onFormCancel: () => void;
onBotDeleted: () => void;
onNewBotCreated: (botId: string) => void;
}) {
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
@@ -106,6 +108,11 @@ export default function BotForm({
const [, setIsLoading] = useState<boolean>(false);
useEffect(() => {
setBotFormValues();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
function setBotFormValues() {
initBotFormComponent().then(() => {
// 拉取初始化表单信息
if (initBotId) {
@@ -128,8 +135,8 @@ export default function BotForm({
form.reset();
}
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}
async function initBotFormComponent() {
// 初始化流水线列表
const pipelinesRes = await httpClient.getPipelines();
@@ -281,9 +288,13 @@ export default function BotForm({
httpClient
.createBot(newBot)
.then((res) => {
console.log(res);
onFormSubmit(form.getValues());
toast.success('创建成功');
console.log('create bot success', res);
toast.success('创建成功 请启用或修改绑定流水线');
initBotId = res.uuid;
setBotFormValues();
onNewBotCreated(res.uuid);
})
.catch((err) => {
toast.error('创建失败:' + err.message);

View File

@@ -19,7 +19,7 @@ export default function BotConfigPage() {
const [modalOpen, setModalOpen] = useState<boolean>(false);
const [botList, setBotList] = useState<BotCardVO[]>([]);
const [isEditForm, setIsEditForm] = useState(false);
const [nowSelectedBotCard, setNowSelectedBotCard] = useState<BotCardVO>();
const [nowSelectedBotUUID, setNowSelectedBotUUID] = useState<string>();
useEffect(() => {
getBotList();
@@ -62,18 +62,13 @@ export default function BotConfigPage() {
function handleCreateBotClick() {
setIsEditForm(false);
setNowSelectedCard(undefined);
setNowSelectedBotUUID('');
setModalOpen(true);
}
function setNowSelectedCard(cardVO: BotCardVO | undefined) {
setNowSelectedBotCard(cardVO);
}
function selectBot(cardVO: BotCardVO) {
function selectBot(botUUID: string) {
setNowSelectedBotUUID(botUUID);
setIsEditForm(true);
setNowSelectedCard(cardVO);
console.log('set now vo', cardVO);
setModalOpen(true);
}
@@ -88,7 +83,7 @@ export default function BotConfigPage() {
</DialogHeader>
<div className="flex-1 overflow-y-auto px-6">
<BotForm
initBotId={nowSelectedBotCard?.id}
initBotId={nowSelectedBotUUID}
onFormSubmit={() => {
getBotList();
setModalOpen(false);
@@ -98,6 +93,11 @@ export default function BotConfigPage() {
getBotList();
setModalOpen(false);
}}
onNewBotCreated={(botId) => {
console.log('new bot created', botId);
getBotList();
selectBot(botId);
}}
/>
</div>
</DialogContent>
@@ -116,7 +116,7 @@ export default function BotConfigPage() {
<div
key={cardVO.id}
onClick={() => {
selectBot(cardVO);
selectBot(cardVO.id);
}}
>
<BotCard botCardVO={cardVO} />

View File

@@ -328,7 +328,7 @@ class HttpClient {
return this.get(`/api/v1/platform/bots/${uuid}`);
}
public createBot(bot: Bot): Promise<object> {
public createBot(bot: Bot): Promise<{ uuid: string }> {
return this.post('/api/v1/platform/bots', bot);
}
@@ -445,8 +445,8 @@ class HttpClient {
}
// export const httpClient = new HttpClient("https://version-4.langbot.dev");
// export const httpClient = new HttpClient('http://localhost:5300');
export const httpClient = new HttpClient('/');
export const httpClient = new HttpClient('http://localhost:5300');
// export const httpClient = new HttpClient('/');
// 临时写法未来两种Client都继承自HttpClient父类不允许共享方法
export const spaceClient = new HttpClient('https://space.langbot.app');