Skip to content

Commit

Permalink
notification hooks added
Browse files Browse the repository at this point in the history
  • Loading branch information
sinanptm committed Sep 22, 2024
1 parent 0bebcc3 commit 006c5cd
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 2 deletions.
63 changes: 63 additions & 0 deletions client/lib/api/notification/index.ts
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;
}
31 changes: 31 additions & 0 deletions client/lib/hooks/notification/useSlotDoctor.ts
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);
}
})
}
31 changes: 31 additions & 0 deletions client/lib/hooks/notification/useSlotPatient.ts
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);
}
})
}
19 changes: 19 additions & 0 deletions client/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,22 @@ export interface IExtendedAppointment extends IAppointment {
slot?: ISlot;
doctor?: IDoctor;
}



export enum NotificationTypes {
APPOINTMENT_CANCELED = 'appointment_canceled',
APPOINTMENT_CONFIRMED = 'appointment_confirmed',
APPOINTMENT_REMINDER = 'appointment_reminder',
}

export interface INotification {
readonly _id?: string;
readonly patientId?: string;
readonly doctorId?: string;
readonly type?: string;
readonly message?: string;
readonly createdAt?: Date;
readonly updatedAt?: Date;
readonly appointmentId?:string
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ router.delete(
);

router.delete(
"/patient/clear/:notificationId",
"/patient/:notificationId",
authorizePatient.exec,
notificationController.clearSingleNotification.bind(notificationController)
);
Expand All @@ -54,7 +54,7 @@ router.delete(
);

router.delete(
"/doctor/clear/:notificationId",
"/doctor/:notificationId",
authorizeDoctor.exec,
notificationController.clearSingleNotification.bind(notificationController)
);
Expand Down

0 comments on commit 006c5cd

Please sign in to comment.