Skip to content

Commit c615240

Browse files
authored
Merge pull request #20 from atlp-rwanda/ft-doctors-messaging
Feature: Doctors messaging first
2 parents 095cc78 + 1392d5c commit c615240

File tree

5 files changed

+73
-22
lines changed

5 files changed

+73
-22
lines changed

Diff for: .github/workflows/deploy.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Deployment Pipeline
1+
name: Deployment Pipeline
22
on:
33
push:
44
branches:
@@ -10,6 +10,8 @@ jobs:
1010
steps:
1111
- uses: actions/checkout@v4
1212
- uses: superfly/flyctl-actions/setup-flyctl@master
13-
- run: flyctl deploy --remote-only
13+
- run: flyctl deploy --remote-only --build-arg NEXT_PUBLIC_SUPABASE_URL=$NEXT_PUBLIC_SUPABASE_URL --build-arg NEXT_PUBLIC_SUPABASE_ANON_KEY=$NEXT_PUBLIC_SUPABASE_ANON_KEY
1414
env:
15-
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
15+
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
16+
NEXT_PUBLIC_SUPABASE_URL: ${{ secrets.NEXT_PUBLIC_SUPABASE_URL }}
17+
NEXT_PUBLIC_SUPABASE_ANON_KEY: ${{ secrets.NEXT_PUBLIC_SUPABASE_ANON_KEY }}

Diff for: app/dashboard/messages/page.tsx

+48-15
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import MessagesMain from "@/components/messages/messagesSection";
33
import Navbar from "@/components/navbar";
44
import { createClient } from "@/utils/supabase/client";
55
import { useRouter } from "next/navigation";
6-
import { useContext, useEffect, useState } from "react";
6+
import { Suspense, useContext, useEffect, useState } from "react";
77
import { AuthContext } from "../layout";
8-
8+
import { useSearchParams } from "next/navigation";
99
export interface AppointmentType {
1010
id: string;
1111
patient_id: string;
@@ -34,12 +34,13 @@ export interface MessageType {
3434
};
3535
}
3636

37-
export default function Messages() {
37+
function Messages() {
3838
const router = useRouter();
3939
const currentUser = useContext(AuthContext);
4040
const [willRefresh, setwillRefresh] = useState<number>(0);
4141
const [messages, setMessages] = useState<MessageType[]>([]);
42-
42+
const searchParams = useSearchParams();
43+
const appointmentId = searchParams.get('id');
4344
const fetchAppointments = async (
4445
userId: string
4546
): Promise<AppointmentType[]> => {
@@ -52,7 +53,19 @@ export default function Messages() {
5253
if (error) throw error;
5354
return data;
5455
};
56+
const sendInitialMessage = async (appointmentId: string, doctorId: string) => {
57+
const supabase = createClient();
58+
const { error } = await supabase
59+
.from("messages")
60+
.insert({
61+
message: "Hello?",
62+
type: "message",
63+
sender_id: doctorId,
64+
appointment_id: appointmentId
65+
});
5566

67+
if (error) throw error;
68+
};
5669
const fetchMessages = async (
5770
appointmentId: string
5871
): Promise<MessageType[]> => {
@@ -66,7 +79,7 @@ export default function Messages() {
6679
.order("created_at", { ascending: true });
6780

6881
if (error) throw error;
69-
console.log(data);
82+
// console.log(data);
7083
return data;
7184
};
7285

@@ -87,7 +100,19 @@ export default function Messages() {
87100
};
88101
fetchAllData();
89102
}, [willRefresh, currentUser]);
90-
103+
useEffect(() => {
104+
const writeInitial=async()=>{
105+
if (appointmentId) {
106+
const currentMessages = await fetchMessages(appointmentId);
107+
if (currentMessages.length === 0) {
108+
await sendInitialMessage(appointmentId, currentUser?.id!);
109+
return;
110+
// setMessages(await fetchMessages(appointmentId));
111+
}
112+
}
113+
}
114+
writeInitial();
115+
}, [])
91116
useEffect(() => {
92117
const supabase = createClient();
93118
const createChannel = supabase
@@ -106,16 +131,24 @@ export default function Messages() {
106131
return () => {
107132
supabase.removeChannel(createChannel);
108133
};
109-
}, []);
134+
}, [router]);
110135

111136
return (
112-
<main className="bg-[#246BFD] flex">
113-
<div className="my-[30px] w-fit">
114-
<Navbar />
115-
</div>
116-
<div className="w-full h-[100vh]">
117-
<MessagesMain messages={messages} />
118-
</div>
119-
</main>
137+
<main className="bg-[#246BFD] flex">
138+
<div className="my-[30px] w-fit">
139+
<Navbar />
140+
</div>
141+
<div className="w-full h-[100vh]">
142+
<MessagesMain messages={messages} />
143+
</div>
144+
</main>
145+
120146
);
121147
}
148+
export default function FixedMessages(){
149+
return (
150+
<Suspense fallback={<p>Loading...</p>}>
151+
<Messages />
152+
</Suspense>
153+
)
154+
}

