fix: dialog state

This commit is contained in:
Johnny 2025-07-17 21:58:00 +08:00
parent 6119a4b965
commit f09897e4b6
4 changed files with 24 additions and 8 deletions

View file

@ -1,4 +1,4 @@
import { useEffect, useState } from "react";
import { useState } from "react";
import { toast } from "react-hot-toast";
import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
@ -20,10 +20,6 @@ function ChangeMemberPasswordDialog({ open, onOpenChange, user, onSuccess }: Pro
const [newPassword, setNewPassword] = useState("");
const [newPasswordAgain, setNewPasswordAgain] = useState("");
useEffect(() => {
// do nth
}, []);
const handleCloseBtnClick = () => {
onOpenChange(false);
};

View file

@ -142,7 +142,7 @@ function CreateIdentityProviderDialog({ open, onOpenChange, identityProvider, on
setOAuth2Scopes(oauth2Config.scopes.join(" "));
}
}
}, []);
}, [identityProvider]);
useEffect(() => {
if (!isCreating) {

View file

@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useEffect, useState } from "react";
import { toast } from "react-hot-toast";
import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
@ -30,6 +30,18 @@ function CreateShortcutDialog({ open, onOpenChange, shortcut: initialShortcut, o
const requestState = useLoading(false);
const isCreating = !initialShortcut;
useEffect(() => {
if (initialShortcut) {
setShortcut({
name: initialShortcut.name,
title: initialShortcut.title,
filter: initialShortcut.filter,
});
} else {
setShortcut({ name: "", title: "", filter: "" });
}
}, [initialShortcut]);
const onShortcutTitleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setShortcut({ ...shortcut, title: e.target.value });
};

View file

@ -1,4 +1,4 @@
import { useState } from "react";
import { useEffect, useState } from "react";
import { toast } from "react-hot-toast";
import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
@ -23,6 +23,14 @@ function CreateUserDialog({ open, onOpenChange, user: initialUser, onSuccess }:
const requestState = useLoading(false);
const isCreating = !initialUser;
useEffect(() => {
if (initialUser) {
setUser(User.fromPartial(initialUser));
} else {
setUser(User.fromPartial({}));
}
}, [initialUser]);
const setPartialUser = (state: Partial<User>) => {
setUser({
...user,