Skip to content

Commit fda2af8

Browse files
johnny-t06wkim10
andauthored
Dashboard "Event"/Timeslot Card Updates (#121)
* Refactored EventCard * Gap changes * Route Admin/Volunteer * eslint fix * add fetching hours/days logic and small changes to header and communications page * eslint fixes --------- Co-authored-by: wkim10 <wonkim025@gmail.com>
1 parent 914193f commit fda2af8

13 files changed

Lines changed: 358 additions & 235 deletions

File tree

package-lock.json

Lines changed: 18 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/locales/en/home.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"welcome_title": "Thanks for checking in",
33
"welcome_subtitle": "What's the next event you want to join",
4-
"upcoming_events": "Upcoming events",
4+
"upcoming_times": "Your upcoming volunteer times",
55
"volunteer_hours": "Personal volunteer hours",
66
"events_attended": "Events attended"
77
}

public/locales/es/home.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"welcome_title": "Gracias por visitar nuestro sitio",
33
"welcome_subtitle": "¿Cuál es el próximo evento al que quieres unirte?",
4-
"upcoming_events": "Próximos eventos",
4+
"upcoming_times": "Tus próximos tiempos de voluntariado",
55
"volunteer_hours": "Horas de voluntariado",
66
"events_attended": "Eventos asistidos"
77
}

src/app/api/timeSlot/route.client.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,21 @@ export const addTimeSlot = async (
5151
}
5252
) => fetchApi("/api/timeSlot", "POST", { timeSlot, groupSignupInfo });
5353

54+
export const getTimeSlots = async (userId: string) => {
55+
const url = `/api/timeSlot?userId=${userId}`;
56+
return fetchApi(url, "GET");
57+
};
58+
5459
export const getTimeSlotsByDate = async (userId: string, date: Date) => {
5560
const isoDate = date.toISOString().split("T")[0];
56-
const url = userId
57-
? `/api/timeSlot?userId=${userId}&date=${isoDate}`
58-
: `/api/timeSlot?date=${isoDate}`;
59-
61+
const url = `/api/timeSlot?userId=${userId}&date=${isoDate}`;
6062
return fetchApi(url, "GET");
6163
};
6264

65+
export const getTimeSlotsByStatus = async (status: string) => {
66+
const url = `/api/timeSlot?status=${status}`;
67+
return fetchApi(url, "GET");
68+
};
6369
export const deleteTimeSlot = async (
6470
userId: string,
6571
startTime: Date,

src/app/api/timeSlot/route.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PrismaClient } from "@prisma/client";
1+
import { PrismaClient, TimeSlotStatus } from "@prisma/client";
22
import { NextRequest, NextResponse } from "next/server";
33
import { sendGroupSignupMail } from "../../../lib/groupSignupMail";
44

@@ -47,10 +47,11 @@ export const POST = async (request: NextRequest) => {
4747
export const GET = async (request: NextRequest) => {
4848
const { searchParams } = new URL(request.url);
4949

50-
const userId = searchParams.get("userId");
51-
const date = searchParams.get("date");
50+
const userId: string | undefined = searchParams.get("userId") || undefined;
51+
const date: string | undefined = searchParams.get("date") || undefined;
52+
const status: string | undefined = searchParams.get("status") || undefined;
5253

53-
if (!userId || !date) {
54+
if (!userId && !date && !status) {
5455
return NextResponse.json(
5556
{
5657
code: "BAD_REQUEST",
@@ -60,23 +61,19 @@ export const GET = async (request: NextRequest) => {
6061
);
6162
}
6263

63-
const [year, month, day] = date.split("-").map(Number);
64-
const start = new Date(year, month - 1, day);
65-
start.setHours(0, 0, 0, 0);
66-
const end = new Date(start);
67-
end.setDate(start.getDate() + 1);
68-
6964
try {
7065
const slots = await prisma.timeSlot.findMany({
7166
where: {
72-
userId,
73-
date: {
74-
gte: start,
75-
lt: end,
76-
},
67+
...(userId && { userId }),
68+
...(date && {
69+
date: {
70+
gte: new Date(date),
71+
lt: new Date(new Date(date).setDate(new Date(date).getDate() + 1)),
72+
},
73+
}),
74+
...(status && { status: status as TimeSlotStatus }),
7775
},
7876
});
79-
8077
return NextResponse.json(
8178
{
8279
code: "SUCCESS",

src/app/api/volunteerSession/route.client.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,8 @@ export const getVolunteerSessions = async (userId: string) => {
5151
const url = `/api/volunteerSession?userId=${userId}`;
5252
return fetchApi(url, "GET");
5353
};
54+
55+
export const getAllVolunteerSessions = async () => {
56+
const url = `/api/volunteerSession`;
57+
return fetchApi(url, "GET");
58+
};

src/app/api/volunteerSession/route.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,36 @@ export const GET = async (request: NextRequest) => {
113113
const { searchParams } = new URL(request.url);
114114
const userId: string | undefined = searchParams.get("userId") || undefined;
115115

116-
if (!userId) {
117-
return NextResponse.json(
118-
{
119-
code: "BAD_REQUEST",
120-
message: "User ID is required.",
121-
},
122-
{
123-
status: 400,
116+
try {
117+
if (userId) {
118+
const volunteerSessions = await prisma.volunteerSession.findMany({
119+
where: {
120+
userId: userId,
121+
NOT: [{ checkOutTime: null }, { durationHours: null }],
122+
},
123+
});
124+
125+
if (!volunteerSessions) {
126+
return NextResponse.json(
127+
{
128+
code: "NOT_FOUND",
129+
message: "No volunteer sessions found",
130+
},
131+
{ status: 404 }
132+
);
124133
}
125-
);
126-
}
127134

128-
try {
135+
return NextResponse.json(
136+
{
137+
code: "SUCCESS",
138+
data: volunteerSessions,
139+
},
140+
{ status: 200 }
141+
);
142+
}
143+
129144
const volunteerSessions = await prisma.volunteerSession.findMany({
130145
where: {
131-
userId: userId,
132146
NOT: [{ checkOutTime: null }, { durationHours: null }],
133147
},
134148
});

src/app/private/communication/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ export default function CommunicationPage() {
197197
placeholder="Type your email content"
198198
value={text}
199199
onChange={(e) => setText(e.target.value)}
200+
rows={10}
200201
/>
201202
</div>
202203
</div>

src/app/private/events/page.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ import {
1515
} from "@api/timeSlot/route.client";
1616
import VolunteerTable from "@components/VolunteerTable";
1717
import { getUsersByDate } from "@api/user/route.client";
18+
import { useSearchParams } from "next/navigation";
19+
import { getStandardDate } from "../../utils";
1820
import { getCustomDay } from "@api/customDay/route.client";
1921

2022
export default function EventsPage() {
2123
const { data: session } = useSession();
24+
const searchParams = useSearchParams();
25+
const date = searchParams.get("date");
2226

2327
const [selectedDate, setSelectedDate] = React.useState<Date | undefined>(
24-
new Date()
28+
getStandardDate(date ?? "")
2529
);
2630
const [timeSlots, setTimeSlots] = React.useState([
2731
{ start: "", end: "", submitted: false },

0 commit comments

Comments
 (0)