mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-16 13:57:02 +08:00
fix(admin): user form not dynamically updating as expected (#7858)
- Fixed the issue that a certain feature must be enabled when creating a user - Fixed the issue that the modified content was not reset to the default content when exiting the user form without saving after modification - Fixed the issue that the content did not switch as expected when switching user forms of different users https://github.com/user-attachments/assets/02567021-9342-4ed1-be77-3bdcbb3d86ab
This commit is contained in:
@@ -31,9 +31,16 @@ function UserForm({
|
|||||||
}: UserFormProps) {
|
}: UserFormProps) {
|
||||||
const serverConfig = useServerConfig();
|
const serverConfig = useServerConfig();
|
||||||
|
|
||||||
const [changes, setChanges] = useState<Partial<UserInput>>({
|
const defaultUser: Partial<UserInput> = useMemo(
|
||||||
features: defaultValue?.features ?? [],
|
() => ({
|
||||||
});
|
name: defaultValue?.name ?? '',
|
||||||
|
email: defaultValue?.email ?? '',
|
||||||
|
features: defaultValue?.features ?? [],
|
||||||
|
}),
|
||||||
|
[defaultValue?.email, defaultValue?.features, defaultValue?.name]
|
||||||
|
);
|
||||||
|
|
||||||
|
const [changes, setChanges] = useState<Partial<UserInput>>(defaultUser);
|
||||||
|
|
||||||
const setField = useCallback(
|
const setField = useCallback(
|
||||||
<K extends keyof UserInput>(
|
<K extends keyof UserInput>(
|
||||||
@@ -74,6 +81,15 @@ function UserForm({
|
|||||||
[setField]
|
[setField]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleClose = useCallback(() => {
|
||||||
|
setChanges(defaultUser);
|
||||||
|
onClose();
|
||||||
|
}, [defaultUser, onClose]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setChanges(defaultUser);
|
||||||
|
}, [defaultUser]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col h-full gap-1">
|
<div className="flex flex-col h-full gap-1">
|
||||||
<div className=" flex justify-between items-center py-[10px] px-6">
|
<div className=" flex justify-between items-center py-[10px] px-6">
|
||||||
@@ -82,7 +98,7 @@ function UserForm({
|
|||||||
size="icon"
|
size="icon"
|
||||||
className="w-7 h-7"
|
className="w-7 h-7"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
onClick={onClose}
|
onClick={handleClose}
|
||||||
>
|
>
|
||||||
<XIcon size={20} />
|
<XIcon size={20} />
|
||||||
</Button>
|
</Button>
|
||||||
@@ -104,14 +120,14 @@ function UserForm({
|
|||||||
<InputItem
|
<InputItem
|
||||||
label="Name"
|
label="Name"
|
||||||
field="name"
|
field="name"
|
||||||
value={changes.name ?? defaultValue?.name}
|
value={changes.name}
|
||||||
onChange={setField}
|
onChange={setField}
|
||||||
/>
|
/>
|
||||||
<Separator />
|
<Separator />
|
||||||
<InputItem
|
<InputItem
|
||||||
label="Email"
|
label="Email"
|
||||||
field="email"
|
field="email"
|
||||||
value={changes.email ?? defaultValue?.email}
|
value={changes.email}
|
||||||
onChange={setField}
|
onChange={setField}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -121,11 +137,7 @@ function UserForm({
|
|||||||
<div key={feature}>
|
<div key={feature}>
|
||||||
<ToggleItem
|
<ToggleItem
|
||||||
name={feature}
|
name={feature}
|
||||||
checked={(
|
checked={changes.features?.includes(feature) ?? false}
|
||||||
changes.features ??
|
|
||||||
defaultValue?.features ??
|
|
||||||
[]
|
|
||||||
).includes(feature)}
|
|
||||||
onChange={onFeatureChanged}
|
onChange={onFeatureChanged}
|
||||||
/>
|
/>
|
||||||
{i < serverConfig.availableUserFeatures.length - 1 && (
|
{i < serverConfig.availableUserFeatures.length - 1 && (
|
||||||
@@ -188,7 +200,7 @@ function InputItem({
|
|||||||
<Input
|
<Input
|
||||||
type="text"
|
type="text"
|
||||||
className="py-2 px-3 text-base font-normal"
|
className="py-2 px-3 text-base font-normal"
|
||||||
defaultValue={value}
|
value={value}
|
||||||
onChange={onValueChange}
|
onChange={onValueChange}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user