File tree Expand file tree Collapse file tree 2 files changed +17
-6
lines changed
src/app/[locale]/(main)/(container)/profile Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Original file line number Diff line number Diff line change 11import { Link } from '@/navigation' ;
22import {
33 Chip ,
4+ CircularProgress ,
45 Divider ,
56 List ,
67 ListItem ,
@@ -17,6 +18,7 @@ export interface MenuItem {
1718 icon : any ;
1819 count ?: number ;
1920 onClick ?: ( ) => void ;
21+ isLoading ?: boolean ;
2022}
2123
2224export interface MenuItemsProps {
@@ -60,8 +62,13 @@ const MenuItems: FC<MenuItemsProps> = ({ items }) => {
6062 minWidth : 36 ,
6163 } }
6264 >
63- < item . icon />
65+ { item . isLoading ? (
66+ < CircularProgress color = "inherit" size = { 20 } />
67+ ) : (
68+ < item . icon />
69+ ) }
6470 </ ListItemIcon >
71+
6572 < ListItemText
6673 primary = { item . label }
6774 primaryTypographyProps = { {
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import { MenuItem } from '../components/MenuItems';
99import { usePathname , useRouter } from '@/navigation' ;
1010import { signOut } from 'next-auth/react' ;
1111import { protectedRoutes } from '@/config/app' ;
12+ import { useTransition } from 'react' ;
1213
1314export interface IUseMenuItems {
1415 ( props ?: { ordersCount : number } ) : {
@@ -17,14 +18,16 @@ export interface IUseMenuItems {
1718}
1819const useMenuItems : IUseMenuItems = ( props ) => {
1920 const t = useTranslations ( ) ;
20-
21+ const [ isPending , startTransition ] = useTransition ( ) ;
2122 const pathname = usePathname ( ) ;
2223 const router = useRouter ( ) ;
2324 const handleLogout = async ( ) => {
24- await signOut ( { redirect : false } ) ;
25- if ( protectedRoutes . some ( ( route ) => pathname . includes ( route ) ) ) {
26- router . push ( '/' ) ;
27- }
25+ startTransition ( async ( ) => {
26+ await signOut ( { redirect : false } ) ;
27+ if ( protectedRoutes . some ( ( route ) => pathname . includes ( route ) ) ) {
28+ router . push ( '/' ) ;
29+ }
30+ } ) ;
2831 } ;
2932
3033 const items = [
@@ -48,6 +51,7 @@ const useMenuItems: IUseMenuItems = (props) => {
4851 label : t ( 'profile.logout' ) ,
4952 onClick : handleLogout ,
5053 icon : LogoutOutlined ,
54+ isLoading : isPending ,
5155 } ,
5256 ] ;
5357 return { items } ;
You can’t perform that action at this time.
0 commit comments