diff --git a/src/App.jsx b/src/App.jsx index cd6caadf..b15ae738 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -379,9 +379,18 @@ function App() { } }; - const handleGuestLogin = () => { + const handleGuestLogin = async ({ onSuccess, onFailure }) => { if (userRef.current) { - userRef.current.loginAsGuest(); + try { + await userRef.current.loginAsGuest(); + setIsLoginUserHidden(true); + setIsLoggingIn(false); + if (onSuccess) onSuccess(); + } catch (error) { + setIsLoginUserHidden(false); + setIsLoggingIn(false); + if (onFailure) onFailure(error); + } } } diff --git a/src/modals/CreateUserModal.jsx b/src/modals/CreateUserModal.jsx index c48a18cd..cb65a5aa 100644 --- a/src/modals/CreateUserModal.jsx +++ b/src/modals/CreateUserModal.jsx @@ -10,22 +10,31 @@ const CreateUserModal = ({ isHidden, form, setForm, handleCreateUser, setIsCreat const [confirmPassword, setConfirmPassword] = useState(''); const [showPassword, setShowPassword] = useState(false); const [showConfirmPassword, setShowConfirmPassword] = useState(false); + const [isLoading, setIsLoading] = useState(false); const isFormValid = () => { if (!form.username || !form.password || form.password !== confirmPassword) return false; return true; }; - const handleCreate = () => { - handleCreateUser({ - ...form - }); + const handleCreate = async () => { + setIsLoading(true); + try { + await handleCreateUser({ + ...form, + onSuccess: () => setIsLoading(false), + onFailure: () => setIsLoading(false) + }); + } catch (error) { + setIsLoading(false); + } }; useEffect(() => { if (isHidden) { setForm({ username: '', password: '' }); setConfirmPassword(''); + setIsLoading(false); } }, [isHidden]); @@ -54,18 +63,23 @@ const CreateUserModal = ({ isHidden, form, setForm, handleCreateUser, setIsCreat