Skip to content

Commit

Permalink
refactor(web): setup welcome section with CMS
Browse files Browse the repository at this point in the history
  • Loading branch information
HasithDeAlwis committed Jan 11, 2025
1 parent f1641b1 commit 447389e
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 50 deletions.
28 changes: 10 additions & 18 deletions apps/cms/src/payload-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,6 @@ export interface User {
website?: string | null;
instagram?: string | null;
};
emergencyContact: {
firstName: string;
middleName?: string | null;
lastName: string;
email: string;
phoneNumber: string;
relationship: string;
};
academicInfo?: {
school?: ('Carleton' | 'uOttawa' | 'Other') | null;
levelOfStudy?: ('Undergraduate' | 'Graduate' | 'PhD') | null;
Expand Down Expand Up @@ -186,6 +178,14 @@ export interface SocialLink {
| 'github-project'
| 'github-repo';
url: string;
/**
* Green coloured icon
*/
primaryIcon?: (number | null) | Media;
/**
* White coloured icon
*/
secondaryIcon?: (number | null) | Media;
updatedAt: string;
createdAt: string;
}
Expand Down Expand Up @@ -356,16 +356,6 @@ export interface UsersSelect<T extends boolean = true> {
website?: T;
instagram?: T;
};
emergencyContact?:
| T
| {
firstName?: T;
middleName?: T;
lastName?: T;
email?: T;
phoneNumber?: T;
relationship?: T;
};
academicInfo?:
| T
| {
Expand Down Expand Up @@ -420,6 +410,8 @@ export interface MediaSelect<T extends boolean = true> {
export interface SocialLinksSelect<T extends boolean = true> {
platform?: T;
url?: T;
primaryIcon?: T;
secondaryIcon?: T;
updatedAt?: T;
createdAt?: T;
}
Expand Down
6 changes: 5 additions & 1 deletion apps/cms/src/payload.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Events } from '@cuhacking/db/collections/Events'
import { Challenges } from '@cuhacking/db/collections/Challenges'
import { Schedule } from '@cuhacking/db/collections/Schedule'
import { Organizations } from '@cuhacking/db/collections/Organizations'
import { Welcome } from '@cuhacking/db/collections/Welcome'

const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
Expand All @@ -27,6 +28,8 @@ export default buildConfig({
baseDir: path.resolve(dirname),
},
},
cors: "*",
csrf: ["*"],
collections: [
Hackathons,
Users,
Expand All @@ -36,7 +39,8 @@ export default buildConfig({
Events,
Challenges,
Schedule,
Organizations
Organizations,
Welcome
],
editor: lexicalEditor(),
secret: process.env.PAYLOAD_SECRET || '',
Expand Down
7 changes: 5 additions & 2 deletions apps/website/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@
"// targets": "to see all targets run: nx show project website --web",
"targets": {
"dev": {
"command": "remix vite:dev",
"command": "remix vite:dev --port 3010",
"options": {
"cwd": "apps/website"
}
},
"build": {
"command": "remix vite:build",
"cache": true,
"outputs": ["{projectRoot}/build", "{projectRoot}/public/build"],
"outputs": [
"{projectRoot}/build",
"{projectRoot}/public/build"
],
"options": {
"cwd": "apps/website"
}
Expand Down
3 changes: 3 additions & 0 deletions libs/db/collections/Media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export const Media: CollectionConfig = {
slug: 'media',
access: {
read: () => true,
create: () => true,
update: () => true,
delete: () => true,
},
fields: [
{
Expand Down
1 change: 0 additions & 1 deletion libs/website/ui/introduction/welcome/welcome.section.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import BgKeyboard from '@website/assets/ui/introduction/bg-keyboard-1.webp'
import { SplineComponent } from '@website/shared/ui/spline/spline-component'
import React from 'react'
import { WELCOME_CONSTANTS } from '../constants/welcome.constants'
import { Welcome } from './welcome'

Expand Down
120 changes: 92 additions & 28 deletions libs/website/ui/introduction/welcome/welcome.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,106 @@
import { GlassmorphicCard } from '@cuhacking/shared/ui/glassmorphic-card'
import { TerminalText } from '@cuhacking/shared/ui/terminal-text'
import { Socials } from '@website/shared/ui/socials'
import Socials from '@website/shared/ui/socials'
import { useEffect, useState } from 'react'

interface WelcomeData {
title: string
organization: string
date: string
callToAction: string
}

interface Media {
src: string
alt: string
}

interface IntroProps {
socials: { link: string, media: Media }[]
socials: { link: string, media: Media, name: string }[]
}

async function fetchWelcomeData(): Promise<WelcomeData | null> {
const query = `
query {
Welcomes {
docs {
title
organization
date
callToAction
}
}
}
`

try {
const response = await fetch(`${import.meta.env.VITE_API_URL}/api/graphql`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ query }),
})

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
}

const data = await response.json()
const welcomeData = data.data.Welcomes.docs[0] // Assuming only one document or taking the first one
return {
title: welcomeData.title,
organization: welcomeData.organization,
date: welcomeData.date,
callToAction: welcomeData.callToAction,
}
}
catch (error) {
console.error('Failed to fetch welcome data:', error)
return null
}
}
// TODO: Refactor so that it takes in props that can communicate colours

export function Welcome({ socials }: IntroProps) {
const [welcomeData, setWelcomeData] = useState<WelcomeData | null>(null)

useEffect(() => {
async function getData() {
const data = await fetchWelcomeData()
setWelcomeData(data)
}
getData()
}, [])

return (
<GlassmorphicCard
variant="default"
className="flex flex-col items-start p-3.5 sm:p-6 gap-y-2.5"
>
<h2 className="text-2xl font-bold text-center">HELLO, WORLD</h2>
<div>
<TerminalText className="text-base">
<p>
<span className="text-transparent bg-greendiant bg-clip-text">
cuHacking
</span>
{' '}
is coming to you
<span className="text-transparent bg-greendiant bg-clip-text">
{' '}
Mar. 14 - 16 2025 @ Carleton University 💚
</span>
</p>
</TerminalText>
<TerminalText className="text-base">
<p>In the meantime, check out all the cool stuff we're working on!</p>
</TerminalText>
<Socials socials={socials} className="justify-center pt-5" />
</div>
</GlassmorphicCard>
welcomeData
? (
<GlassmorphicCard
variant="default"
className="flex flex-col items-start p-3.5 sm:p-6 gap-y-2.5"
>
<h2 className="text-2xl font-bold text-center">{welcomeData.title}</h2>
<div>
<TerminalText className="text-base">
<p>
<span className="text-transparent bg-greendiant bg-clip-text">
{welcomeData.organization}
</span>
{' '}
is coming to you
<span className="text-transparent bg-greendiant bg-clip-text">
{' '}
{welcomeData.date}
</span>
</p>
</TerminalText>
<TerminalText className="text-base">
<p>{welcomeData.callToAction}</p>
</TerminalText>
<Socials socials={socials} className="justify-center pt-5" />
</div>
</GlassmorphicCard>
)
: null
)
}

0 comments on commit 447389e

Please sign in to comment.