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 authored and mr3nz1 committed Jul 23, 2024
1 parent 7a1d280 commit d2405c8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 30 deletions.
34 changes: 15 additions & 19 deletions app/(app)/ActionMenu/Booking/SelectPayment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,17 @@ export default function SelectPayment() {
console.log("Error while inserting data in booking ", error);
}
}
const addNotification = async ( doctorName: string) => {
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,
viewed:false

});
console.log("Notification will be pushed")
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,
viewed: false,
});
console.log("Notification will be pushed");
if (error) {
console.log("Error while inserting notification ", error);
}
Expand All @@ -109,9 +106,9 @@ console.log("Notification will be pushed")
};
const fetchDoctorName = async (doctorId: string) => {
const { data, error } = await supabase
.from('doctors')
.select('first_name')
.eq('id', doctorId)
.from("doctors")
.select("first_name")
.eq("id", doctorId)
.single();

if (error) {
Expand Down Expand Up @@ -213,11 +210,10 @@ console.log("Notification will be pushed")
),
});
};
const handleOnRedirect = async(data: RedirectParams) => {

const handleOnRedirect = async (data: RedirectParams) => {
if (data.status === "successful") {
bookAppointment();
if (typeof doctor_id === "string") {
if (typeof doctor_id === "string") {
const doctorName = await fetchDoctorName(doctor_id);
await addNotification(doctorName);
}
Expand Down
23 changes: 12 additions & 11 deletions app/(app)/ActionMenu/Booking/SelectPaymentFlutter.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { View, TouchableOpacity, StyleSheet } from 'react-native';
import { FlutterwaveInit } from 'flutterwave-react-native';
import React from "react";
import { View, TouchableOpacity, StyleSheet } from "react-native";
import { FlutterwaveInit } from "flutterwave-react-native";

interface MyCartState {
isPending: boolean;
Expand Down Expand Up @@ -35,21 +35,22 @@ class MyCart extends React.Component<{}, MyCartState> {
const paymentLink = await FlutterwaveInit(
{
tx_ref: generateTransactionRef(),
authorization: '[merchant public key]',
authorization: "[merchant public key]",
amount: 100,
currency: 'USD',
currency: "USD",
customer: {
email: '[email protected]',
email: "[email protected]",
},
payment_options: 'card',
payment_options: "card",
},
this.abortController.signal
);
// use payment link

this.usePaymentLink(paymentLink);
} catch (error: any) {
// do nothing if our payment initialization was aborted
if (error.code === 'ABORTERROR') {
if (error.code === "ABORTERROR") {
return;
}
// handle other errors
Expand All @@ -61,17 +62,17 @@ class MyCart extends React.Component<{}, MyCartState> {

generateTransactionRef = (): string => {
// Generate a transaction reference
return 'unique_transaction_ref';
return "unique_transaction_ref";
};

usePaymentLink = (link: string) => {
// Use the payment link (navigate to a webview or open in browser)
console.log('Payment link:', link);
console.log("Payment link:", link);
};

displayErrorMessage = (message: string) => {
// Display error message to the user
console.error('Error:', message);
console.error("Error:", message);
};

render() {
Expand Down

0 comments on commit d2405c8

Please sign in to comment.