Diff for: components/dashboard/appointments/upcomingAppointments.tsx

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import { AuthContext } from "@/app/dashboard/layout";
22
import Loading from "@/components/Loading";
33
import { createClient } from "@/utils/supabase/client";
4+
import { UUID } from "crypto";
5+
46
import { useContext, useEffect, useState } from "react";
7+
import { redirectTo } from "@/utils/supabase/getUser";
58
import {
69
Appointment,
710
AppointmentCalendarContext,
811
getAppointmentTime,
912
getColorByPackage,
1013
getDate,
1114
getPatientName,
15+
Patient,
1216
} from "./helpers";
1317

1418
export default function UpcomingAppointments() {
@@ -19,7 +23,12 @@ export default function UpcomingAppointments() {
1923
useState<Appointment | null>(null);
2024
const [updating, setUpdating] = useState(false);
2125
const [loading, setLoading] = useState(true);
22-
26+
const getPatientName = (patient: Patient) =>
27+
patient.full_name + " " + patient.nickname;
28+
const getAppointmentTime = (time: string) => {
29+
const [hours, minutes] = time.split(":");
30+
return `${hours}:${minutes} ${parseInt(hours) >= 12 ? "PM" : "AM"}`;
31+
};
2332
useEffect(() => {
2433
if (!currentUser) return;
2534
const supabase = createClient();
@@ -195,7 +204,7 @@ export default function UpcomingAppointments() {
195204
<button className="bg-primary-500 border border-primary-500 text-white px-4 py-0.5 rounded-full hover:bg-primary-700 transition-colors">
196205
Reschedule
197206
</button>
198-
<button className="bg-primary-500 border border-primary-500 text-white px-4 py-0.5 rounded-full hover:bg-primary-700 transition-colors">
207+
<button onClick={()=>redirectTo(appointment.id)}className="bg-primary-500 border border-primary-500 text-white px-4 py-0.5 rounded-full hover:bg-primary-700 transition-colors">
199208
Join
200209
</button>
201210
</div>

Diff for: components/messages/messagesSection.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default function MessagesMain({ messages }: MessageProps) {
1414
const [appDate, setAppDate] = useState<string>("");
1515
const [appTime, setAppTime] = useState<string>("");
1616
const [isEnded, setIsEnded] = useState<boolean>(false);
17+
const [searchTerm, setSearchTerm] = useState<string>("");
1718
const handleChanges = (
1819
str: string,
1920
appId: string,
@@ -83,6 +84,7 @@ export default function MessagesMain({ messages }: MessageProps) {
8384
<input
8485
placeholder="Search"
8586
className="border-[1px] w-full p-2 rounded-xl bg-[#E5E5E5]"
87+
onChange={(e) => setSearchTerm(e.target.value.toLowerCase())}
8688
/>
8789
<div className="absolute right-2 top-1/2 transform -translate-y-1/2">
8890
<Image
@@ -96,7 +98,8 @@ export default function MessagesMain({ messages }: MessageProps) {
9698
</div>
9799
</div>
98100
<div className="flex-1 justify-between overflow-y-auto px-[30px] py-[20px]">
99-
{groupedMessages.map((message) => (
101+
{groupedMessages.filter((message)=>message.appointment.patient.full_name.toLowerCase().includes(searchTerm))
102+
.map((message) => (
100103
<button
101104
key={message.id}
102105
className="w-full"
@@ -223,7 +226,7 @@ export default function MessagesMain({ messages }: MessageProps) {
223226
{isEnded ? (
224227
<div className="flex justify-center p-[30px]">
225228
<div className="p-2 bg-gray-300 rounded-md w-fit">
226-
<p>Session ended</p>
229+
<p>Currently you don't have access to this session</p>
227230
</div>
228231
</div>
229232
) : (

Diff for: utils/supabase/getUser.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use server'
22
import { revalidatePath } from "next/cache";
33
import { createClient } from "./server";
4+
import { redirect } from "next/navigation";
45
const supabase = createClient();
56
export async function getCurrentUser(){
67
const {data, error}= await supabase.auth.getUser();
@@ -15,6 +16,9 @@ export const pathRevalidation=(path:string)=>{
1516
revalidatePath(`/${path}`);
1617

1718
}
19+
export const redirectTo=(id:string)=>{
20+
redirect(`/dashboard/messages/?id=${id}`);
21+
}
1822
// export async function fetchDoctor(userId:string){
1923
// const {data, error}= await supabase.from('doctor')
2024
// }

0 commit comments

Comments
 (0)