Skip to content

Commit

Permalink
added vendor runsheets
Browse files Browse the repository at this point in the history
  • Loading branch information
amykapernick committed Mar 5, 2024
1 parent 2700c1a commit 1127f0f
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 44 deletions.
3 changes: 1 addition & 2 deletions src/app/runsheet/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { SignOutButton } from "@clerk/nextjs";
import FetchData from "@components/parts/fetchRunsheet";
import FetchData from "@components/parts/fetchGuestRunsheet";

export default async function Runsheet ()
{


return (
<>
<h2 id="runsheet">Runsheets</h2>
Expand Down
18 changes: 18 additions & 0 deletions src/app/runsheet/vendor/[vendor]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { SignOutButton } from "@clerk/nextjs";
import FetchData from "@components/parts/fetchRunsheet";

export default async function Runsheet (props)
{
const { vendor } = props.params

return (
<>
<h2 id="runsheet">Runsheets</h2>
<p>You can print these off for easy reference.</p>
<FetchData vendor={vendor} />
<span className="signout">
<SignOutButton>Log Out</SignOutButton>
</span>
</>
)
}
59 changes: 59 additions & 0 deletions src/components/parts/fetchGuestRunsheet/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Client } from '@notionhq/client'
import { currentUser } from '@clerk/nextjs';
import type { NotionGuest } from "@ts/people";
import type { User } from "@clerk/nextjs/server";
import { TrackEvent } from "@parts/fathom";
import GuestRunsheets from "@parts/guestRunsheets";
import { NotionRunsheetEvent, NotionStakeholder } from '@ts/runsheet';

const FetchData = async () =>
{
const { emailAddresses } = await currentUser() as User;
const notion = new Client({
auth: process.env.NOTION_API_KEY
})
const data = await notion.databases.query({
database_id: process.env.GUEST_DB ?? '',
filter: {
property: 'GokD',
email: {
equals: emailAddresses[0].emailAddress.toLowerCase()
}
}
})
const guest = data.results?.[0] as unknown as NotionGuest
const runsheetEvents: any = await notion.databases.query({
database_id: process.env.RUNSHEET_DB ?? '',
filter: {
property: 'Guests',
rollup: {
any: {
relation: {
contains: guest.id
}
}
}
}
})
const stakeholders = await notion.databases.query({
database_id: process.env.STAKEHOLDER_DB ?? '',
filter: {
property: 'Invitations',
relation: {
contains: guest.id
}
}
})

return (
<>
{emailAddresses[0].emailAddress.toLowerCase() && <TrackEvent name="Signed In" />}
<GuestRunsheets
runsheetEvents={runsheetEvents?.results as any as NotionRunsheetEvent[]}
stakeholders={stakeholders?.results as any as NotionStakeholder[]}
/>
</>
)
}

export default FetchData
53 changes: 20 additions & 33 deletions src/components/parts/fetchRunsheet/index.tsx
Original file line number Diff line number Diff line change
@@ -1,56 +1,43 @@
import { Client } from '@notionhq/client'
import { currentUser } from '@clerk/nextjs';
import type { NotionGuest } from "@ts/people";
import type { User } from "@clerk/nextjs/server";
import { TrackEvent } from "@parts/fathom";
import GuestRunsheets from "@parts/guestRunsheets";
import { NotionRunsheetEvent, NotionStakeholder } from '@ts/runsheet';
import { NotionRunsheetEvent } from '@ts/runsheet';
import VendorRunsheets from '@parts/vendorRunsheet';

const FetchData = async () =>
const FetchData = async (props) =>
{
const { emailAddresses } = await currentUser() as User;
const notion = new Client({
auth: process.env.NOTION_API_KEY
})
const data = await notion.databases.query({
database_id: process.env.GUEST_DB ?? '',
filter: {
property: 'GokD',
email: {
equals: emailAddresses[0].emailAddress.toLowerCase()
let filter = undefined

if (props.vendor && props.vendor !== 'all')
{
filter = {
property: 'Vendor Slugs',
formula: {
string: {
contains: props.vendor
}
}
}
})
const guest = data.results?.[0] as unknown as NotionGuest
}

const runsheetEvents: any = await notion.databases.query({
database_id: process.env.RUNSHEET_DB ?? '',
filter: {
property: 'Guests',
rollup: {
any: {
relation: {
contains: guest.id
}
}
}
}
})
const stakeholders = await notion.databases.query({
database_id: process.env.STAKEHOLDER_DB ?? '',
filter: {
property: 'Invitations',
relation: {
contains: guest.id
}
}
filter
})

console.log({ ...runsheetEvents })

return (
<>
{emailAddresses[0].emailAddress.toLowerCase() && <TrackEvent name="Signed In" />}
<GuestRunsheets
<VendorRunsheets
runsheetEvents={runsheetEvents?.results as any as NotionRunsheetEvent[]}
stakeholders={stakeholders?.results as any as NotionStakeholder[]}
vendor={props.vendor?.replaceAll('_', ' ')}
/>
</>
)
Expand Down
2 changes: 0 additions & 2 deletions src/components/parts/guestRunsheets/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ const GuestRunsheets = (props: GuestRunsheetsProps) =>

runsheetEvents.forEach(event =>
{
console.log({ ...event })

events[event.id] = {
name: event.properties.Name.title[0].plain_text,
tags: event.properties.Tags.multi_select.map(tag => tag.name),
Expand Down
3 changes: 3 additions & 0 deletions src/components/parts/runsheet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ const Runsheet = (props: RunsheetProps) =>
<h4 className={styles.day}>{day}</h4>
<table className={styles.timetable}>
<thead>
<tr className="spacing">
<th colspan="5"></th>
</tr>
<tr>
<th>Start</th>
<th>End</th>
Expand Down
14 changes: 10 additions & 4 deletions src/components/parts/runsheet/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,21 @@
font-family: $font_headings;
background: $green;
color: $white;

& :global(.spacing) {
display: none;
}
}

& td, & th {
padding: 0.7em;
}

& tr {
&:nth-child(2n) {
background: $green_light;
}
& tbody {
& tr {
&:nth-child(2n) {
background: $green_light;
}
}
}
}
38 changes: 38 additions & 0 deletions src/components/parts/vendorRunsheet/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { NotionRunsheetEvent, RunsheetEvent, NotionStakeholder, VendorRunsheetEvent } from "@ts/runsheet"
import Runsheet from "@parts/runsheet"
import { parseISO } from "date-fns"

type VendorRunsheetsProps = {
runsheetEvents: NotionRunsheetEvent[]
vendor: string | null
}

const VendorRunsheets = (props: VendorRunsheetsProps) =>
{
const { runsheetEvents = [] } = props
const events: Record<string, VendorRunsheetEvent> = {}

runsheetEvents.forEach(event =>
{
events[event.id] = {
name: event.properties.Name.title[0].plain_text,
tags: event.properties.Tags.multi_select.map(tag => tag.name),
start: parseISO(event.properties.Date.date.start),
end: event.properties.Date.date.end ? parseISO(event.properties.Date.date.end) : null,
notes: event.properties.Notes.rich_text.map(note => note.plain_text).join('\n'),
vendors: event.properties['Vendor Slugs'].formula.string?.split(',')
}
})

return (
<Runsheet
stakeholder={{
name: props.vendor ?? "Runsheet",
events: Object.values(events).sort((a, b) => a.start.getTime() - b.start.getTime())
}}
/>
)
}

export default VendorRunsheets

19 changes: 16 additions & 3 deletions src/styles/global/print.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@page {
size: A5;
margin: 0;
margin: 0 0 50px 0;
}

body {
Expand Down Expand Up @@ -36,15 +36,28 @@ article[class*="runsheet"] {

& span[class*="person_name"] {
display: block;
margin-bottom: 0;
}

& .frame {
display: block;
}
}

&:has(+ section[data-page="true"]) {
padding-bottom: var(--page_margins);
& h4 {
margin-bottom: calc(-50px + 0.5em);
}

& thead {
& .spacing {
height: 50px;
background: $white;
display: block;

& th {
padding: 0;
}
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/types/runsheet.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export type NotionRunsheetEvent = {
plain_text: string
}[]
}
'Vendor Slugs': {
formula: {
string: string
}
}
}
}

Expand All @@ -45,6 +50,10 @@ export type RunsheetEvent = {
notes: string;
}

export type VendorRunsheetEvent = RunsheetEvent & {
vendors: string[]
}

export type NotionStakeholder = {
id: string
properties: {
Expand Down

0 comments on commit 1127f0f

Please sign in to comment.