Skip to content

Commit d2405c8

Browse files
23nosurrendmr3nz1
authored andcommitted
ft(notifications):add logic to insert notifications on every booking
1 parent 7a1d280 commit d2405c8

File tree

2 files changed

+27
-30
lines changed

2 files changed

+27
-30
lines changed

Diff for: app/(app)/ActionMenu/Booking/SelectPayment.tsx

+15-19
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,17 @@ export default function SelectPayment() {
8686
console.log("Error while inserting data in booking ", error);
8787
}
8888
}
89-
const addNotification = async ( doctorName: string) => {
89+
const addNotification = async (doctorName: string) => {
9090
try {
91-
const { error } = await supabase
92-
.from('notifications')
93-
.insert({
94-
title: 'Appointment Booked',
95-
description: `You have successfully booked an appointment with Dr. ${doctorName}`,
96-
patient_id: patient_id,
97-
type: "appointment_booked",
98-
doctor_id: doctor_id,
99-
viewed:false
100-
101-
});
102-
console.log("Notification will be pushed")
91+
const { error } = await supabase.from("notifications").insert({
92+
title: "Appointment Booked",
93+
description: `You have successfully booked an appointment with Dr. ${doctorName}`,
94+
patient_id: patient_id,
95+
type: "appointment_booked",
96+
doctor_id: doctor_id,
97+
viewed: false,
98+
});
99+
console.log("Notification will be pushed");
103100
if (error) {
104101
console.log("Error while inserting notification ", error);
105102
}
@@ -109,9 +106,9 @@ console.log("Notification will be pushed")
109106
};
110107
const fetchDoctorName = async (doctorId: string) => {
111108
const { data, error } = await supabase
112-
.from('doctors')
113-
.select('first_name')
114-
.eq('id', doctorId)
109+
.from("doctors")
110+
.select("first_name")
111+
.eq("id", doctorId)
115112
.single();
116113

117114
if (error) {
@@ -213,11 +210,10 @@ console.log("Notification will be pushed")
213210
),
214211
});
215212
};
216-
const handleOnRedirect = async(data: RedirectParams) => {
217-
213+
const handleOnRedirect = async (data: RedirectParams) => {
218214
if (data.status === "successful") {
219215
bookAppointment();
220-
if (typeof doctor_id === "string") {
216+
if (typeof doctor_id === "string") {
221217
const doctorName = await fetchDoctorName(doctor_id);
222218
await addNotification(doctorName);
223219
}

Diff for: app/(app)/ActionMenu/Booking/SelectPaymentFlutter.tsx

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import React from 'react';
2-
import { View, TouchableOpacity, StyleSheet } from 'react-native';
3-
import { FlutterwaveInit } from 'flutterwave-react-native';
1+
import React from "react";
2+
import { View, TouchableOpacity, StyleSheet } from "react-native";
3+
import { FlutterwaveInit } from "flutterwave-react-native";
44

55
interface MyCartState {
66
isPending: boolean;
@@ -35,21 +35,22 @@ class MyCart extends React.Component<{}, MyCartState> {
3535
const paymentLink = await FlutterwaveInit(
3636
{
3737
tx_ref: generateTransactionRef(),
38-
authorization: '[merchant public key]',
38+
authorization: "[merchant public key]",
3939
amount: 100,
40-
currency: 'USD',
40+
currency: "USD",
4141
customer: {
42-
42+
4343
},
44-
payment_options: 'card',
44+
payment_options: "card",
4545
},
4646
this.abortController.signal
4747
);
4848
// use payment link
49+
4950
this.usePaymentLink(paymentLink);
5051
} catch (error: any) {
5152
// do nothing if our payment initialization was aborted
52-
if (error.code === 'ABORTERROR') {
53+
if (error.code === "ABORTERROR") {
5354
return;
5455
}
5556
// handle other errors
@@ -61,17 +62,17 @@ class MyCart extends React.Component<{}, MyCartState> {
6162

6263
generateTransactionRef = (): string => {
6364
// Generate a transaction reference
64-
return 'unique_transaction_ref';
65+
return "unique_transaction_ref";
6566
};
6667

6768
usePaymentLink = (link: string) => {
6869
// Use the payment link (navigate to a webview or open in browser)
69-
console.log('Payment link:', link);
70+
console.log("Payment link:", link);
7071
};
7172

7273
displayErrorMessage = (message: string) => {
7374
// Display error message to the user
74-
console.error('Error:', message);
75+
console.error("Error:", message);
7576
};
7677

7778
render() {

0 commit comments

Comments
 (0)