Skip to content

Commit

Permalink
Add tab for the RSVPing to tavern
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwofford committed Jan 8, 2025
1 parent 9f47be3 commit 45ad775
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/app/[tab]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function Page({
}, [])

const { tab } = params
const validTabs = ['signpost', 'shipyard', 'wonderdome', 'shop']
const validTabs = ['signpost', 'shipyard', 'wonderdome', 'shop', 'tavern']
if (!validTabs.includes(tab)) return notFound()

const { magic_auth_token } = searchParams
Expand Down
6 changes: 6 additions & 0 deletions src/app/harbor/tabs/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
import Shipyard from '../shipyard/shipyard'
import Battles from '../battles/battles'
import Shop from '../shop/shop'
import Tavern from '../tavern/tavern'
import { useEffect } from 'react'
import SignPost from '../signpost/signpost'
import { tour } from './tour'
Expand Down Expand Up @@ -211,6 +212,11 @@ export default function Harbor({
path: 'shop',
component: <Shop session={session} />,
},
{
name: <>Tavern 🍻</>,
path: 'tavern',
component: <Tavern />,
},
]

let usPrices = false
Expand Down
52 changes: 52 additions & 0 deletions src/app/harbor/tavern/tavern.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use client'

import { useEffect } from 'react'
import useLocalStorageState from '../../../../lib/useLocalStorageState'
import { setTavernRsvpStatus, getTavernRsvpStatus } from '@/app/utils/tavern'

const RsvpStatusSwitcher = () => {
const [rsvpStatus, setRsvpStatus] = useLocalStorageState(
'cache.rsvpStatus',
'none',
)

useEffect(() => {
// set rsvp status
getTavernRsvpStatus().then((status) => setRsvpStatus(status))
}, [])

const onOptionChangeHandler = (e) => {
setRsvpStatus(e.target.value)
setTavernRsvpStatus(e.target.value)
}

return (
<div className="text-center mb-6 mt-12" id="region-select">
<label>Will you join?</label>
<select
onChange={onOptionChangeHandler}
value={rsvpStatus}
className="ml-2 text-gray-600 rounded-sm"
>
<option disabled>Select</option>
<option value="none">Nope, can't do neither</option>
<option value="organizer">I can organize a tavern near me</option>
<option value="participant">I want to attend a tavern near me</option>
</select>
</div>
)
}

export default function Tavern() {
return (
<div className="container mx-auto px-4 py-8 text-white relative">
<div className="text-center text-white">
<h1 className="font-heading text-5xl mb-6 text-center relative w-fit mx-auto">
Mystic Tavern
</h1>

<RsvpStatusSwitcher />
</div>
</div>
)
}
45 changes: 45 additions & 0 deletions src/app/utils/tavern.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use server'

import Airtable from 'airtable'
import { getSession } from './auth'

Airtable.configure({
apiKey: process.env.AIRTABLE_API_KEY,
endpointUrl: process.env.AIRTABLE_ENDPOINT_URL,
})

type RsvpStatus = 'none' | 'organizer' | 'participant'
export const setTavernRsvpStatus = async (rsvpStatus: RsvpStatus) => {
// check auth
const session = await getSession()
if (!session) {
return
}
if (!session.personId) {
return
}

// update status
const base = Airtable.base(process.env.BASE_ID)
const result = await base('people').update(session.personId, {
tavern_rsvp_status: rsvpStatus,
})

return result.get('tavern_rsvp_status')
}

export const getTavernRsvpStatus = async () => {
// check auth
const session = await getSession()
if (!session) {
return
}
if (!session.personId) {
return
}

// get status
const base = Airtable.base(process.env.BASE_ID)
const record = await base('people').find(session.personId)
return record.get('tavern_rsvp_status') as RsvpStatus
}
9 changes: 8 additions & 1 deletion src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,5 +212,12 @@ export async function middleware(request: NextRequest) {
}

export const config = {
matcher: ['/signpost', '/shipyard', '/wonderdome', '/shop', '/api/cron/'],
matcher: [
'/signpost',
'/shipyard',
'/wonderdome',
'/shop',
'/tavern',
'/api/cron/',
],
}

0 comments on commit 45ad775

Please sign in to comment.