Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.

Commit

Permalink
#28 Fixed all delete appointment UI
Browse files Browse the repository at this point in the history
  • Loading branch information
MilitsaB committed Apr 7, 2022
1 parent d54b9fa commit 695a049
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
26 changes: 16 additions & 10 deletions src/components/dashboard/PatientView/PatientAppointments.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState, useContext } from 'react';
import React, { useEffect, useState } from 'react';
import AdapterDateFns from '@mui/lab/AdapterDateFns';
import LocalizationProvider from '@mui/lab/LocalizationProvider';
import CalendarPicker from '@mui/lab/CalendarPicker';
Expand All @@ -23,7 +23,7 @@ const style = {
borderRadius: 4,
};

export default function PatientAppointments({ handleAppointmentViewClose } : any) {
export default function PatientAppointments({ handleAppointmentsViewClose } : any) {
const theme = useTheme();
const midSize = useMediaQuery(theme.breakpoints.down(1190));
const [appointmentDate, setAppointmentDate] = React.useState<Date | null>(new Date());
Expand All @@ -36,16 +36,21 @@ export default function PatientAppointments({ handleAppointmentViewClose } : any
const handleClose = () => {
setOpen(false);
};
const users = firestore.collection('users');

const deleteAppointment = () => {
const cancelAppointment = Firebase.functions().httpsCallable('cancelAppointment');
console.log(appointmentDate);
cancelAppointment({ appointmentDate }).then(() => {
// TODO set canBookAppointment to true*
})
.catch((saveError) => {
console.error(saveError);
});
handleClose();
handleAppointmentsViewClose();
cancelAppointment({ appointmentDate }).then(async () => {
await users
.doc(state.id)
.update({
disableBook: false,
});
}).catch((saveError) => {
console.error(saveError);
});
};

useEffect(() => {
Expand Down Expand Up @@ -104,7 +109,8 @@ export default function PatientAppointments({ handleAppointmentViewClose } : any
{appointmentDate !== null && appointmentDate.getMinutes() < 10 && ('0')}
{appointmentDate?.getMinutes()}
{' '}
AM
{appointmentDate !== null && appointmentDate?.getHours() < 12 && (' AM')}
{appointmentDate !== null && appointmentDate?.getHours() >= 12 && (' PM')}
</Typography>
</Paper>
{!midSize && (
Expand Down
10 changes: 5 additions & 5 deletions src/components/dashboard/PatientView/PatientView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ function PatientView() {
if (data) {
setUser(data);
setDisableBook(data.disableBook);
const appointmentData = data?.appointments[data.appointments.length - 1].selectedDate;
const appointmentTime = appointmentData.toDate();
const appointmentData = data?.appointments[data.appointments.length - 1]?.selectedDate;
const appointmentTime = appointmentData?.toDate();
const currentDate = new Date();
if (appointmentTime > currentDate) {
setAppointment(true);
Expand Down Expand Up @@ -120,7 +120,7 @@ function PatientView() {
</ListItemIcon>
<ListItemText data-testid="TestResults" primary="Test Results" onClick={handleTestROpen} />
</ListItem>
{!areAssigned && (
{areAssigned && (
<ListItem button key="Results" data-testid="SymptomsUpdate2">
<ListItemIcon>
<ContentPasteIcon />
Expand All @@ -137,7 +137,7 @@ function PatientView() {
</ListItemIcon>
<ListItemText primary="Main Settings" onClick={() => { setContentId(2); }} />
</ListItem>
{!appointment && !disableBook && areAssigned && (
{!disableBook && areAssigned && (
<ListItem button key="Booking">
<ListItemIcon>
<EventIcon />
Expand All @@ -148,7 +148,7 @@ function PatientView() {
/>
</ListItem>
)}
{appointment && (
{appointment && disableBook && (
<ListItem button key="Appointments">
<ListItemIcon>
<EventIcon />
Expand Down
2 changes: 1 addition & 1 deletion src/pages/booking/bookingSystem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function bookingSystem({ handleBookingClose } : Props) {
const snapData = snapshot.data();
if (snapData) {
const appointmentDates = snapData?.appointments
.map((appointment: { date: Timestamp; }) => appointment.date.toDate());
.map((appointment: { selectedDate: Timestamp; }) => appointment.selectedDate.toDate());
setBookedDates(appointmentDates);
}
});
Expand Down

0 comments on commit 695a049

Please sign in to comment.