Skip to content

Commit 53c0e2f

Browse files
committed
delete rsvp request and rsvp when user selects 'not going'; use priorityemails for all rsvp types
1 parent d370c43 commit 53c0e2f

File tree

4 files changed

+37
-12
lines changed

4 files changed

+37
-12
lines changed

src/app/api/approval/rsvp/route.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ export async function POST(req: NextRequest) {
154154

155155
// Send notification emails to proposers
156156
try {
157-
// Import the priority queue function
158-
const { queuePriorityEmail } = await import("src/lib/queue");
157+
// Import the immediate priority email function
158+
const { sendPriorityEmailImmediately } = await import("src/lib/queue");
159159

160160
// Transform event to match ServerEvent type (using type assertion for compatibility)
161161
const serverEvent = {
@@ -182,15 +182,15 @@ export async function POST(req: NextRequest) {
182182

183183
// Queue as priority emails instead of regular emails
184184
if (proposerEmails.length > 0) {
185-
await queuePriorityEmail({
185+
await sendPriorityEmailImmediately({
186186
event: serverEvent,
187187
creatorId: undefined, // No specific creator for approval requests
188188
proposerEmails: proposerEmails,
189189
attendeeEmails: [], // No attendee emails for approval requests
190190
});
191191

192192
console.log(
193-
`Queued ${proposerEmails.length} approval request emails as priority`
193+
`Sent ${proposerEmails.length} approval request emails immediately as priority`
194194
);
195195
}
196196
} catch (emailError) {
@@ -370,7 +370,7 @@ export async function PUT(req: NextRequest) {
370370
// Send notification email to the requester
371371
try {
372372
if (updatedRequest.user.email) {
373-
const { queuePriorityEmail } = await import("src/lib/queue");
373+
const { sendPriorityEmailImmediately } = await import("src/lib/queue");
374374

375375
const emailType =
376376
status === "APPROVED" ? "approval-approved" : "approval-rejected";
@@ -402,16 +402,16 @@ export async function PUT(req: NextRequest) {
402402
: undefined,
403403
};
404404

405-
// Queue as priority email
406-
await queuePriorityEmail({
405+
// Send as immediate priority email
406+
await sendPriorityEmailImmediately({
407407
event: serverEvent,
408408
creatorId: undefined,
409409
proposerEmails: [], // No proposer emails for responses
410410
attendeeEmails: [requesterEmail], // Send to the requester
411411
});
412412

413413
console.log(
414-
`Queued approval ${status.toLowerCase()} email as priority`
414+
`Sent approval ${status.toLowerCase()} email immediately as priority`
415415
);
416416
}
417417
} catch (emailError) {

src/app/api/create/rsvp/route.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ export async function POST(req: NextRequest) {
112112

113113
// 2. Determine state and initialize variables
114114
const eventLimit = event.limit;
115-
const wasGoing = existingRsvp?.rsvpType === RSVP_TYPE.GOING;
115+
const wasGoing =
116+
existingRsvp?.rsvpType === RSVP_TYPE.GOING ||
117+
existingRsvp?.rsvpType === RSVP_TYPE.MAYBE;
116118
const isNowGoing = rsvp.type === RSVP_TYPE.GOING;
117119
const isChangingToMaybeOrNotGoing =
118120
rsvp.type === RSVP_TYPE.MAYBE || rsvp.type === RSVP_TYPE.NOT_GOING;

src/components/EventPage/EventWrapper.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ const EventWrapper = ({
8787
{
8888
onSuccess: (data) => {
8989
console.log("RSVP Update successful in component:", data);
90+
91+
// Handle approval required response
92+
if (data.status === "APPROVAL_REQUIRED") {
93+
console.log("Approval required, opening approval request modal");
94+
setIsConfirmCredenzaOpen(false);
95+
setIsApprovalRequestOpen(true);
96+
return;
97+
}
98+
99+
// Handle normal success
90100
setIsConfirmCredenzaOpen(false);
91101
setPendingRsvpType(null);
92102
},

src/hooks/useUpdateRsvp.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ type RsvpMutationVariables = {
88
};
99

1010
type RsvpApiResponse = {
11-
status: "SUCCESS" | "WAITLISTED";
11+
status: "SUCCESS" | "WAITLISTED" | "APPROVAL_REQUIRED";
1212
eventId: string;
13+
message?: string;
1314
};
1415

1516
const useUpdateRsvp = () => {
@@ -39,14 +40,26 @@ const useUpdateRsvp = () => {
3940
}),
4041
});
4142

43+
const result = await response.json();
44+
45+
// Handle special case where approval is required
4246
if (!response.ok) {
43-
const errorData = await response.json().catch(() => ({}));
47+
// Check if this is an "APPROVAL_REQUIRED" response
48+
if (
49+
response.status === 400 &&
50+
result.data?.status === "APPROVAL_REQUIRED"
51+
) {
52+
// Return the approval required data instead of throwing an error
53+
return result.data;
54+
}
55+
56+
// For other errors, throw as usual
57+
const errorData = result || {};
4458
throw new Error(
4559
errorData?.error || `HTTP error! status: ${response.status}`
4660
);
4761
}
4862

49-
const result = await response.json();
5063
return result.data as RsvpApiResponse;
5164
};
5265

0 commit comments

Comments
 (0)