mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-22 04:16:07 +00:00
feat: open bot edit dialog after creating
This commit is contained in:
@@ -61,11 +61,13 @@ export default function BotForm({
|
|||||||
onFormSubmit,
|
onFormSubmit,
|
||||||
onFormCancel,
|
onFormCancel,
|
||||||
onBotDeleted,
|
onBotDeleted,
|
||||||
|
onNewBotCreated,
|
||||||
}: {
|
}: {
|
||||||
initBotId?: string;
|
initBotId?: string;
|
||||||
onFormSubmit: (value: z.infer<typeof formSchema>) => void;
|
onFormSubmit: (value: z.infer<typeof formSchema>) => void;
|
||||||
onFormCancel: () => void;
|
onFormCancel: () => void;
|
||||||
onBotDeleted: () => void;
|
onBotDeleted: () => void;
|
||||||
|
onNewBotCreated: (botId: string) => void;
|
||||||
}) {
|
}) {
|
||||||
const form = useForm<z.infer<typeof formSchema>>({
|
const form = useForm<z.infer<typeof formSchema>>({
|
||||||
resolver: zodResolver(formSchema),
|
resolver: zodResolver(formSchema),
|
||||||
@@ -106,6 +108,11 @@ export default function BotForm({
|
|||||||
const [, setIsLoading] = useState<boolean>(false);
|
const [, setIsLoading] = useState<boolean>(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
setBotFormValues();
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
function setBotFormValues() {
|
||||||
initBotFormComponent().then(() => {
|
initBotFormComponent().then(() => {
|
||||||
// 拉取初始化表单信息
|
// 拉取初始化表单信息
|
||||||
if (initBotId) {
|
if (initBotId) {
|
||||||
@@ -128,8 +135,8 @@ export default function BotForm({
|
|||||||
form.reset();
|
form.reset();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
}
|
||||||
}, []);
|
|
||||||
async function initBotFormComponent() {
|
async function initBotFormComponent() {
|
||||||
// 初始化流水线列表
|
// 初始化流水线列表
|
||||||
const pipelinesRes = await httpClient.getPipelines();
|
const pipelinesRes = await httpClient.getPipelines();
|
||||||
@@ -281,9 +288,13 @@ export default function BotForm({
|
|||||||
httpClient
|
httpClient
|
||||||
.createBot(newBot)
|
.createBot(newBot)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log(res);
|
console.log('create bot success', res);
|
||||||
onFormSubmit(form.getValues());
|
toast.success('创建成功 请启用或修改绑定流水线');
|
||||||
toast.success('创建成功');
|
initBotId = res.uuid;
|
||||||
|
|
||||||
|
setBotFormValues();
|
||||||
|
|
||||||
|
onNewBotCreated(res.uuid);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
toast.error('创建失败:' + err.message);
|
toast.error('创建失败:' + err.message);
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export default function BotConfigPage() {
|
|||||||
const [modalOpen, setModalOpen] = useState<boolean>(false);
|
const [modalOpen, setModalOpen] = useState<boolean>(false);
|
||||||
const [botList, setBotList] = useState<BotCardVO[]>([]);
|
const [botList, setBotList] = useState<BotCardVO[]>([]);
|
||||||
const [isEditForm, setIsEditForm] = useState(false);
|
const [isEditForm, setIsEditForm] = useState(false);
|
||||||
const [nowSelectedBotCard, setNowSelectedBotCard] = useState<BotCardVO>();
|
const [nowSelectedBotUUID, setNowSelectedBotUUID] = useState<string>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getBotList();
|
getBotList();
|
||||||
@@ -62,18 +62,13 @@ export default function BotConfigPage() {
|
|||||||
|
|
||||||
function handleCreateBotClick() {
|
function handleCreateBotClick() {
|
||||||
setIsEditForm(false);
|
setIsEditForm(false);
|
||||||
setNowSelectedCard(undefined);
|
setNowSelectedBotUUID('');
|
||||||
setModalOpen(true);
|
setModalOpen(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setNowSelectedCard(cardVO: BotCardVO | undefined) {
|
function selectBot(botUUID: string) {
|
||||||
setNowSelectedBotCard(cardVO);
|
setNowSelectedBotUUID(botUUID);
|
||||||
}
|
|
||||||
|
|
||||||
function selectBot(cardVO: BotCardVO) {
|
|
||||||
setIsEditForm(true);
|
setIsEditForm(true);
|
||||||
setNowSelectedCard(cardVO);
|
|
||||||
console.log('set now vo', cardVO);
|
|
||||||
setModalOpen(true);
|
setModalOpen(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +83,7 @@ export default function BotConfigPage() {
|
|||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<div className="flex-1 overflow-y-auto px-6">
|
<div className="flex-1 overflow-y-auto px-6">
|
||||||
<BotForm
|
<BotForm
|
||||||
initBotId={nowSelectedBotCard?.id}
|
initBotId={nowSelectedBotUUID}
|
||||||
onFormSubmit={() => {
|
onFormSubmit={() => {
|
||||||
getBotList();
|
getBotList();
|
||||||
setModalOpen(false);
|
setModalOpen(false);
|
||||||
@@ -98,6 +93,11 @@ export default function BotConfigPage() {
|
|||||||
getBotList();
|
getBotList();
|
||||||
setModalOpen(false);
|
setModalOpen(false);
|
||||||
}}
|
}}
|
||||||
|
onNewBotCreated={(botId) => {
|
||||||
|
console.log('new bot created', botId);
|
||||||
|
getBotList();
|
||||||
|
selectBot(botId);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
@@ -116,7 +116,7 @@ export default function BotConfigPage() {
|
|||||||
<div
|
<div
|
||||||
key={cardVO.id}
|
key={cardVO.id}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
selectBot(cardVO);
|
selectBot(cardVO.id);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<BotCard botCardVO={cardVO} />
|
<BotCard botCardVO={cardVO} />
|
||||||
|
|||||||
@@ -328,7 +328,7 @@ class HttpClient {
|
|||||||
return this.get(`/api/v1/platform/bots/${uuid}`);
|
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);
|
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("https://version-4.langbot.dev");
|
||||||
// export const httpClient = new HttpClient('http://localhost:5300');
|
export const httpClient = new HttpClient('http://localhost:5300');
|
||||||
export const httpClient = new HttpClient('/');
|
// export const httpClient = new HttpClient('/');
|
||||||
|
|
||||||
// 临时写法,未来两种Client都继承自HttpClient父类,不允许共享方法
|
// 临时写法,未来两种Client都继承自HttpClient父类,不允许共享方法
|
||||||
export const spaceClient = new HttpClient('https://space.langbot.app');
|
export const spaceClient = new HttpClient('https://space.langbot.app');
|
||||||
|
|||||||
Reference in New Issue
Block a user