From 318a4bb9f6b2a8c5dc3ea0a3eafa8ced57a2deaa Mon Sep 17 00:00:00 2001 From: Irirwanirira Date: Fri, 19 Jul 2024 11:51:15 +0200 Subject: [PATCH] remove static dotor while joinning the call --- .../MessagingAppointment/ChannelScreen.tsx | 8 +- .../MessagingAppointment/Home.tsx | 88 +++++++++---------- .../MessagingAppointment/index.tsx | 7 +- 3 files changed, 49 insertions(+), 54 deletions(-) diff --git a/app/(app)/Appointments/MessagingAppointment/ChannelScreen.tsx b/app/(app)/Appointments/MessagingAppointment/ChannelScreen.tsx index 6a18f73..6e2f29e 100644 --- a/app/(app)/Appointments/MessagingAppointment/ChannelScreen.tsx +++ b/app/(app)/Appointments/MessagingAppointment/ChannelScreen.tsx @@ -31,9 +31,14 @@ const ChannelScreen = () => { const [isloading, setIsLoading] = useState(false); const ios = Platform.OS === "ios"; const modal = useModal(); - const {appointmentId} = useGlobalSearchParams(); + const {id,appointmentId} = useGlobalSearchParams(); const { channel } = useAppContext(); + // const deleteChannel = async () => { + // try{ + // await client.deleteChannels([id], {hard_delete: true}); + // }catch(error){} + // } const endAppointment = async() => { try { setIsLoading(true); @@ -131,7 +136,6 @@ const ChannelScreen = () => { enforceUniqueReaction={true} giphyEnabled={true} > - diff --git a/app/(app)/Appointments/MessagingAppointment/Home.tsx b/app/(app)/Appointments/MessagingAppointment/Home.tsx index d7fd32c..b5dbcb4 100644 --- a/app/(app)/Appointments/MessagingAppointment/Home.tsx +++ b/app/(app)/Appointments/MessagingAppointment/Home.tsx @@ -3,65 +3,62 @@ import { AuthContext } from "@/ctx/AuthContext"; import { useContext, useEffect, useState } from "react"; import { StreamChat } from "stream-chat"; import { fetchPatientData } from "@/utils/LoggedInUser"; -import {PatientTypes} from "@/constants/Types"; +import { PatientTypes } from "@/constants/Types"; import { useAppContext } from "@/ctx/ChatContext"; import ChannelLists from "./ChannelList"; import uuid from "react-native-uuid"; -import {useGlobalSearchParams } from "expo-router"; +import { useGlobalSearchParams } from "expo-router"; const API_KEY = process.env.EXPO_PUBLIC_STREAM_API_KEY; const SECRETE_KEY = process.env.EXPO_PUBLIC_STREAM_API_SECRET; export function Home() { - const [clientIsReady, setClientIsReady] = useState(false); - const [patientData, setPatientData] = useState(null); - const [client, setClient] = useState(null); - const { channel, setChannel } = useAppContext(); + const [clientIsReady, setClientIsReady] = useState(false); + const [patientData, setPatientData] = useState(null); + const [client, setClient] = useState(null); + const { channel, setChannel } = useAppContext(); + const { userId } = useContext(AuthContext); + const CDNURL = + "https://vbwbfflzxuhktdvpbspd.supabase.co/storage/v1/object/public/patients/"; + const { doctorId, appointmentId } = useGlobalSearchParams(); + const chatRoomId = "matadores-medica" + uuid.v4(); + useEffect(() => { + if (userId) { + fetchPatientData(userId, setPatientData); + } + }, [userId]); - const { userId } = useContext(AuthContext); - - const {id, appointmentId} = useGlobalSearchParams() - const doctorId = id; - const chatRoomId = "matadores-medica"+uuid.v4(); - - useEffect(() => { - if (userId) { - fetchPatientData(userId, setPatientData); - } - }, [userId]); - - const chatClient = StreamChat.getInstance(`${API_KEY}`); + const chatClient = StreamChat.getInstance(`${API_KEY}`); useEffect(() => { const setupClient = async () => { - try { - if (patientData && patientData[0]) { - const user = { - id: patientData[0].id, - name: `${patientData[0].first_name} ${patientData[0].last_name}`, - image: "https://i.imgur.com/fR9Jz14.png", - }; + try { + if (patientData && patientData[0]) { + const user = { + id: patientData[0].id, + name: `${patientData[0].first_name} ${patientData[0].last_name}`, + image: `${CDNURL + patientData[0]?.image}`, + }; - await chatClient.connectUser( - user, - chatClient.devToken(user.id)); - setClientIsReady(true); - setClient(chatClient); + await chatClient.connectUser(user, chatClient.devToken(user.id)); - const channel = chatClient.channel("messaging", `${chatRoomId}`, { - image: "https://vbwbfflzxuhktdvpbspd.supabase.co/storage/v1/object/public/doctors/adaptive_icon.png", - name: "Medica Chat Room", - members: [user?.id , `${doctorId}`], - }); - await channel.watch(); - setChannel(channel); - } else { - console.log("No patient data found"); - } - } catch (error) { - console.error("An error occurred while connecting the user:", error); + setClientIsReady(true); + setClient(chatClient); + const channel = chatClient.channel("messaging", `${chatRoomId}`, { + image: + "https://vbwbfflzxuhktdvpbspd.supabase.co/storage/v1/object/public/doctors/adaptive_icon.png", + name: `${user?.name} in the chat`, + members: [user?.id, `${doctorId}`], + }); + await channel.watch(); + setChannel(channel); + } else { + console.log("No patient data found"); } + } catch (error) { + console.error("An error occurred while connecting the user:", error); + } }; if (!chatClient.userID) { setupClient(); @@ -69,10 +66,7 @@ export function Home() { // if(client){return async()=> await client.disconnectUser()} }, [patientData]); - return ( - - ) + return ; } export default Home; - diff --git a/app/(app)/Appointments/MessagingAppointment/index.tsx b/app/(app)/Appointments/MessagingAppointment/index.tsx index 3a84674..140b740 100644 --- a/app/(app)/Appointments/MessagingAppointment/index.tsx +++ b/app/(app)/Appointments/MessagingAppointment/index.tsx @@ -157,9 +157,6 @@ try { fetchUserProfile() }, [loggeduser]) - - - return ( {appointment.paid ? "(Paid)" : "(not paid)"} + ]}>(Paid) @@ -419,7 +416,7 @@ try { router.push( { pathname: "(app)/Appointments/MessagingAppointment/Home", - params: {id: "1f4c9b93-5d95-427b-93fc-4936e4046454", appointmentId: appointment?.id} + params: {doctorId: appointment?.doctor_id, appointmentId: appointment?.id} } ) }