diff --git a/app/components/ui/toast.tsx b/app/components/ui/toast.tsx index 9aaa1d7..f8f37c9 100644 --- a/app/components/ui/toast.tsx +++ b/app/components/ui/toast.tsx @@ -60,7 +60,7 @@ const ToastAction = React.forwardRef< - {toasts.map(({ id, title, description, action, cancelMutation, ...props }) => { - const undoButton = cancelMutation ? Undo : undefined - return ( - -
- {title && {title}} - {description && ( - {description} - )} -
- {action} - {undoButton} - -
- ) - })} + {toasts.map( + ({ id, title, description, action, cancelMutation, ...props }) => { + const undoButton = cancelMutation ? ( + + Undo + + ) : undefined; + return ( + +
+ {title && {title}} + {description && ( + {description} + )} +
+ {action} + {undoButton} + +
+ ); + }, + )} - ) + ); } diff --git a/app/routes/account.tsx b/app/routes/account.tsx index 9fdf752..8ccacc3 100644 --- a/app/routes/account.tsx +++ b/app/routes/account.tsx @@ -9,7 +9,7 @@ import { useUpdate, useUpdatePassword, } from "@refinedev/core"; -import { useMemo, useState } from "react"; +import { useEffect, useMemo, useState } from "react"; import { z } from "zod"; import { Field } from "~/components/forms"; import { GeneralLayout } from "~/components/general-layout"; @@ -53,21 +53,28 @@ export default function MyAccount() { changeAvatar: false, }); + const closeModal = () => { + setModal({ + changeEmail: false, + changePassword: false, + setupTwoFactor: false, + changeAvatar: false, + }); + }; + const isModalOpen = Object.values(openModal).some(isOpen => isOpen); + return ( - +

My Account

{ if (!open) { - setModal({ - changeEmail: false, - changePassword: false, - setupTwoFactor: false, - changeAvatar: false, - }); + closeModal(); } - }}> + }} + open={isModalOpen} + > - {openModal.changeAvatar && } + {openModal.changeAvatar && } {openModal.changeEmail && ( - + )} - {openModal.changePassword && } - {openModal.setupTwoFactor && } + {openModal.changePassword && } + {openModal.setupTwoFactor && }
@@ -243,9 +250,9 @@ const ChangeEmailSchema = z return true; }); -const ChangeEmailForm = ({ currentValue }: { currentValue: string }) => { +const ChangeEmailForm = ({ currentValue, close }: { currentValue: string, close: () => void }) => { const { data: identity } = useGetIdentity<{ id: BaseKey }>(); - const { mutate: updateEmail } = useUpdate(); + const { mutate: updateEmail, isSuccess } = useUpdate(); const [form, fields] = useForm({ id: "login", constraint: getZodConstraint(ChangeEmailSchema), @@ -269,6 +276,12 @@ const ChangeEmailForm = ({ currentValue }: { currentValue: string }) => { }, }); + useEffect(() => { + if (isSuccess) { + close(); + } + }, [isSuccess, close]); + return ( <> @@ -320,8 +333,8 @@ const ChangePasswordSchema = z return true; }); -const ChangePasswordForm = () => { - const { mutate: updatePassword } = +const ChangePasswordForm = ({ close }: { close: () => void }) => { + const { mutate: updatePassword, isSuccess } = useUpdatePassword(); const [form, fields] = useForm({ id: "login", @@ -342,6 +355,12 @@ const ChangePasswordForm = () => { }, }); + useEffect(() => { + if (isSuccess) { + close(); + } + }, [isSuccess, close]); + return ( <> @@ -375,7 +394,7 @@ const ChangePasswordForm = () => { ); }; -const SetupTwoFactorDialog = () => { +const SetupTwoFactorDialog = ({ close }: { close: () => void }) => { const [continueModal, setContinue] = useState(false); return ( @@ -414,7 +433,7 @@ const SetupTwoFactorDialog = () => { ); }; -const ChangeAvatarForm = () => { +const ChangeAvatarForm = ({ close }: { close: () => void }) => { const { getRootProps, getInputProps, @@ -424,9 +443,6 @@ const ChangeAvatarForm = () => { removeFile, cancelAll, } = useUppy(); - - console.log({ state, files: getFiles() }); - const isUploading = state === "uploading"; const isCompleted = state === "completed"; const hasStarted = state !== "idle" && state !== "initializing"; @@ -439,6 +455,12 @@ const ChangeAvatarForm = () => { } }, [file]); + useEffect(() => { + if (isCompleted) { + close(); + } + }, [isCompleted, close]); + return ( <> diff --git a/app/routes/dashboard.tsx b/app/routes/dashboard.tsx index 450d157..28cf40c 100644 --- a/app/routes/dashboard.tsx +++ b/app/routes/dashboard.tsx @@ -11,7 +11,7 @@ import { Authenticated } from "@refinedev/core"; export default function Dashboard() { return ( - +

Dashboard