Skip to content

Commit

Permalink
ft(notifications):add logic to insert notifications on every booking
Browse files Browse the repository at this point in the history
  • Loading branch information
23nosurrend committed Jul 20, 2024
1 parent fcb2dc5 commit a522889
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions app/(app)/ActionMenu/Booking/SelectPayment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,40 @@ export default function SelectPayment() {
console.log("Error while inserting data in booking ", error);
}
}
const addNotification = async ( doctorName: string) => {
try {
const { error } = await supabase
.from('notifications')
.insert({
title: 'Appointment Booked',
description: `You have successfully booked an appointment with Dr. ${doctorName}`,
patient_id: patient_id,
type: "appointment_booked",
doctor_id:doctor_id

});
console.log("Notification will be pushed")
if (error) {
console.log("Error while inserting notification ", error);
}
} catch (error) {
console.log("Error while inserting notification ", error);
}
};
const fetchDoctorName = async (doctorId: string) => {
const { data, error } = await supabase
.from('doctors')
.select('first_name')
.eq('id', doctorId)
.single();

if (error) {
console.log("Error fetching doctor's name: ", error);
return "";
}

return data.first_name;
};
function successBooking() {
router.push("ActionMenu");
modal.hide();
Expand Down Expand Up @@ -178,10 +212,14 @@ export default function SelectPayment() {
),
});
};
const handleOnRedirect = (data: RedirectParams) => {
// console.log("redire data:", data)
const handleOnRedirect = async(data: RedirectParams) => {

if (data.status === "successful") {
bookAppointment();
if (typeof doctor_id === "string") {
const doctorName = await fetchDoctorName(doctor_id);
await addNotification(doctorName);
}
showSuccefulModal();
} else {
alert("Payment Failed or cancelled ,please try again");
Expand Down

0 comments on commit a522889

Please sign in to comment.