Skip to content

Commit

Permalink
#CheckWithTech: Handle error and use appropriate perms check
Browse files Browse the repository at this point in the history
  • Loading branch information
markspolakovs committed Sep 12, 2024
1 parent 8dd2058 commit 782437c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
26 changes: 19 additions & 7 deletions app/(authenticated)/calendar/[eventID]/CheckWithTech.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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={<TbBrandSlack size={14} />}
Expand Down
14 changes: 3 additions & 11 deletions app/(authenticated)/calendar/[eventID]/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit 782437c

Please sign in to comment.