From 0103af243c72ed232be2a1b44d1959420beede79 Mon Sep 17 00:00:00 2001 From: Egor Kolesnikov Date: Sun, 19 Nov 2023 19:52:34 +1000 Subject: [PATCH] feat: add logout in profile --- .../profile-components/profile-menu/index.tsx | 61 ++++++++++++++++--- .../profile-menu/profile-menu.module.scss | 39 ++++++++++++ src/contexts/auth-context.tsx | 13 +++- src/contexts/popup-context.tsx | 2 + src/services/api.ts | 30 +++++++-- 5 files changed, 129 insertions(+), 16 deletions(-) diff --git a/src/components/profile-components/profile-menu/index.tsx b/src/components/profile-components/profile-menu/index.tsx index 765aebd3..b89d6d28 100644 --- a/src/components/profile-components/profile-menu/index.tsx +++ b/src/components/profile-components/profile-menu/index.tsx @@ -5,8 +5,11 @@ import ExitIcon from '@images/profile/exit.svg?react'; import HeartIcon from '@images/profile/heart.svg?react'; import MarkerIcon from '@images/profile/marker.svg?react'; import UserIcon from '@images/profile/user.svg?react'; -// import { useAuth } from '@hooks/use-auth'; +import { useAuth } from '@hooks/use-auth'; import clsx from 'clsx'; +import { usePopup } from '@hooks/use-popup'; +import Popup from '@components/popup'; +import { useState } from 'react'; const menuArray = [ { title: 'Мои заказы', Icon: BagIcon, path: '.' }, @@ -18,11 +21,17 @@ const menuArray = [ export default function ProfileMenu() { const navigate = useNavigate(); - // const { logout } = useAuth(); + const { logout } = useAuth(); + const { handleOpenPopup, handleClosePopup, popupState } = usePopup(); + const [isLoadingExit, setIsLoadingExit] = useState(false); - const onClick = () => { - // logout(); - navigate('/'); + const handleExit = () => { + setIsLoadingExit(true); + logout().then(() => { + handleClosePopup('openPopupLogout'); + setIsLoadingExit(false); + navigate('/'); + }); }; return (