Skip to content

Commit 97665a8

Browse files
committed
update
1 parent 31df00a commit 97665a8

File tree

3 files changed

+102
-3
lines changed

3 files changed

+102
-3
lines changed

app/pages/rides/[id].vue

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
}
9999
}
100100
101-
async function handleVolunteerAction(action: 'signup' | 'complete') {
101+
async function handleVolunteerAction(action: 'signup' | 'unsignup' | 'complete') {
102102
if (action === 'signup') {
103103
try {
104104
await $fetch(`/api/post/rides/${id}/signup`, { method: 'POST' })
@@ -114,6 +114,21 @@
114114
return
115115
}
116116
117+
if (action === 'unsignup') {
118+
try {
119+
await $fetch(`/api/post/rides/${id}/unsignup`, { method: 'POST' })
120+
toast.add({
121+
title: 'Success',
122+
description: 'You have unsigned from this ride',
123+
color: 'success',
124+
})
125+
await refreshRide()
126+
} catch (e) {
127+
toast.add({ title: 'Error', description: 'Failed to unsign up', color: 'error' })
128+
}
129+
return
130+
}
131+
117132
if (action === 'complete') {
118133
isCompleteModalOpen.value = true
119134
}
@@ -230,6 +245,15 @@
230245
class="flex-1 justify-center"
231246
@click="handleVolunteerAction('signup')"
232247
/>
248+
<UButton
249+
v-if="isVolunteer && isAssignedToMe && ride.status === 'ASSIGNED'"
250+
label="Unsign Up"
251+
icon="i-lucide-user-minus"
252+
color="warning"
253+
variant="subtle"
254+
class="flex-1 justify-center"
255+
@click="handleVolunteerAction('unsignup')"
256+
/>
233257
<UButton
234258
v-if="isVolunteer && isAssignedToMe && ride.status === 'ASSIGNED'"
235259
label="Mark as Completed"
@@ -320,7 +344,7 @@
320344
<UTextarea v-model="editState.notes" class="w-full" :disabled="!isAdmin" />
321345
</UFormField>
322346

323-
<UFormField label="Total Ride Time (Hours)" name="totalRideTime" v-if="ride.status === 'COMPLETED' || isAdmin">
347+
<UFormField label="Total Ride Time (Hours)" name="totalRideTime" v-if="ride?.status === 'COMPLETED' || isAdmin">
324348
<UInput v-model.number="editState.totalRideTime" type="number" step="0.1" class="w-full" />
325349
</UFormField>
326350

notes/notifs.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
- a new volunteer is created
55
- send to created volunteer
66
- when a volunteer signs up for a ride
7-
- sent to admins
7+
- sent to all admins
88
- sent to volunteer who signed up
9+
- when a volunteer un sign ups for a ride
10+
- send to all admins
11+
- send to volunteers who un signed up
912
- when a volunteer completed a ride
1013
- sent to admins
1114
- sent to volunteer who completed the ride
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { prisma } from '../../../../utils/prisma'
2+
import { auth } from '../../../../utils/auth'
3+
4+
export default defineEventHandler(async (event) => {
5+
const id = getRouterParam(event, 'id')
6+
const session = await auth.api.getSession({
7+
headers: event.headers
8+
})
9+
10+
if (!session) {
11+
throw createError({
12+
statusCode: 401,
13+
statusMessage: 'Unauthorized',
14+
})
15+
}
16+
17+
const user = session.user
18+
19+
if (!id) {
20+
throw createError({
21+
statusCode: 400,
22+
statusMessage: 'Ride ID is required',
23+
})
24+
}
25+
26+
// 1. Get Volunteer profile
27+
const volunteer = await prisma.volunteer.findUnique({
28+
where: { userId: user.id }
29+
})
30+
31+
if (!volunteer) {
32+
throw createError({
33+
statusCode: 403,
34+
statusMessage: 'You must be a registered volunteer to unsign up.',
35+
})
36+
}
37+
38+
// 2. Check Ride status and assignment
39+
const ride = await prisma.ride.findUnique({
40+
where: { id }
41+
})
42+
43+
if (!ride) {
44+
throw createError({
45+
statusCode: 404,
46+
statusMessage: 'Ride not found',
47+
})
48+
}
49+
50+
if (ride.volunteerId !== volunteer.id) {
51+
throw createError({
52+
statusCode: 403,
53+
statusMessage: 'You are not assigned to this ride.',
54+
})
55+
}
56+
57+
if (ride.status !== 'ASSIGNED') {
58+
throw createError({
59+
statusCode: 400,
60+
statusMessage: 'Ride cannot be unsigned from in its current state.',
61+
})
62+
}
63+
64+
// 3. Unassign Volunteer
65+
return await prisma.ride.update({
66+
where: { id },
67+
data: {
68+
volunteerId: null,
69+
status: 'CREATED'
70+
}
71+
})
72+
})

0 commit comments

Comments
 (0)