27 lines
972 B
JavaScript
27 lines
972 B
JavaScript
import useSWR from 'swr'
|
|
import {GET_SIDEBAR_NOTIFICATION} from "@/core/data/apiRoutes";
|
|
import useRequest from "@/lib/app/hooks/useRequest";
|
|
const GLOBAL_HAS_VALUE = process.env.NEXT_PUBLIC_HAS_VALUE;
|
|
const hasPermissionsValue = GLOBAL_HAS_VALUE ? JSON.parse(GLOBAL_HAS_VALUE) : [];
|
|
const isNotificationEnabled = hasPermissionsValue.includes("NEXT_PUBLIC_HAS_NOTIFICATION");
|
|
|
|
const useNotification = () => {
|
|
|
|
const requestServer = useRequest({auth: true, notification: false})
|
|
|
|
//swr config
|
|
const fetcher = (...args) => {
|
|
return requestServer(args, 'get').then((response) => {
|
|
return response.data.data;
|
|
}).catch(() => {
|
|
})
|
|
};
|
|
|
|
const {data, mutate} = useSWR( isNotificationEnabled ? GET_SIDEBAR_NOTIFICATION : '', fetcher , {keepPreviousData:true})
|
|
const notification_count = data
|
|
//swr config
|
|
|
|
// render data
|
|
return {notification_count, update_notification: mutate}
|
|
}
|
|
export default useNotification |