Skip to content

Commit

Permalink
ft: add appointment date filters
Browse files Browse the repository at this point in the history
  • Loading branch information
fredshema committed Jul 24, 2024
1 parent 63f4a4d commit 3c1230c
Show file tree
Hide file tree
Showing 9 changed files with 242 additions and 236 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"rules": {
"@next/next/no-img-element": "off",
"jsx-a11y/alt-text": "off",
"react/no-unescaped-entities": "off"
"react/no-unescaped-entities": "off",
" react-hooks/exhaustive-deps": "off"
}
}
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# Adjust NODE_VERSION as desired
ARG NODE_VERSION=20.15.0
ARG NEXT_PUBLIC_SUPABASE_URL
ARG NEXT_PUBLIC_SUPABASE_ANON_KEY
FROM node:${NODE_VERSION}-slim as base

LABEL fly_launch_runtime="Next.js"
Expand All @@ -27,6 +29,8 @@ RUN npm ci --include=dev
# Copy application code
COPY --link . .

ARG NEXT_PUBLIC_SUPABASE_URL
ARG NEXT_PUBLIC_SUPABASE_ANON_KEY
# Build application
RUN npm run build

Expand Down
154 changes: 81 additions & 73 deletions app/dashboard/appointments/page.tsx
Original file line number Diff line number Diff line change
@@ -1,100 +1,108 @@
"use client";
import AppointmentRequests from "@/components/dashboard/appointments/appointmentRequests";
import CancelledAppointments from "@/components/dashboard/appointments/cancelledAppointments";
import { DateValue } from "@/components/dashboard/appointments/helpers";
import UpcomingAppointments from "@/components/dashboard/appointments/upcomingAppointments";
import Navbar from "@/components/navbar";
import TopBar from "@/components/topbar";
import Link from "next/link";
import { useContext, useState } from "react";
import { createContext, useContext, useState } from "react";
import Calendar from "react-calendar";
import "react-calendar/dist/Calendar.css";
import { AuthContext } from "../layout";

type ValuePiece = Date | null;
type DateValue = ValuePiece | [ValuePiece, ValuePiece];
export const AppointmentCalendarContext = createContext<{
date: DateValue;
setDate: (date: DateValue) => void;
}>({
date: new Date(),
setDate: () => {},
});

export default function AppointmentsPage() {
const currentUser = useContext(AuthContext);
const [date, setDate] = useState<DateValue>(new Date());

return (
<main className=" bg-primary-500 flex">
<div className="py-[30px] w-[230px]">
<Navbar />
</div>
<div className="bg-[#F8F8F8] p-8 rounded-l-[50px] w-full overflow-hidden">
<TopBar
firstName={currentUser?.firstName ?? ""}
image={currentUser?.image ?? ""}
/>
<div className="flex mb-12 mt-6 gap-8">
<div className="col flex-[2] overflow-hidden flex flex-col">
<h1 className="text-xl mb-6">
Good morning &nbsp;
<span className="font-semibold text-3xl text-primary-500">
Dr. {currentUser?.firstName}!
</span>
</h1>
<UpcomingAppointments />
</div>
<div className="col max-w-[320px]">
<div className="bg-white rounded-xl shadow-md p-5 mb-3">
<div className="flex justify-between items-center mb-3">
<h5 className="font-semibold">Calendar</h5>
<svg
width="18"
height="18"
viewBox="0 0 18 18"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M4.73976 7.68237C5.08716 7.3325 5.65273 7.3315 6.00137 7.68014L8.68446 10.3632C9.10984 10.7886 9.79952 10.7886 10.2249 10.3632L12.908 7.68014C13.2566 7.3315 13.8222 7.3325 14.1696 7.68237V7.68237C14.5153 8.0305 14.5143 8.59263 14.1674 8.93953L10.2249 12.882C9.79952 13.3074 9.10984 13.3074 8.68446 12.882L4.74198 8.93953C4.39507 8.59263 4.39408 8.0305 4.73976 7.68237V7.68237Z"
fill="#5F647E"
/>
</svg>
</div>
<div>
<Calendar
className={"calendar"}
locale="en-US"
onChange={setDate}
/>
</div>
<div className="flex justify-between items-center pt-4">
<p className="font-bold">Upcoming</p>
<Link
href={""}
className="text-[12px] text-[#1A71FF] mr-[10px]"
>
View all
</Link>
</div>
<div className="flex gap-[30px] items-center mt-[20px] p-1 bg-[#F0F9FD] rounded-xl">
<div className="ml-1 p-2 bg-gradient-to-tr from-[#1A71FF45] to-[#1A71FF] rounded-full h-[40px] w-[40px] flex items-center justify-center">
<p className="font-bold text-white">M</p>
<AppointmentCalendarContext.Provider value={{ date, setDate }}>
<main className=" bg-primary-500 flex">
<div className="py-[30px] w-[230px]">
<Navbar />
</div>
<div className="bg-[#F8F8F8] p-8 rounded-l-[50px] w-full overflow-hidden">
<TopBar
firstName={currentUser?.firstName ?? ""}
image={currentUser?.image ?? ""}
/>
<div className="flex mb-12 mt-6 gap-8">
<div className="col flex-[2] overflow-hidden flex flex-col">
<h1 className="text-xl mb-6">
Good morning &nbsp;
<span className="font-semibold text-3xl text-primary-500">
Dr. {currentUser?.firstName}!
</span>
</h1>
<UpcomingAppointments />
</div>
<div className="col max-w-[320px]">
<div className="bg-white rounded-xl shadow-md p-5 mb-3">
<div className="flex justify-between items-center mb-3">
<h5 className="font-semibold">Calendar</h5>
<svg
width="18"
height="18"
viewBox="0 0 18 18"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M4.73976 7.68237C5.08716 7.3325 5.65273 7.3315 6.00137 7.68014L8.68446 10.3632C9.10984 10.7886 9.79952 10.7886 10.2249 10.3632L12.908 7.68014C13.2566 7.3315 13.8222 7.3325 14.1696 7.68237V7.68237C14.5153 8.0305 14.5143 8.59263 14.1674 8.93953L10.2249 12.882C9.79952 13.3074 9.10984 13.3074 8.68446 12.882L4.74198 8.93953C4.39507 8.59263 4.39408 8.0305 4.73976 7.68237V7.68237Z"
fill="#5F647E"
/>
</svg>
</div>
<div>
<p className="text-[14px] font-semibold">
Monthly doctor's meet
</p>
<p className="text-[12px] text-[#0D0D0D60]">
8 April, 2021 | 04:00 PM
</p>
<Calendar
className={"calendar"}
locale="en-US"
onChange={setDate}
/>
</div>
<div className="flex justify-between items-center pt-4">
<p className="font-bold">Upcoming</p>
<Link
href={""}
className="text-[12px] text-[#1A71FF] mr-[10px]"
>
View all
</Link>
</div>
<div className="flex gap-[30px] items-center mt-[20px] p-1 bg-[#F0F9FD] rounded-xl">
<div className="ml-1 p-2 bg-gradient-to-tr from-[#1A71FF45] to-[#1A71FF] rounded-full h-[40px] w-[40px] flex items-center justify-center">
<p className="font-bold text-white">M</p>
</div>
<div>
<p className="text-[14px] font-semibold">
Monthly doctor's meet
</p>
<p className="text-[12px] text-[#0D0D0D60]">
8 April, 2021 | 04:00 PM
</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div className="flex gap-8 mb-8">
<div className="col flex-[1] overflow-hidden">
<AppointmentRequests />
</div>
<div className="col flex-[1] overflow-hidden">
<CancelledAppointments />
<div className="flex gap-8 mb-8">
<div className="col flex-[1] overflow-hidden">
<AppointmentRequests />
</div>
<div className="col flex-[1] overflow-hidden">
<CancelledAppointments />
</div>
</div>
</div>
</div>
</main>
</main>
</AppointmentCalendarContext.Provider>
);
}
42 changes: 23 additions & 19 deletions components/MainSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import "react-calendar/dist/Calendar.css";
import {
Appointment,
getColorByPackage,
Patient,
} from "./dashboard/appointments/upcomingAppointments";
getDate,
getPatientName,
} from "./dashboard/appointments/helpers";
import ListItem from "./listItem";
import Loading from "./Loading";
import TopBar from "./topbar";

