Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add alert on public events to distinguish them #161

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion app/(authenticated)/calendar/[eventID]/EventActionsUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ import {
import { useCallback, useState, useTransition } from "react";
import Image from "next/image";
import AdamRMSLogo from "../../../_assets/adamrms-logo.png";
import { Button, Menu, Modal, Select, Text } from "@mantine/core";
import { Alert, Button, Menu, Modal, Select, Text } from "@mantine/core";
import { useModals } from "@mantine/modals";
import { useRouter } from "next/navigation";
import { PermissionGate } from "@/components/UserContext";
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
import type { Project } from "@/lib/adamrms";
import { TbAlertTriangle } from "react-icons/tb";

function EditModal(props: { event: EventObjectType; close: () => void }) {
return (
Expand Down Expand Up @@ -57,6 +58,18 @@ function EditModal(props: { event: EventObjectType; close: () => void }) {
{/*<CheckBoxField name="is_private" label="Private Event" />*/}
<br />
<CheckBoxField name="is_tentative" label="Tentative Event" />
{props.event.event_type === "public" && (
<Alert
variant="light"
color="orange"
icon={<TbAlertTriangle />}
title="Public Event"
className="mt-4"
>
This event is public. Its details can be seen by anyone outside YSTV{" "}
and any changes are immediately published.
</Alert>
)}
</Form>
);
}
Expand Down
11 changes: 11 additions & 0 deletions app/(authenticated)/calendar/[eventID]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,17 @@ export default async function EventPage({
<SlackBanner event={event} />
</Suspense>
)}
{event.event_type === "public" && canManageAnySignupSheet(event, me) && (
<Alert
variant="light"
color="orange"
icon={<TbAlertTriangle />}
title="Public Event"
>
This event is public. Its details can be seen by anyone outside YSTV{" "}
and any changes are immediately published.
</Alert>
)}
<div
className={
"flex w-full flex-col items-center justify-between sm:flex-row"
Expand Down
16 changes: 15 additions & 1 deletion app/(authenticated)/calendar/new/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import {
import { useRouter } from "next/navigation";
import { EventType } from "@/features/calendar/types";
import { identity } from "lodash";
import { InputLabel } from "@mantine/core";
import { Alert, InputLabel } from "@mantine/core";
import SlackChannelField from "@/components/SlackChannelField";
import { useSlackEnabled } from "@/components/slack/SlackEnabledProvider";
import { useCurrentUser } from "@/components/UserContext";
import { TbAlertTriangle } from "react-icons/tb";

export function CreateEventForm(props: {
action: FormAction<{ id: number }>;
Expand Down Expand Up @@ -52,6 +53,19 @@ export function CreateEventForm(props: {
>
<SearchedMemberSelect name="host" label="Host" />
</ConditionalField>
<ConditionalField
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick but a bit of space between this and the segmented select above it would be good

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bosh

referencedFieldName="type"
condition={(t) => t === "public"}
>
<Alert
color="orange"
icon={<TbAlertTriangle />}
title="Public Event"
className="mt-1"
>
The details of this event will be visible to anyone outside YSTV.
</Alert>
</ConditionalField>
{/*<br />*/}
{/*<CheckBoxField name="private" label="Private Event" />*/}
{isSlackEnabled && (
Expand Down
4 changes: 2 additions & 2 deletions components/FormFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,14 @@ export function ConditionalField<
>(props: {
referencedFieldName: TField;
condition: (data: TSchema[TField]) => boolean;
childFieldName: string;
childFieldName?: string;
children: ReactNode;
}) {
const ctx = useFormContext<TSchema>();
const referencedField = ctx.watch(props.referencedFieldName);
const shouldShow = props.condition(referencedField);
useEffect(() => {
if (!shouldShow) {
if (!shouldShow && props.childFieldName) {
// @ts-expect-error - otherwise you get errors if referencedFieldName and childFieldName don't match
ctx.setValue(props.childFieldName, undefined as any);
}
Expand Down
Loading