diff --git a/src/hooks/useAuth.tsx b/src/hooks/useAuth.tsx index a7d9887..61571d9 100644 --- a/src/hooks/useAuth.tsx +++ b/src/hooks/useAuth.tsx @@ -38,6 +38,7 @@ type AuthContextType = { recoverPassword: (email: string) => Promise; changePassword: (password: string, mailToken: string) => Promise; getProfile: () => Promise; + deleteProfile: () => Promise; }; const AuthContext = createContext({} as AuthContextType); @@ -50,6 +51,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => { recoverPassword: authRecoverPassword, changePassword: authChangePassword, getProfile: authGetProfile, + deleteProfile: authDeleteProfile, } = useApi(); const localToken = @@ -149,6 +151,15 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => { }) return false; } + + async function deleteProfile(): Promise { + await authDeleteProfile(token); + toaster.create({ + title: 'Perfil deletado com sucesso!', + type: 'success', + }) + return true; + } function signOut(): void { typeof window !== 'undefined' @@ -169,6 +180,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => { recoverPassword, changePassword, getProfile, + deleteProfile, }} > {children} diff --git a/src/pages/Profile/DeleteProfileDialog/index.tsx b/src/pages/Profile/DeleteProfileDialog/index.tsx index 528e4f2..0dc9bc7 100644 --- a/src/pages/Profile/DeleteProfileDialog/index.tsx +++ b/src/pages/Profile/DeleteProfileDialog/index.tsx @@ -11,18 +11,15 @@ import { DialogCloseTrigger, } from "../../../components/ui/dialog" import { Button } from "../../../components/ui/button" -import useApi from "../../../hooks/useApi" import { useAuth } from "../../../hooks/useAuth" import { useNavigate } from "react-router" const DeleteProfileDialog = () => { const navigate = useNavigate(); - const { deleteProfile } = useApi(); - const { signOut, getProfile } = useAuth(); + const { signOut, deleteProfile } = useAuth(); const handleDelete = async () => { - const profile = await getProfile(); - await deleteProfile(profile.id); + await deleteProfile(); signOut(); navigate('/login'); }