File size: 623 Bytes
2d64850
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import {
  ProfileSettingBaseKey,
  ProfileSettingRouteKey,
} from '@/constants/setting';
import { useLogout } from '@/hooks/login-hooks';
import { useCallback } from 'react';
import { useNavigate } from 'umi';

export const useHandleMenuClick = () => {
  const navigate = useNavigate();
  const { logout } = useLogout();

  const handleMenuClick = useCallback(
    (key: ProfileSettingRouteKey) => () => {
      if (key === ProfileSettingRouteKey.Logout) {
        logout();
      } else {
        navigate(`/${ProfileSettingBaseKey}/${key}`);
      }
    },
    [logout, navigate],
  );

  return { handleMenuClick };
};