Skip to content

Commit

Permalink
fix(logout): fix logic code undefined in invoke api
Browse files Browse the repository at this point in the history
  • Loading branch information
ngyngcphu committed Dec 4, 2023
1 parent 26e8e0a commit d600dce
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { MAIN_MENU, SUB_MENU } from '@constants';
import { useUserQuery } from '@hooks';
import { AppLayout, AuthLayout } from '@layouts';
import { AuthPage, HomePage } from '@pages';
import { authService } from './services/auth.service';

export default function App() {
const navigate: NavigateFunction = useNavigate();
Expand Down Expand Up @@ -84,8 +85,7 @@ export default function App() {
{
type: 'logout-btn',
name: SUB_MENU.logout,
onClick() {}
//onClick: () => authService.logout().then(() => getData())
onClick: () => authService.logout().then(() => refetch())
}
]}
/>
Expand Down
15 changes: 9 additions & 6 deletions src/components/common/AppNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import coin from '@assets/coin.png';
import { AppDrawer, DesktopNavbar, ToggleSidebarBtn, useSidebarMenu } from '@components/common';
import { useCloseForm } from '@components/order/common';
import { ScreenSize } from '@constants';
import { useScreenSize, useUserQuery, usePrintingRequestQuery, emitEvent } from '@hooks';
import {
useScreenSize,
useUserQuery,
usePrintingRequestQuery,
useAuthMutation,
emitEvent
} from '@hooks';
import { useMenuBarStore, useOrderWorkflowStore } from '@states';
import { formatFileSize } from '@utils';
import { useAuthMutation } from '@hooks';

export const AppNavigation: Component<{ mainMenu: RouteMenu; subMenu: RouteMenu }> = ({
mainMenu,
Expand All @@ -32,9 +37,7 @@ export const AppNavigation: Component<{ mainMenu: RouteMenu; subMenu: RouteMenu
() => listFiles?.reduce((totalSize, file) => totalSize + file.fileSize, 0),
[listFiles]
);
const handleLogout = () => {
logout.mutateAsync();
};

return (
<div className='w-full max-h-[768px] py-3 shadow-md lg:sticky my-3 lg:my-0'>
<div className='flex items-center justify-between px-6 lg:px-9'>
Expand Down Expand Up @@ -62,7 +65,7 @@ export const AppNavigation: Component<{ mainMenu: RouteMenu; subMenu: RouteMenu
)}
<img className='w-7 h-7 lg:w-10 lg:h-10' src={coin} alt='coin'></img>
<PowerIcon
onClick={handleLogout}
onClick={() => logout.mutateAsync()}
className='w-10 h-10 hidden lg:block lg:opacity-40 lg:ml-6 lg:cursor-pointer'
/>
</div>
Expand Down
11 changes: 6 additions & 5 deletions src/components/common/SidebarMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import logo from '@assets/logobk.png';
import ticklab from '@assets/ticklab.png';
import { ToggleSidebarBtn } from '@components/common';
import { useMenuBarStore } from '@states';
import { useAuthMutation } from '@hooks';

export function useSidebarMenu() {
const { logout } = useAuthMutation();
const { selectedMenu, setSelectedMenu } = useMenuBarStore();

const ITEM_CLASSNAME =
Expand Down Expand Up @@ -56,9 +54,6 @@ export function useSidebarMenu() {
);
}
})}
<ListItem className={ITEM_CLASSNAME} onClick={() => logout.mutateAsync()}>
Log out
</ListItem>
</List>
<List className='p-0'>
{subMenu.map((menuItem, idx) => {
Expand All @@ -81,6 +76,12 @@ export function useSidebarMenu() {
</ListItem>
</Link>
);
} else if (menuItem.type === 'logout-btn') {
return (
<ListItem key={idx} className={ITEM_CLASSNAME} onClick={menuItem.onClick}>
{menuItem.name}
</ListItem>
);
}
})}
</List>
Expand Down
9 changes: 3 additions & 6 deletions src/components/order/desktop/TopUpWalletDesktop.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { InformationCircleIcon, BanknotesIcon, WalletIcon } from '@heroicons/react/24/outline';
import { Button, Radio } from '@material-tailwind/react';
import coinImage from '@assets/coin.png';
import momoImage from '@assets/momo.png';
import zaloImage from '@assets/zalo.png';
import VNPayImage from '@assets/VNPay.png';

export const TopUpWalletDestop = () => {
const currentBalance = 202;
Expand All @@ -12,15 +9,15 @@ export const TopUpWalletDestop = () => {
const amountLevel = 100000;
const methodList = [
{
image: momoImage,
image: coinImage,
method: 'Momo'
},
{
image: zaloImage,
image: coinImage,
method: 'Zalo'
},
{
image: VNPayImage,
image: coinImage,
method: 'VNPay'
}
];
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file Automatically generated by barrelsby.
*/

export * from './useAuthMutation';
export * from './useAuthMutation.hook';
export * from './useEvent';
export * from './usePrintingRequestMutation.hook';
export * from './usePrintingRequestQuery.hook';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { authService, userService } from '@services';

export function useAuthMutation() {
const queryClient = useQueryClient();

const logout = useMutation({
mutationKey: ['logout'],
mutationFn: () => authService.logout(),
onSuccess: () => {
queryClient.prefetchQuery({
queryKey: ['/api/user'],
queryFn: () => userService.getInfo()
queryFn: () => userService.getInfo(),
retry: 0
});
}
});
Expand Down
4 changes: 3 additions & 1 deletion src/hooks/usePrintingRequestMutation.hook.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { printingRequestService, buyCoinService, userService } from '@services';
import { retryQueryFn } from '@utils';

export function usePrintingRequestMutation() {
const queryClient = useQueryClient();
Expand Down Expand Up @@ -65,7 +66,8 @@ export function usePrintingRequestMutation() {
onSuccess: () => {
queryClient.prefetchQuery({
queryKey: ['/api/user/remain-coins'],
queryFn: () => userService.getRemainCoins()
queryFn: () => userService.getRemainCoins(),
retry: retryQueryFn
});
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/services/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export const apiClient = createClient<paths>({

export async function invoke<T = unknown>(call: Promise<FetchResponse<T>>) {
const { data, error } = await call;
if (data) return data;
if (data !== undefined) return data;
throw (error as ResponseError).message;
}

0 comments on commit d600dce

Please sign in to comment.