@@ -23,17 +23,13 @@ function Screen() {
2323 const [ complete , setComlpete ] = useState ( false ) ;
2424 const [ notupcome , setNotupcome ] = useState ( false ) ;
2525 const [ isModalVisible , setIsModalVisible ] = useState ( false ) ;
26- < < << << < HEAD
27- const [ appointmentData , setAppointmentData ] = useState < any [ ] > ( [ ] ) ;
2826 const { doctorId } = useLocalSearchParams < { doctorId : string } > ( ) ;
29- const [ appointId , setAppointId ] = useState ( { } ) ;
27+ const appointments = useSelector (
28+ ( state : RootState ) => state . appointment . appointments
29+ ) ;
3030 const [ canceledData , setcanceledData ] = useState < any [ ] > ( [ ] ) ;
31-
32- = === ===
33- const { doctorId } = useLocalSearchParams < { doctorId : string } > ( ) ;
34- const appointments = useSelector ( ( state : RootState ) => state . appointment . appointments ) ;
31+ const [ appointId , setAppointId ] = useState ( { } ) ;
3532 const dispatch = useDispatch ( ) ;
36- > >>> >>> cf07aa0 ( messaging appointment and doctor details )
3733 const handleUpcoming = ( ) => {
3834 setCancels ( false ) ;
3935 setUpcoming ( true ) ;
@@ -64,28 +60,39 @@ function Screen() {
6460
6561 const fetchAppointment = async ( ) => {
6662 try {
67- const { data : userData , error : userError } = await supabase . auth . getUser ( ) ;
63+ const { data : userData , error : userError } =
64+ await supabase . auth . getUser ( ) ;
6865 if ( userError ) throw userError ;
6966 const userId = userData ?. user ?. id ;
70- < < << << < HEAD
7167 const { data, error } = await supabase
7268 . from ( "appointment" )
73- . select ( `
69+ . select (
70+ `
7471 *,
7572 doctor(
7673 id,
7774 name,
7875 role,
7976 image,
8077 hospital
81- )
82- ` )
78+ ),
79+ patient(
80+ id,
81+ email,
82+ phone,
83+ full_name,
84+ nickname,
85+ date_of_birth,
86+ gender
87+ )
88+ `
89+ )
8390 . eq ( "patient_id" , userId ) ;
8491
8592 if ( error ) {
8693 console . log ( "Error occurred while fetching appointments" , error ) ;
8794 } else {
88- setAppointmentData ( data ) ;
95+ dispatch ( getAppointments ( data ) ) ;
8996 if ( data . length === 0 ) {
9097 setNotupcome ( true ) ;
9198 setUpcoming ( false ) ;
@@ -102,10 +109,10 @@ function Screen() {
102109 fetchAppointment ( ) ;
103110 } , [ ] ) ;
104111
105-
106112 const cancelAppointment = async ( ) => {
107113 try {
108- const { data : userData , error : userError } = await supabase . auth . getUser ( ) ;
114+ const { data : userData , error : userError } =
115+ await supabase . auth . getUser ( ) ;
109116 if ( userError ) throw userError ;
110117 const userId = userData ?. user ?. id ;
111118 const { data, error } = await supabase
@@ -127,14 +134,13 @@ function Screen() {
127134 cancelAppointment ( ) ;
128135 } , [ ] ) ;
129136
130-
131137 const getPackageIcon = ( typecall : any ) => {
132138 switch ( typecall ) {
133- case ' Voice Call' :
139+ case " Voice Call" :
134140 return require ( "../../assets/appointmentIcon/voice.png" ) ;
135- case ' Video Call' :
141+ case " Video Call" :
136142 return require ( "../../assets/appointmentIcon/video.png" ) ;
137- case ' Messaging' :
143+ case " Messaging" :
138144 return require ( "../../assets/appointmentIcon/message.png" ) ;
139145 default :
140146 return null ;
@@ -146,55 +152,17 @@ function Screen() {
146152 appointmentId : appointment . id ,
147153 appointment_date : appointment . appointment_date ,
148154 appointment_time : appointment . appointment_time ,
149- doctorId :appointment . doctor ?. id ,
150- doctorname :appointment . doctor . name ,
151- doctimage :appointment . doctor . image ,
152- typecall :appointment . package
155+ doctorId : appointment . doctor ?. id ,
156+ doctorname : appointment . doctor . name ,
157+ doctimage : appointment . doctor . image ,
158+ typecall : appointment . package ,
153159 } ) ;
154160 setIsModalVisible ( true ) ;
155161 } ;
156- = === ===
157- const { data, error} = await supabase
158- . from ( "appointment" )
159- . select ( `
160- *,
161- doctor(
162- id,
163- name,
164- role,
165- image,
166- hospital
167- ),
168- patient(
169- id,
170- email,
171- phone,
172- full_name,
173- nickname,
174- date_of_birth,
175- gender
176- )
177- ` )
178- . eq ( "patient_id" , userId ) ;
179162
180- if ( error ) {
181- console . log ( "Error occured while fetching appointments" , error )
182- } else {
183- dispatch ( getAppointments ( data ) )
184- console . log ( "fetched data:" ) ;
185- setTimeout ( ( ) => {
186- router . push ( "/(tabs)/appointment" )
187- } , 0 )
188- } }
189- catch ( error ) {
190- console . log ( error ) ;
191- }
192- }
193- useEffect ( ( ) => {
194-
195- fetchAppointment ( ) ;
196- } , [ ] )
197- >>> > >>> cf07aa0 ( messaging appointment and doctor details )
163+ useEffect ( ( ) => {
164+ fetchAppointment ( ) ;
165+ } , [ ] ) ;
198166
199167 return (
200168 < >
@@ -278,28 +246,24 @@ fetchAppointment();
278246 >
279247 { cancels && (
280248 < View style = { styles . content } >
281- { canceledData . map ( ( canceled , index ) => (
282- < Cardcomponent
283- key = { index }
284- name = { canceled . doctorname }
285- imager = { canceled . doctimage }
286- typecall = { canceled . package }
287- action = "Cancelled"
288- date = { canceled . appointment_date }
289- time = { canceled . appointment_time . slice ( 0 , 5 ) }
290- imagerr = { getPackageIcon ( canceled . package ) }
291- styles = { styles . cancelStyles }
292- />
293- ) ) }
249+ { canceledData . map ( ( canceled , index ) => (
250+ < Cardcomponent
251+ key = { index }
252+ name = { canceled . doctorname }
253+ imager = { canceled . doctimage }
254+ typecall = { canceled . package }
255+ action = "Cancelled"
256+ date = { canceled . appointment_date }
257+ time = { canceled . appointment_time . slice ( 0 , 5 ) }
258+ imagerr = { getPackageIcon ( canceled . package ) }
259+ styles = { styles . cancelStyles }
260+ />
261+ ) ) }
294262 </ View >
295263 ) }
296264 { upcoming && (
297265 < View style = { styles . content } >
298- < < << << < HEAD
299- { appointmentData . map ( ( appointment : any , index : any ) => (
300- = === ===
301- { appointments. map ( ( appointment :any , index :any ) => (
302- > >>> >>> cf07aa0 ( messaging appointment and doctor details )
266+ { appointments . map ( ( appointment : any , index : any ) => (
303267 < Cardscomponent
304268 key = { index }
305269 appointment = { appointment }
@@ -319,8 +283,8 @@ fetchAppointment();
319283 pathname : "/Appointments/reschedul" ,
320284 params : {
321285 appointmentId : appointment . id ,
322- appointmentdate :appointment . appointment_date ,
323- appointmentime :appointment . appointment_time ,
286+ appointmentdate : appointment . appointment_date ,
287+ appointmentime : appointment . appointment_time ,
324288 } ,
325289 } )
326290 }
@@ -332,7 +296,9 @@ fetchAppointment();
332296
333297 { notupcome && (
334298 < View style = { styles . centerbar } >
335- < Image source = { require ( "../../assets/appointmentIcon/first.png" ) } />
299+ < Image
300+ source = { require ( "../../assets/appointmentIcon/first.png" ) }
301+ />
336302 < Text style = { styles . centerbartitle } >
337303 You don't have an appointment yet
338304 </ Text >
@@ -398,15 +364,14 @@ const styles = StyleSheet.create({
398364 flexGrow : 1 ,
399365 paddingBottom : 50 ,
400366 paddingTop : 20 ,
401- height :"80%"
367+ height : "80%" ,
402368 } ,
403369 centerbar : {
404370 display : "flex" ,
405371 justifyContent : "center" ,
406372 alignItems : "center" ,
407373 height : "76%" ,
408374 gap : 20 ,
409-
410375 } ,
411376 centerbartitle : {
412377 fontSize : 20 ,
@@ -499,4 +464,4 @@ const styles = StyleSheet.create({
499464 mode : {
500465 color : "#f75555" ,
501466 } ,
502- } ) ;
467+ } ) ;
0 commit comments