From 782437c98734560e87a2931ec3321ab2f39fd9e5 Mon Sep 17 00:00:00 2001 From: Marks Polakovs Date: Thu, 12 Sep 2024 22:10:38 +0100 Subject: [PATCH] #CheckWithTech: Handle error and use appropriate perms check --- .../calendar/[eventID]/CheckWithTech.tsx | 26 ++++++++++++++----- .../calendar/[eventID]/actions.ts | 14 +++------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/app/(authenticated)/calendar/[eventID]/CheckWithTech.tsx b/app/(authenticated)/calendar/[eventID]/CheckWithTech.tsx index b3d675ca..2483dd30 100644 --- a/app/(authenticated)/calendar/[eventID]/CheckWithTech.tsx +++ b/app/(authenticated)/calendar/[eventID]/CheckWithTech.tsx @@ -97,13 +97,25 @@ function PostMessage(props: { loading={isPending} onClick={() => startTransition(async () => { - await doCheckWithTech(props.eventID, memo, props.isConfident); - notifications.show({ - title: "Sent!", - message: - "Keep an eye out on Slack in case the tech team need any further details.", - }); - props.done(); + const result = await doCheckWithTech( + props.eventID, + memo, + props.isConfident, + ); + if (result.ok) { + notifications.show({ + title: "Sent!", + message: + "Keep an eye out on Slack in case the tech team need any further details.", + }); + props.done(); + } else { + notifications.show({ + title: "Sorry, something went wrong...", + message: result.errors?.root ?? "Please try again later.", + color: "red", + }); + } }) } leftSection={} diff --git a/app/(authenticated)/calendar/[eventID]/actions.ts b/app/(authenticated)/calendar/[eventID]/actions.ts index 0c095a8d..66eaed6e 100644 --- a/app/(authenticated)/calendar/[eventID]/actions.ts +++ b/app/(authenticated)/calendar/[eventID]/actions.ts @@ -9,19 +9,11 @@ import { z } from "zod"; import { AttendStatus, AttendStatuses } from "@/features/calendar/statuses"; import * as Calendar from "@/features/calendar"; import { EventType, hasRSVP } from "@/features/calendar/types"; -import { - canManage, - canManageSignUpSheet, -} from "@/features/calendar/permissions"; +import { canManage } from "@/features/calendar/permissions"; import { zodErrorResponse } from "@/components/FormServerHelpers"; -import { - EditEventSchema, - SignupSheetSchema, -} from "@/app/(authenticated)/calendar/[eventID]/schema"; +import { EditEventSchema } from "@/app/(authenticated)/calendar/[eventID]/schema"; import { FormResponse } from "@/components/Form"; -import { updateSignUpSheet } from "@/features/calendar/signup_sheets"; import { updateEventAttendeeStatus } from "@/features/calendar/events"; -import { isBefore } from "date-fns"; import invariant from "@/lib/invariant"; import slackApiConnection, { isSlackEnabled, @@ -308,7 +300,7 @@ export const doCheckWithTech = wrapServerAction( const event = await Calendar.getEvent(eventID); invariant(event, "Event does not exist"); - if (!canManage(event, me)) { + if (!Calendar.canManageAnySignupSheet(event, me)) { return { ok: false, errors: {