type ValuePiece = Date | null;
Expand All @@ -20,12 +22,12 @@ type Value = ValuePiece | [ValuePiece, ValuePiece];
export default function MainSection() {
const currentUser = useContext(AuthContext);
const [appointments, setAppointments] = useState<Appointment[]>([]);

const getPatientName = (patient: Patient) =>
patient.full_name + " " + patient.nickname;
const [date, setDate] = useState<Value>(new Date());
const [loading, setLoading] = useState(true);

useEffect(() => {
if (!currentUser) return;
setLoading(true);
const supabase = createClient();
const fetchAppointments = async () => {
const { data, error } = await supabase
Expand All @@ -35,10 +37,12 @@ export default function MainSection() {
)
.eq("doctor_id", currentUser.id)
.eq("status", "Approved")
.gt("appointment_date", new Date().toISOString())
.gt("appointment_date", getDate(date).toISOString())
.order("appointment_date", { ascending: true })
.limit(5);

setLoading(false);

if (error) {
console.log(error);
}
Expand All @@ -48,9 +52,7 @@ export default function MainSection() {
}
};
fetchAppointments();
}, [currentUser]);

const [dateValue, setDateValue] = useState<Value>(new Date());
}, [currentUser, date]);

return (
<div className="bg-[#F8F8F8] rounded-l-[50px] ps-[30px] pt-[30px] overflow-x-hidden w-[100%]">
Expand Down Expand Up @@ -121,22 +123,24 @@ export default function MainSection() {
<div className="w-[50%] max-[720px]:w-[80%] p-2">
<div className="flex justify-between items-center pb-2 text-[18px]">
<p className="font-medium my-2">Upcoming appointments</p>
<div className="flex gap-2 items-center ">
<p className=" text-gray-500 font-light">Today</p>
<Image
src={require("../assets/icons/accordion.svg")}
alt="accordion"
/>
</div>
</div>

<div className="flex flex-col gap-[20px]">
{appointments.length === 0 && (
{loading && appointments.length == 0 && (
<div className="mt-12">
<Loading
loading={loading}
label="Loading upcoming appointments"
/>
</div>
)}
{!loading && appointments.length === 0 && (
<p className="text-center text-gray-500 py-12">
No appointments found
</p>
)}
{appointments.length > 0 &&
{!loading &&
appointments.length > 0 &&
appointments.map((appointment) => (
<ListItem
key={appointment.id}
Expand Down Expand Up @@ -249,7 +253,7 @@ export default function MainSection() {
<Calendar
className={"calendar"}
locale="en-US"
onChange={setDateValue}
onChange={setDate}
/>
</div>
<div className="flex justify-between items-center pt-4">
Expand Down
Loading

0 comments on commit 3c1230c

Please sign in to comment.