diff --git a/src/app/(frontend)/components/MyAYOCopyLink.tsx b/src/app/(frontend)/components/MyAYOCopyLink.tsx new file mode 100644 index 0000000..1ff0c66 --- /dev/null +++ b/src/app/(frontend)/components/MyAYOCopyLink.tsx @@ -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 ( + + ) +} + +export default MyAYOCopyLink diff --git a/src/app/(frontend)/my-ayo/page.tsx b/src/app/(frontend)/my-ayo/page.tsx new file mode 100644 index 0000000..aec1f3e --- /dev/null +++ b/src/app/(frontend)/my-ayo/page.tsx @@ -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 ( +
+
+ + +
+
+ ) + } + + return ( +
+ +
+ +

Add to Google Calendar

+
+ +

Subscribe on iPhone / Apple Calendar

+
+ +
+
+ ) +} diff --git a/src/collections/CalendarLink.ts b/src/collections/CalendarLink.ts new file mode 100644 index 0000000..f2084ef --- /dev/null +++ b/src/collections/CalendarLink.ts @@ -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', + }, + ], +} diff --git a/src/collections/Passwords.ts b/src/collections/Passwords.ts new file mode 100644 index 0000000..e2eceb6 --- /dev/null +++ b/src/collections/Passwords.ts @@ -0,0 +1,11 @@ +import type { CollectionConfig } from 'payload' + +export const Passwords: CollectionConfig = { + slug: 'passwords', + fields: [ + { + name: 'password', + type: 'text', + }, + ], +} diff --git a/src/payload-types.ts b/src/payload-types.ts index e90e259..e533b64 100644 --- a/src/payload-types.ts +++ b/src/payload-types.ts @@ -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; @@ -80,6 +82,8 @@ export interface Config { users: UsersSelect | UsersSelect; media: MediaSelect | MediaSelect; partners: PartnersSelect | PartnersSelect; + passwords: PasswordsSelect | PasswordsSelect; + links: LinksSelect | LinksSelect; 'payload-kv': PayloadKvSelect | PayloadKvSelect; 'payload-locked-documents': PayloadLockedDocumentsSelect | PayloadLockedDocumentsSelect; 'payload-preferences': PayloadPreferencesSelect | PayloadPreferencesSelect; @@ -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". @@ -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: { @@ -308,6 +342,26 @@ export interface PartnersSelect { updatedAt?: T; createdAt?: T; } +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "passwords_select". + */ +export interface PasswordsSelect { + password?: T; + updatedAt?: T; + createdAt?: T; +} +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "links_select". + */ +export interface LinksSelect { + 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". diff --git a/src/payload.config.ts b/src/payload.config.ts index d49c200..490a2c1 100644 --- a/src/payload.config.ts +++ b/src/payload.config.ts @@ -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) @@ -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: {