-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
146 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { withTempBaseUrl } from "@/lib/utils/withTempBaseUrl"; | ||
import patientAxiosInstance from "../patient/authorizedRoutes"; | ||
import doctorAxiosInstance from "../doctor/authorizedRoutes"; | ||
|
||
const patientBaseUrl = `${process.env.NEXT_PUBLIC_API_URL}/notifications/patient`; | ||
const doctorBaseUrl = `${process.env.NEXT_PUBLIC_API_URL}/notifications/doctor`; | ||
|
||
// Patient | ||
export const getPatientNotifications = async()=>{ | ||
const response = await withTempBaseUrl(patientAxiosInstance,patientBaseUrl,{ | ||
method:"GET", | ||
url:"/" | ||
}) | ||
return response.data; | ||
} | ||
|
||
export const clearMultiplePatientNotifications = async(notificationIds:string[])=>{ | ||
const response = await withTempBaseUrl(patientAxiosInstance,patientBaseUrl,{ | ||
method:"DELETE", | ||
url:"/clear-all", | ||
data:{ | ||
notificationIds | ||
} | ||
}) | ||
return response.data; | ||
} | ||
|
||
export const clearPatientNotification = async(notificationId:string)=>{ | ||
const response = await withTempBaseUrl(patientAxiosInstance,patientBaseUrl,{ | ||
method:"DELETE", | ||
url:`/${notificationId}`, | ||
}); | ||
return response.data; | ||
} | ||
|
||
|
||
// Doctor | ||
export const getDoctorNotifications = async()=>{ | ||
const response = await withTempBaseUrl(doctorAxiosInstance,doctorBaseUrl,{ | ||
method:"GET", | ||
url:"/" | ||
}) | ||
return response.data; | ||
} | ||
|
||
export const clearMultipleDoctorNotifications = async(notificationIds:string[])=>{ | ||
const response = await withTempBaseUrl(doctorAxiosInstance,doctorBaseUrl,{ | ||
method:"DELETE", | ||
url:"/clear-all", | ||
data:{ | ||
notificationIds | ||
} | ||
}) | ||
return response.data; | ||
} | ||
|
||
export const clearDoctorNotification = async(notificationId:string)=>{ | ||
const response = await withTempBaseUrl(doctorAxiosInstance,doctorBaseUrl,{ | ||
method:"DELETE", | ||
url:`/${notificationId}`, | ||
}); | ||
return response.data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { clearMultiplePatientNotifications, getDoctorNotifications, clearDoctorNotification } from "@/lib/api/notification" | ||
import { ErrorResponse, INotification, MessageResponse } from "@/types" | ||
import { useMutation, useQuery } from "@tanstack/react-query" | ||
import { AxiosError } from "axios" | ||
|
||
|
||
|
||
export const useGetAllDoctorNotifications = ()=>{ | ||
return useQuery<INotification[],AxiosError<ErrorResponse>>({ | ||
queryKey:["notifications"], | ||
queryFn:getDoctorNotifications | ||
}) | ||
} | ||
|
||
export const useClearMultipleDoctorNotifications = ()=>{ | ||
return useMutation<MessageResponse,AxiosError<ErrorResponse>,{notificationIds:string[]}>({ | ||
mutationFn:({notificationIds})=>clearMultiplePatientNotifications(notificationIds), | ||
onError:(error)=>{ | ||
console.log('error in clearing notifications ,', error); | ||
} | ||
}) | ||
} | ||
|
||
export const useClearDoctorNotification = ()=>{ | ||
return useMutation<MessageResponse,AxiosError<ErrorResponse>,{notificationId:string}>({ | ||
mutationFn:({notificationId})=>clearDoctorNotification(notificationId), | ||
onError:(error)=>{ | ||
console.log('error in clearing notification ,', error); | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { clearMultiplePatientNotifications, getPatientNotifications, clearPatientNotification } from "@/lib/api/notification" | ||
import { ErrorResponse, INotification, MessageResponse } from "@/types" | ||
import { useMutation, useQuery } from "@tanstack/react-query" | ||
import { AxiosError } from "axios" | ||
|
||
|
||
|
||
export const useGetAllPatientNotifications = ()=>{ | ||
return useQuery<INotification[],AxiosError<ErrorResponse>>({ | ||
queryKey:["notifications"], | ||
queryFn:getPatientNotifications | ||
}) | ||
} | ||
|
||
export const useClearMultiplePatientNotifications = ()=>{ | ||
return useMutation<MessageResponse,AxiosError<ErrorResponse>,{notificationIds:string[]}>({ | ||
mutationFn:({notificationIds})=>clearMultiplePatientNotifications(notificationIds), | ||
onError:(error)=>{ | ||
console.log('error in clearing notifications ,', error); | ||
} | ||
}) | ||
} | ||
|
||
export const useClearPatientNotification = ()=>{ | ||
return useMutation<MessageResponse,AxiosError<ErrorResponse>,{notificationId:string}>({ | ||
mutationFn:({notificationId})=>clearPatientNotification(notificationId), | ||
onError:(error)=>{ | ||
console.log('error in clearing notification ,', error); | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters