-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f47be3
commit 45ad775
Showing
5 changed files
with
112 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters