notification count
This commit is contained in:
@@ -19,3 +19,10 @@ export const useGetCategories = () => {
|
|||||||
enabled: !!name,
|
enabled: !!name,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useGetNotificationsCount = () => {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["notifications-count"],
|
||||||
|
queryFn: api.getNotificationsCount,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
import { api } from "@/config/axios";
|
import { api } from "@/config/axios";
|
||||||
import { CategoriesResponse, FoodsResponse } from "../types/Types";
|
import {
|
||||||
|
CategoriesResponse,
|
||||||
|
FoodsResponse,
|
||||||
|
NotificationsCountResponse,
|
||||||
|
} from "../types/Types";
|
||||||
|
|
||||||
export const getFoods = async (slug: string): Promise<FoodsResponse> => {
|
export const getFoods = async (slug: string): Promise<FoodsResponse> => {
|
||||||
const response = await api.get<FoodsResponse>(
|
const response = await api.get<FoodsResponse>(
|
||||||
@@ -16,3 +20,12 @@ export const getCategories = async (
|
|||||||
);
|
);
|
||||||
return response.data;
|
return response.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getNotificationsCount = async (): Promise<
|
||||||
|
NotificationsCountResponse
|
||||||
|
> => {
|
||||||
|
const response = await api.get<NotificationsCountResponse>(
|
||||||
|
`/public/notifications/unseen-count`
|
||||||
|
);
|
||||||
|
return response.data;
|
||||||
|
};
|
||||||
|
|||||||
@@ -76,3 +76,9 @@ export interface Food {
|
|||||||
|
|
||||||
export type FoodsResponse = BaseResponse<Food[]>;
|
export type FoodsResponse = BaseResponse<Food[]>;
|
||||||
export type FoodResponse = BaseResponse<Food>;
|
export type FoodResponse = BaseResponse<Food>;
|
||||||
|
|
||||||
|
export interface NotificationsCountData {
|
||||||
|
count: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type NotificationsCountResponse = BaseResponse<NotificationsCountData>;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { useParams } from 'next/navigation'
|
|||||||
import useToggle from '@/hooks/helpers/useToggle'
|
import useToggle from '@/hooks/helpers/useToggle'
|
||||||
import LogoutPrompt from '@/features/general/LogoutPrompt'
|
import LogoutPrompt from '@/features/general/LogoutPrompt'
|
||||||
import { useGetProfile } from '@/app/[name]/(Profile)/profile/hooks/userProfileData'
|
import { useGetProfile } from '@/app/[name]/(Profile)/profile/hooks/userProfileData'
|
||||||
|
import { useGetNotificationsCount } from '@/app/[name]/(Main)/hooks/useMenuData'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
profileDropState: boolean,
|
profileDropState: boolean,
|
||||||
@@ -29,6 +30,7 @@ function TopBar({ profileDropState, toggleProfileDropState, toggleMenuState }: P
|
|||||||
const { name } = params;
|
const { name } = params;
|
||||||
const { state: logoutModal, toggle: toggleLogoutModal } = useToggle();
|
const { state: logoutModal, toggle: toggleLogoutModal } = useToggle();
|
||||||
const { data: profile, isSuccess } = useGetProfile();
|
const { data: profile, isSuccess } = useGetProfile();
|
||||||
|
const { data: notificationsCount } = useGetNotificationsCount();
|
||||||
const profileData = profile?.data;
|
const profileData = profile?.data;
|
||||||
const isLoggedIn = isSuccess && profileData;
|
const isLoggedIn = isSuccess && profileData;
|
||||||
const fullName = profileData ? `${profileData.firstName} ${profileData.lastName}`.trim() : 'کاربر داناک';
|
const fullName = profileData ? `${profileData.firstName} ${profileData.lastName}`.trim() : 'کاربر داناک';
|
||||||
@@ -70,7 +72,7 @@ function TopBar({ profileDropState, toggleProfileDropState, toggleMenuState }: P
|
|||||||
className='relative'>
|
className='relative'>
|
||||||
<NotificationBellIcon className='size-4.5 text-icon-active dark:text-foreground' />
|
<NotificationBellIcon className='size-4.5 text-icon-active dark:text-foreground' />
|
||||||
<span className='absolute -right-1 -top-1 flex items-center justify-center bg-primary size-3 rounded-full text-[8px] text-container'>
|
<span className='absolute -right-1 -top-1 flex items-center justify-center bg-primary size-3 rounded-full text-[8px] text-container'>
|
||||||
<div className='mt-0.25 place-self-center'>2</div>
|
<div className='mt-0.25 place-self-center'>{notificationsCount?.data?.count}</div>
|
||||||
</span>
|
</span>
|
||||||
</Link>
|
</Link>
|
||||||
{isLoggedIn ? (
|
{isLoggedIn ? (
|
||||||
|
|||||||
Reference in New Issue
Block a user