Skip to content
Open
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
2 changes: 1 addition & 1 deletion apps/admin/src/components/events/EventExpectFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { EventFormValues } from '../../lib/form/event-form';
import { EVENT_HIGHLIGHTS } from '../../types/event';
import { FIELD_INPUT } from '../ui/field-styles';
import { FormField } from '../ui/FormField';
import { HIGHLIGHT_NAMES } from './event-labels';
import { HIGHLIGHT_NAMES } from '../../lib/ui/event-labels';

type EventExpectFieldsProps = {
register: UseFormRegister<EventFormValues>;
Expand Down
1 change: 0 additions & 1 deletion apps/admin/src/components/events/EventForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export function EventForm({ kind, defaultValues, unreadableTime, pictureUrl, sav
register={register}
errors={errors}
format={values.format}
oldLocation={defaultValues.buildingCode === '' ? defaultValues.location : ''}
onFormatChange={(next) => setValue('format', next, { shouldDirty: true })}
/>

Expand Down
12 changes: 3 additions & 9 deletions apps/admin/src/components/events/EventPlaceFields.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Where an event is, on the event form: a switch for an online event, the building and room for an in-person
* one, and the meeting link for an online one. Switching online greys the building and room out, since an online
* event has neither. An old event with no building yet shows its free-text location under the picker.
* event has neither.
*/
import { Link2 } from 'lucide-react';
import type { FieldErrors, UseFormRegister } from 'react-hook-form';
Expand All @@ -16,19 +16,13 @@ type EventPlaceFieldsProps = {
register: UseFormRegister<EventFormValues>;
errors: FieldErrors<EventFormValues>;
format: EventFormat;
/** The saved free-text location of an event that has no building yet, or empty. */
oldLocation: string;
onFormatChange: (format: EventFormat) => void;
};

export function EventPlaceFields({ register, errors, format, oldLocation, onFormatChange }: EventPlaceFieldsProps) {
export function EventPlaceFields({ register, errors, format, onFormatChange }: EventPlaceFieldsProps) {
const buildings = useBuildings();
const online = format === 'online';
const buildingHint = buildings.isError
? "The buildings couldn't be loaded. Reload the page to try again."
: !online && oldLocation
? `Saved as "${oldLocation}". Pick its building to replace it.`
: null;
const buildingHint = buildings.isError ? "The buildings couldn't be loaded. Reload the page to try again." : null;

return (
<fieldset className="grid gap-4">
Expand Down
2 changes: 1 addition & 1 deletion apps/admin/src/components/events/EventResourcesPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { ConfirmDialog } from '../ui/ConfirmDialog';
import { FIELD_INPUT } from '../ui/field-styles';
import { FormField } from '../ui/FormField';
import { Tag } from '../ui/Tag';
import { DOCUMENT_KIND_NAMES } from './event-labels';
import { DOCUMENT_KIND_NAMES } from '../../lib/ui/event-labels';
import { ExtraPanel } from './ExtraPanel';

export function EventResourcesPanel({ eventId }: { eventId: string }) {
Expand Down
2 changes: 1 addition & 1 deletion apps/admin/src/components/events/EventWhenFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { type EventFormValues, lengthOptions } from '../../lib/form/event-form';
import { EVENT_CATEGORIES } from '../../types/event';
import { FIELD_INPUT } from '../ui/field-styles';
import { FormField } from '../ui/FormField';
import { CATEGORY_NAMES } from './event-labels';
import { CATEGORY_NAMES } from '../../lib/ui/event-labels';

type EventWhenFieldsProps = {
register: UseFormRegister<EventFormValues>;
Expand Down
16 changes: 13 additions & 3 deletions apps/admin/src/components/events/ImportTicket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,24 @@ import type { ImportEntry } from '../ui/import-view';
import { importedEvent } from './event-import';
import { Ticket } from './Ticket';

// The values on a ticket's face that a CSV can change; a description is only in the details.
const FACE_FIELDS: readonly (keyof TicketFace)[] = ['title', 'date', 'time', 'location'];
// The values on a ticket's face that a CSV can change, and the columns behind each. The rest (a description, the
// colours) are only in the details.
const FACE_FIELDS = ['title', 'category', 'date', 'time', 'location'] as const satisfies readonly (keyof TicketFace)[];
const FACE_COLUMNS: Readonly<Record<(typeof FACE_FIELDS)[number], readonly string[]>> = {
title: ['title'],
category: ['category'],
date: ['date'],
time: ['start_time', 'end_time'],
location: ['format', 'building_code', 'room'],
};

export function ImportTicket({ entry }: { entry: ImportEntry<Event, EventFields> }) {
const event = importedEvent(entry);
const pictureUrl = entry.kind === 'updated' ? entry.item.after.pictureUrl : null;
const face = toTicketFace({ ...event, pictureUrl });
const marked = new Set(entry.kind === 'updated' ? FACE_FIELDS.filter((key) => entry.item.cells.some((cell) => cell.column === key)) : []);
const marked = new Set(
entry.kind === 'updated' ? FACE_FIELDS.filter((key) => entry.item.cells.some((cell) => FACE_COLUMNS[key].includes(cell.column))) : [],
);
// "Next up" depends on every other event, so an imported one is upcoming or past, like the form's preview.
const status = isUpcoming(event, clubToday()) ? 'upcoming' : 'past';
return <Ticket face={face} status={status} importKind={entry.kind} marked={marked} />;
Expand Down
17 changes: 13 additions & 4 deletions apps/admin/src/components/events/Ticket.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
/**
* An event drawn as a ticket: a date stub coloured by its status, a perforated tear line, the picture, title,
* when and where, and a barcode end. It lays itself out by its own width, not the screen's: a band across the
* top when narrow (a phone, or the ticket printer), a stub on the left when wide. `actions` go at the end of
* the body, like Edit and Delete on the Events list. In a CSV import a ticket also shows its `importKind` (new
* or updated) and puts a highlighter over the `marked` values that will change.
* its kind (a dot in the kind's accent), when and where, and a barcode end. It lays itself out by its own width,
* not the screen's: a band across the top when narrow (a phone, or the ticket printer), a stub on the left when
* wide. `actions` go at the end of the body, like Edit and Delete on the Events list. In a CSV import a ticket also
* shows its `importKind` (new or updated) and puts a highlighter over the `marked` values that will change.
*/
import { Calendar, Clock, ImageIcon, MapPin } from 'lucide-react';
import type { ReactNode } from 'react';
import { formatEventDay } from '../../lib/time/dates';
import { CATEGORY_ACCENTS } from '../../lib/ui/accents';
import { CATEGORY_NAMES } from '../../lib/ui/event-labels';
import type { EventStatus, TicketFace } from '../../types/event';
import { ACCENT_FILLS } from '../ui/accent-styles';
import type { ImportKind } from '../ui/import-labels';
import { Tag, type TagTone } from '../ui/Tag';
import { TicketStub } from './TicketStub';
Expand Down Expand Up @@ -71,6 +74,12 @@ export function Ticket({ face, status, actions, importKind, marked = NOTHING_MAR
<Tag tone={look.tag}>{look.label}</Tag>
</div>
<div className="mt-2 flex flex-wrap gap-x-5 gap-y-1 text-sm text-text-2">
<Detail
icon={<span aria-hidden="true" className={`size-2.5 rounded-full ${ACCENT_FILLS[CATEGORY_ACCENTS[face.category]]}`} />}
marked={marked.has('category')}
>
{CATEGORY_NAMES[face.category]}
</Detail>
<Detail icon={<Calendar aria-hidden="true" className="size-4" />} marked={marked.has('date')}>
{face.date ? formatEventDay(face.date) : 'Day not set'}
</Detail>
Expand Down
53 changes: 46 additions & 7 deletions apps/admin/src/components/events/event-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
* How events read in a CSV import: an event's name, every field in its details, and its lines on the print
* order. The ticket itself is `ImportTicket`.
*/
import { shortEventDay } from '../../lib/time/dates';
import { eventTimeLabel } from '../../lib/form/event-form';
import { shortEventDay } from '../../lib/time/dates';
import { CATEGORY_NAMES, HIGHLIGHT_NAMES } from '../../lib/ui/event-labels';
import { type Event, type EventFields, placeLabel } from '../../types/event';
import type { FieldChange } from '../ui/FieldChanges';
import type { ImportEntry, ImportView, OrderItem } from '../ui/import-view';
Expand All @@ -15,8 +16,22 @@ export function importedEvent(entry: EventEntry): EventFields {
return entry.kind === 'new' ? entry.item.fields : entry.item.after;
}

// What each column is called on the print order, in the words the ticket uses.
const ORDER_LABELS: Readonly<Record<string, string>> = { title: 'title', date: 'date', time: 'time', location: 'room', description: 'description' };
// What each column is called on the print order, in the words the event form uses.
const ORDER_LABELS: Readonly<Record<string, string>> = {
slug: 'link name',
start_time: 'starts',
end_time: 'ends',
format: 'in person or online',
building_code: 'building',
meeting_url: 'meeting link',
stream_url: 'stream link',
dress_code: 'dress code',
primary_colour: 'main colour',
secondary_colour: 'second colour',
};

// Columns too long for a receipt line; the event's details show what changed in them.
const LONG_COLUMNS: ReadonlySet<string> = new Set(['description', 'meeting_url', 'stream_url']);

/** "→ BA201"; an emptied value reads "→ none". */
function becomes(value: string): string {
Expand All @@ -26,11 +41,21 @@ function becomes(value: string): string {
function changeLines(entry: Extract<EventEntry, { kind: 'updated' }>): readonly OrderItem[] {
return entry.item.cells.map(({ column, after }) => ({
label: ORDER_LABELS[column] ?? column,
// A description is too long for a receipt line; the event's details show what changed in it.
value: column === 'description' ? 'edited' : becomes(column === 'date' ? shortEventDay(after) : after),
value: LONG_COLUMNS.has(column) ? (after ? 'edited' : 'removed') : becomes(column === 'date' ? shortEventDay(after) : after),
}));
}

/** "Food, Drinks", or "None". */
function highlightsOf(event: Pick<EventFields, 'highlights'>): string {
return event.highlights.map((highlight) => HIGHLIGHT_NAMES[highlight]).join(', ') || 'None';
}

/** "#ff9770 and #ffd670", or "LCS yellow and pink" when the event uses the default. */
function coloursOf(event: Pick<EventFields, 'primaryColour' | 'secondaryColour'>): string {
if (!event.primaryColour && !event.secondaryColour) return 'LCS yellow and pink';
return [event.primaryColour ?? 'LCS yellow', event.secondaryColour ?? 'LCS pink'].join(' and ');
}

/** A field as the details show it. `before` is left out for a new event, which has nothing to compare. */
function field(label: string, before: string | undefined, after: string): FieldChange {
return { label, before: before ?? null, after };
Expand All @@ -49,7 +74,14 @@ export const EVENT_IMPORT = {
field('Title', was?.title, will.title),
field('Date', was && shortEventDay(was.date), shortEventDay(will.date)),
field('Time', was && (eventTimeLabel(was) ?? 'None'), eventTimeLabel(will) ?? 'None'),
field('Room', was && (placeLabel(was) ?? 'None'), placeLabel(will) ?? 'None'),
field('Category', was && CATEGORY_NAMES[was.category], CATEGORY_NAMES[will.category]),
field('Where', was && (placeLabel(was) ?? 'None'), placeLabel(will) ?? 'None'),
field('Meeting link', was && (was.meetingUrl ?? 'None'), will.meetingUrl ?? 'None'),
field('Stream link', was && (was.streamUrl ?? 'None'), will.streamUrl ?? 'None'),
field('Highlights', was && highlightsOf(was), highlightsOf(will)),
field('Dress code', was && (was.dressCode ?? 'None'), will.dressCode ?? 'None'),
field('Colours', was && coloursOf(was), coloursOf(will)),
field('Link name', was?.slug, will.slug ?? 'Made from the title'),
],
// Only an event with a description, before or after, has one to show.
long:
Expand All @@ -61,6 +93,13 @@ export const EVENT_IMPORT = {
orderItems: (entry) => {
if (entry.kind === 'updated') return changeLines(entry);
const event = entry.item.fields;
return [{ label: [shortEventDay(event.date), eventTimeLabel(event), placeLabel(event)].filter(Boolean).join(' · '), value: '' }];
return [
{
label: [CATEGORY_NAMES[event.category], shortEventDay(event.date), eventTimeLabel(event), placeLabel(event)]
.filter(Boolean)
.join(' · '),
value: '',
},
];
},
} satisfies Omit<ImportView<Event, EventFields>, 'front'>;
22 changes: 22 additions & 0 deletions apps/admin/src/components/guests/CompanyFace.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* A company's logo filling a white circle with a dashed ring in its colour, as a picked speaker's face shows it on
* the site, or its initial when it has no logo yet. The colour is the company's data, so it is set inline.
*/
import type { Company } from '../../types/company';

export function CompanyFace({ company }: { company: Pick<Company, 'name' | 'colour' | 'logoUrl'> }) {
return (
<span className="relative m-1.5 grid size-14 shrink-0 place-items-center rounded-full bg-white">
<span
aria-hidden="true"
style={{ borderColor: company.colour }}
className="absolute -inset-1.5 rounded-full border-3 border-dashed"
/>
{company.logoUrl ? (
<img src={company.logoUrl} alt="" className="size-full rounded-full object-contain" />
) : (
<span className="font-display text-xl font-extrabold text-ink">{company.name.charAt(0)}</span>
)}
</span>
);
}
19 changes: 1 addition & 18 deletions apps/admin/src/components/guests/CompanyRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { messageFor } from '../../lib/server/errors';
import type { Company } from '../../types/company';
import { Button } from '../ui/Button';
import { ConfirmDialog } from '../ui/ConfirmDialog';
import { CompanyFace } from './CompanyFace';

type CompanyRowProps = {
company: Company;
Expand Down Expand Up @@ -74,21 +75,3 @@ export function CompanyRow({ company, guestCount, onEdit }: CompanyRowProps) {
</li>
);
}

/** The company's logo filling a white circle with a dashed ring in its colour, as a picked speaker's face shows it. */
function CompanyFace({ company }: { company: Company }) {
return (
<span className="relative m-1.5 grid size-14 shrink-0 place-items-center rounded-full bg-white">
<span
aria-hidden="true"
style={{ borderColor: company.colour }}
className="absolute -inset-1.5 rounded-full border-3 border-dashed"
/>
{company.logoUrl ? (
<img src={company.logoUrl} alt="" className="size-full rounded-full object-contain" />
) : (
<span className="font-display text-xl font-extrabold text-ink">{company.name.charAt(0)}</span>
)}
</span>
);
}
21 changes: 5 additions & 16 deletions apps/admin/src/components/guests/CompanySheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,17 @@
import { zodResolver } from '@hookform/resolvers/zod';
import { useState } from 'react';
import { useForm, useWatch } from 'react-hook-form';
import { z } from 'zod';
import { useCreateCompany, useUpdateCompany } from '../../hooks/useCompanies';
import { CompanyFormSchema, type CompanyFormValues, toCompanyFields } from '../../lib/form/company-form';
import { messageFor } from '../../lib/server/errors';
import type { PictureChange } from '../../lib/ui/images';
import { type Company, COMPANY_LINK, CompanySchema, type LogoChanges } from '../../types/company';
import type { Company, LogoChanges } from '../../types/company';
import { Button } from '../ui/Button';
import { FIELD_INPUT } from '../ui/field-styles';
import { FormField } from '../ui/FormField';
import { Sheet } from '../ui/Sheet';
import { LogoField } from './LogoField';

const CompanyFormSchema = CompanySchema.pick({ name: true, colour: true }).extend({
// Empty means no link.
link: z
.string()
.trim()
.refine(
(value) => value === '' || COMPANY_LINK.safeParse(value).success,
"That isn't a whole link. Paste the full address, like https://linktr.ee/their-club.",
),
});

const KEEP_BOTH: LogoChanges<PictureChange> = { face: { kind: 'keep' }, card: { kind: 'keep' } };

// A neutral starting colour; most companies' own colour is on their logo or website.
Expand All @@ -47,7 +36,7 @@ export function CompanySheet({ company, onDone, onClose }: CompanySheetProps) {
const update = useUpdateCompany();
const saving = create.isPending || update.isPending;
const failed = create.isError ? create.error : update.isError ? update.error : null;
const { register, handleSubmit, control, formState } = useForm<z.input<typeof CompanyFormSchema>>({
const { register, handleSubmit, control, formState } = useForm<CompanyFormValues>({
resolver: zodResolver(CompanyFormSchema),
defaultValues: {
name: company?.name ?? '',
Expand All @@ -58,8 +47,8 @@ export function CompanySheet({ company, onDone, onClose }: CompanySheetProps) {
const colour = useWatch({ control, name: 'colour' });
const [logos, setLogos] = useState<LogoChanges<PictureChange>>(KEEP_BOTH);

const save = handleSubmit(({ name, colour: chosen, link }) => {
const fields = { name: name.trim(), colour: chosen, link: link || null };
const save = handleSubmit((values) => {
const fields = toCompanyFields(values);
if (company) {
update.mutate({ company, fields, logos }, { onSuccess: onDone });
} else {
Expand Down
10 changes: 10 additions & 0 deletions apps/admin/src/components/guests/GuestHeadshot.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** A guest's headshot pasted on like a small print, or their initial when there isn't one. */
export function GuestHeadshot({ url, name }: { url: string | null; name: string }) {
const shape = 'relative size-14 shrink-0 rounded-md border-3 border-white shadow-(--shadow-cutout) sm:size-16';
if (url) return <img src={url} alt="" className={`${shape} object-cover`} />;
return (
<span aria-hidden="true" className={`${shape} grid place-items-center bg-pink font-display text-2xl font-extrabold text-ink`}>
{name.charAt(0)}
</span>
);
}
14 changes: 2 additions & 12 deletions apps/admin/src/components/guests/GuestLine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { PATHS } from '../../paths';
import type { GuestBookLine } from '../../types/guest';
import { BOOK_COLUMNS } from './book-columns';
import { CompanyMark } from './CompanyMark';
import { GuestHeadshot } from './GuestHeadshot';
import { spokeLine, usesLine } from './guest-words';

const ROUND_ACTION =
Expand Down Expand Up @@ -44,7 +45,7 @@ export function GuestLine({ line, justSaved, onDelete }: GuestLineProps) {
transition={{ duration: 0.6, ease: 'easeOut', delay: 0.2 }}
/>
)}
<Headshot url={guest.pictureUrl} name={guest.name} />
<GuestHeadshot url={guest.pictureUrl} name={guest.name} />
<div className="relative min-w-0">
<p className="font-display text-xl font-extrabold break-words sm:text-2xl">{guest.name}</p>
{guest.title && <p className="text-sm break-words text-text-2">{guest.title}</p>}
Expand Down Expand Up @@ -91,14 +92,3 @@ export function GuestLine({ line, justSaved, onDelete }: GuestLineProps) {
</li>
);
}

/** Their headshot pasted onto the line like a small print, or their initial when there isn't one. */
function Headshot({ url, name }: { url: string | null; name: string }) {
const shape = 'relative size-14 shrink-0 rounded-md border-3 border-white shadow-(--shadow-cutout) sm:size-16';
if (url) return <img src={url} alt="" className={`${shape} object-cover`} />;
return (
<span aria-hidden="true" className={`${shape} grid place-items-center bg-pink font-display text-2xl font-extrabold text-ink`}>
{name.charAt(0)}
</span>
);
}
26 changes: 26 additions & 0 deletions apps/admin/src/components/guests/ImportCompanyCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* A company in a CSV import, drawn as its face on the site in its colour, with its name and its new or updated
* label. Logos aren't in a CSV, so a new company shows its initial until a logo is framed on Companies.
*/
import type { Company, CompanyFields } from '../../types/company';
import { IMPORT_LABELS } from '../ui/import-labels';
import type { ImportEntry } from '../ui/import-view';
import { Tag } from '../ui/Tag';
import { CompanyFace } from './CompanyFace';
import { importedCompany } from './company-import';

export function ImportCompanyCard({ entry }: { entry: ImportEntry<Company, CompanyFields> }) {
const company = importedCompany(entry);
const logoUrl = entry.kind === 'updated' ? entry.item.after.logoUrl : null;
const label = IMPORT_LABELS[entry.kind];
return (
<div className="flex items-center gap-4 rounded-card bg-card px-4 py-3">
<CompanyFace company={{ ...company, logoUrl }} />
<div className="min-w-0 flex-1">
<p className="truncate font-display text-xl font-extrabold">{company.name}</p>
<p className="font-display text-xs font-bold tracking-widest text-text-2 uppercase">{company.colour}</p>
</div>
<Tag tone={label.tag}>{label.text}</Tag>
</div>
);
}
Loading
Loading