Skip to content

Commit

Permalink
#CheckWithTech: Error handling and correct perms check (#153)
Browse files Browse the repository at this point in the history
* #CheckWithTech: Handle error and use appropriate perms check

* Change check with tech prompt prerequisite to canManageAnySignUpSheet
  • Loading branch information
markspolakovs authored Sep 12, 2024
1 parent 8dd2058 commit 2451d5f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 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
1 change: 1 addition & 0 deletions app/(authenticated)/calendar/[eventID]/SignupSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ export function SignupSheetsView({
!event.is_cancelled &&
dayjs(event.start_date).isAfter(new Date()) &&
(event.created_by === me.user_id ? (
// No need for this to be a canManageAnySignUpSheet, because there isn't one yet
<Alert
variant="light"
color="blue"
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
2 changes: 1 addition & 1 deletion app/(authenticated)/calendar/[eventID]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ async function CheckWithTechPrompt({
event: EventObjectType;
me: UserType;
}) {
if (me.user_id !== event.host) {
if (!canManageAnySignupSheet(event, me)) {
return null;
}
if (event.adam_rms_project_id || event.check_with_tech_status) {
Expand Down

0 comments on commit 2451d5f

Please sign in to comment.