Skip to content
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
25 changes: 25 additions & 0 deletions src/app/(frontend)/components/MyAYOCopyLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use client'
import React from 'react'
import { useState } from 'react'

const MyAYOCopyLink = ({ copyLink }: { copyLink: string }) => {
const [text, setText] = useState('Copy ICS link')

const handleCopy = () => {
navigator.clipboard.writeText(copyLink)
setText('Copied!')
setTimeout(() => {
setText('Copy ICS link')
}, 1000)
}
return (
<button
onClick={handleCopy}
className="p-3 ml-30 border-black border-2 rounded-md cursor-pointer"
>
{text}
</button>
)
}

export default MyAYOCopyLink
64 changes: 64 additions & 0 deletions src/app/(frontend)/my-ayo/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import MyAYOCopyLink from '../components/MyAYOCopyLink'
import { cookies } from 'next/headers'
import { getPayload } from 'payload'
import config from '@payload-config'

async function checkPassword(formData: FormData) {
'use server'
const payload = await getPayload({ config })
const password = formData.get('password')
const { docs } = await payload.find({
collection: 'passwords',
})
const correctPasswords = docs.map((doc) => doc.password)
if (password && correctPasswords.includes(password as string)) {
const cookieStore = await cookies()
cookieStore.set('my-ayo-access', 'granted', {
httpOnly: true,
path: '/my-ayo',
maxAge: 60 * 60 * 24 * 7,
})
}
}

export default async function MyAyoPage() {
const payload = await getPayload({ config })

const linkResult = await payload.find({
collection: 'links',
limit: 1,
})

const doc = linkResult.docs[0]
const calendarEmbed = doc?.embedLink ?? ''
const calendarUrl = doc?.publicLink ?? ''
const calendarICal = doc?.icalLink ?? ''

const cookieStore = await cookies()
const hasAccess = cookieStore.get('my-ayo-access')?.value === 'granted'
if (!hasAccess) {
return (
<main>
<form action={checkPassword}>
<input type="password" name="password" placeholder="Enter password" required />
<button type="submit">Submit</button>
</form>
</main>
)
}

return (
<main>
<iframe src={calendarEmbed} className="ml-30 border: 0" width="800" height="600"></iframe>
<div className="flex">
<a href={calendarUrl} className="p-3 ml-30 border-black border-2 rounded-md">
<p>Add to Google Calendar</p>
</a>
<a href={calendarICal} className="p-3 ml-30 border-black border-2 rounded-md">
<p>Subscribe on iPhone / Apple Calendar</p>
</a>
<MyAYOCopyLink copyLink={calendarICal} />
</div>
</main>
)
}
19 changes: 19 additions & 0 deletions src/collections/CalendarLink.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { CollectionConfig } from 'payload'

export const CalendarLink: CollectionConfig = {
slug: 'links',
fields: [
{
name: 'embedLink',
type: 'text',
},
{
name: 'publicLink',
type: 'text',
},
{
name: 'icalLink',
type: 'text',
},
],
}
11 changes: 11 additions & 0 deletions src/collections/Passwords.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { CollectionConfig } from 'payload'

export const Passwords: CollectionConfig = {
slug: 'passwords',
fields: [
{
name: 'password',
type: 'text',
},
],
}
54 changes: 54 additions & 0 deletions src/payload-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export interface Config {
users: User;
media: Media;
partners: Partner;
passwords: Password;
links: Link;
'payload-kv': PayloadKv;
'payload-locked-documents': PayloadLockedDocument;
'payload-preferences': PayloadPreference;
Expand All @@ -80,6 +82,8 @@ export interface Config {
users: UsersSelect<false> | UsersSelect<true>;
media: MediaSelect<false> | MediaSelect<true>;
partners: PartnersSelect<false> | PartnersSelect<true>;
passwords: PasswordsSelect<false> | PasswordsSelect<true>;
links: LinksSelect<false> | LinksSelect<true>;
'payload-kv': PayloadKvSelect<false> | PayloadKvSelect<true>;
'payload-locked-documents': PayloadLockedDocumentsSelect<false> | PayloadLockedDocumentsSelect<true>;
'payload-preferences': PayloadPreferencesSelect<false> | PayloadPreferencesSelect<true>;
Expand Down Expand Up @@ -177,6 +181,28 @@ export interface Partner {
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "passwords".
*/
export interface Password {
id: string;
password?: string | null;
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "links".
*/
export interface Link {
id: string;
embedLink?: string | null;
publicLink?: string | null;
icalLink?: string | null;
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "payload-kv".
Expand Down Expand Up @@ -212,6 +238,14 @@ export interface PayloadLockedDocument {
| ({
relationTo: 'partners';
value: string | Partner;
} | null)
| ({
relationTo: 'passwords';
value: string | Password;
} | null)
| ({
relationTo: 'links';
value: string | Link;
} | null);
globalSlug?: string | null;
user: {
Expand Down Expand Up @@ -308,6 +342,26 @@ export interface PartnersSelect<T extends boolean = true> {
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "passwords_select".
*/
export interface PasswordsSelect<T extends boolean = true> {
password?: T;
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "links_select".
*/
export interface LinksSelect<T extends boolean = true> {
embedLink?: T;
publicLink?: T;
icalLink?: T;
updatedAt?: T;
createdAt?: T;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "payload-kv_select".
Expand Down
5 changes: 3 additions & 2 deletions src/payload.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import sharp from 'sharp'
import { Users } from './collections/Users'
import { Media } from './collections/Media'
import { Partners } from './collections/Partners'

import { Passwords } from './collections/Passwords'
import { CalendarLink } from './collections/CalendarLink'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)

Expand All @@ -19,7 +20,7 @@ export default buildConfig({
baseDir: path.resolve(dirname),
},
},
collections: [Users, Media, Partners],
collections: [Users, Media, Partners, Passwords, CalendarLink],
editor: lexicalEditor(),
secret: process.env.PAYLOAD_SECRET || '',
typescript: {
Expand Down
Loading