Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My patients #24

Merged
merged 19 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions app/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TypographyH2, TypographyP } from "@/components/ui/typography";
import { TypographyP } from "@/components/ui/typography";
import { createServerSupabaseClient } from "@/lib/server-utils";
import { redirect } from "next/navigation";

Expand All @@ -13,14 +13,10 @@ export default async function Dashboard() {
// this is a protected route - only users who are signed in can view this route
redirect("/");
}
const userEmail = session.user.email;

return (
<>
<TypographyH2>Dashboard</TypographyH2>
<TypographyP>This is a protected route accessible only to signed-in users.</TypographyP>
{userEmail && <TypographyP>{`Your email is ${userEmail}`}</TypographyP>}
<br />
<TypographyP>Dashboard, coming soon!</TypographyP>
</>
);
}
2 changes: 1 addition & 1 deletion app/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default async function LoginPage() {
return (
<LoginCard className="sm:w-[350px]">
<div className="flex flex-col space-y-2 text-center">
<h1 className="text-2xl font-semibold tracking-tight">Kinnect</h1>
<h1 className="text-2xl font-semibold tracking-tight">Therable</h1>
</div>
<UserAuthForm />
<div className="flex flex-col space-y-1 text-center">
Expand Down
52 changes: 52 additions & 0 deletions app/my-patients/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import PatientCard from "@/components/patient-card";
import { createServerSupabaseClient } from "@/lib/server-utils";
import { redirect } from "next/navigation";

export default async function MyPatients() {
const supabase = createServerSupabaseClient();
const {
data: { session },
} = await supabase.auth.getSession();

if (!session || session.user.user_metadata.type !== "clinician") {
redirect("/dashboard");
}
const { data: clinician } = await supabase.from("clinicians").select().eq("user_id", session.user.id).single();

// redundant check if clinician irretrievable for some reason
if (!clinician) {
redirect("/dashboard");
}

const { data: clinic } = await supabase.from("clinics").select().eq("owner", clinician.id).single();
const { data: patients } = await supabase
.from("clinic_members")
.select(`*, patients(first_name, last_name)`)
.eq("clinic_id", clinic?.id);

return (
<>
<p className="mb-10 text-2xl">My patients</p>
<div className="grid grid-cols-4 gap-4">
{patients && patients.length > 0 ? (
patients.map((patient, i) => (
<PatientCard
key={i}
userId={patient.id}
firstName={patient.patients ? patient.patients.first_name : "FNU"}
lastName={patient.patients ? patient.patients.last_name : "LNU"}
diagnosis={patient.diagnosis}
lastVisit={new Date()} // placeholder
nextVisit={new Date()} // placeholder
avatar="https://images.pexels.com/photos/771742/pexels-photo-771742.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" // placeholder
/>
))
) : clinic ? (
<p>No patients currently enrolled</p>
) : (
<p>You haven&apos;t created a clinic yet!</p>
)}
</div>
</>
);
}
Loading