mirror of
https://git.boos.lat/aibo/BossChat.git
synced 2026-10-30 15:16:11 +00:00
fix: agent profile save button not working
- Replace form attribute with ref-based form submission to avoid potential portal-related form resolution issues in base-ui Dialog - Add null guard for fetchUsersAll return value to prevent crash when API returns null data
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { CheckIcon, ChevronsUpDownIcon } from "lucide-react";
|
import { CheckIcon, ChevronsUpDownIcon } from "lucide-react";
|
||||||
import { useCallback, useEffect, useState } from "react";
|
import { useCallback, useEffect, useRef, useState } from "react";
|
||||||
import { Controller, Resolver, useForm } from "react-hook-form";
|
import { Controller, Resolver, useForm } from "react-hook-form";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { z } from "zod/v4";
|
import { z } from "zod/v4";
|
||||||
@@ -206,7 +206,7 @@ function AgentEditDialogBody({
|
|||||||
const [users, setUsers] = useState<AdminUser[]>([]);
|
const [users, setUsers] = useState<AdminUser[]>([]);
|
||||||
const [userSelectOpen, setUserSelectOpen] = useState(false);
|
const [userSelectOpen, setUserSelectOpen] = useState(false);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const userOptions = users.map((user) => ({
|
const userOptions = (Array.isArray(users) ? users : []).map((user) => ({
|
||||||
value: String(user.id),
|
value: String(user.id),
|
||||||
label: `${user.nickname || user.username} (${user.username})`,
|
label: `${user.nickname || user.username} (${user.username})`,
|
||||||
}));
|
}));
|
||||||
@@ -215,7 +215,7 @@ function AgentEditDialogBody({
|
|||||||
const [usersData] = await Promise.all([
|
const [usersData] = await Promise.all([
|
||||||
fetchUsersAll(),
|
fetchUsersAll(),
|
||||||
]);
|
]);
|
||||||
setUsers(usersData);
|
setUsers(Array.isArray(usersData) ? usersData : []);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast.error(error instanceof Error ? error.message : "加载选项失败");
|
toast.error(error instanceof Error ? error.message : "加载选项失败");
|
||||||
}
|
}
|
||||||
@@ -228,6 +228,7 @@ function AgentEditDialogBody({
|
|||||||
resolver: editFormResolver,
|
resolver: editFormResolver,
|
||||||
defaultValues: buildFormWithDefaultTeam(null, defaultTeamId),
|
defaultValues: buildFormWithDefaultTeam(null, defaultTeamId),
|
||||||
});
|
});
|
||||||
|
const formRef = useRef<HTMLFormElement>(null);
|
||||||
const {
|
const {
|
||||||
control,
|
control,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
@@ -265,8 +266,6 @@ function AgentEditDialogBody({
|
|||||||
await onSubmit(buildPayload(values));
|
await onSubmit(buildPayload(values));
|
||||||
}
|
}
|
||||||
|
|
||||||
const formId = "agent-edit-form";
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ProjectDialog
|
<ProjectDialog
|
||||||
open={open}
|
open={open}
|
||||||
@@ -283,7 +282,11 @@ function AgentEditDialogBody({
|
|||||||
>
|
>
|
||||||
取消
|
取消
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="submit" form={formId} disabled={saving || loading}>
|
<Button
|
||||||
|
type="button"
|
||||||
|
onClick={() => formRef.current?.requestSubmit()}
|
||||||
|
disabled={saving || loading}
|
||||||
|
>
|
||||||
{saving ? "保存中..." : "保存"}
|
{saving ? "保存中..." : "保存"}
|
||||||
</Button>
|
</Button>
|
||||||
</>
|
</>
|
||||||
@@ -295,7 +298,7 @@ function AgentEditDialogBody({
|
|||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<form
|
<form
|
||||||
id={formId}
|
ref={formRef}
|
||||||
onSubmit={handleSubmit(onFormSubmit)}
|
onSubmit={handleSubmit(onFormSubmit)}
|
||||||
className="space-y-4"
|
className="space-y-4"
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user