diff --git a/package.json b/package.json index 2a14bc1..ff57f06 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "@getbrevo/brevo": "^2.2.0", "@notionhq/client": "^2.2.15", "axios": "^1.7.2", + "classnames": "^2.5.1", "luxon": "^3.5.0", "next": "14.2.5", "react": "^18", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0561cf2..3218b0e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,9 @@ importers: axios: specifier: ^1.7.2 version: 1.7.2 + classnames: + specifier: ^2.5.1 + version: 2.5.1 luxon: specifier: ^3.5.0 version: 3.5.0 @@ -437,6 +440,9 @@ packages: resolution: {integrity: sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==} engines: {node: '>= 8.10.0'} + classnames@2.5.1: + resolution: {integrity: sha512-saHYOzhIQs6wy2sVxTM6bUDsQO4F50V9RQ22qBpEdCW+I+/Wmke2HOl6lS6dTpdxVhb88/I6+Hs+438c3lfUow==} + client-only@0.0.1: resolution: {integrity: sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA==} @@ -2167,6 +2173,8 @@ snapshots: optionalDependencies: fsevents: 2.3.3 + classnames@2.5.1: {} + client-only@0.0.1: {} color-convert@2.0.1: diff --git a/src/apiClient/NotionApiClient.ts b/src/apiClient/NotionApiClient.ts index 7b7dc01..17d0158 100644 --- a/src/apiClient/NotionApiClient.ts +++ b/src/apiClient/NotionApiClient.ts @@ -9,6 +9,7 @@ import { PartialPageObjectResponse, QueryDatabaseResponse, } from "@notionhq/client/build/src/api-endpoints" +import { DateTime } from "luxon" const NotionApiClient = () => { const notionClient = (): NotionClient => { @@ -47,6 +48,36 @@ const NotionApiClient = () => { return data.results?.[0] as PageObjectResponse } + const fetchNextEvent = async (): Promise< + | PageObjectResponse + | PartialPageObjectResponse + | PartialDatabaseObjectResponse + | DatabaseObjectResponse + | undefined + > => { + if (!process.env.NOTION_EVENTS_DATABASE) return undefined + const data = await notionClient().databases.query({ + database_id: process.env.NOTION_EVENTS_DATABASE, + archived: false, + in_trash: false, + page_size: 1, + sorts: [ + { + direction: "ascending", + property: "Date", + }, + ], + filter: { + property: "Date", + date: { + after: DateTime.now().toFormat("yyyy-MM-dd"), + }, + }, + }) + + return data.results?.[0] + } + const fetchLastEvents = async (): Promise< ( | PageObjectResponse @@ -67,20 +98,46 @@ const NotionApiClient = () => { property: "Date", }, ], + filter: { + property: "Date", + date: { + before: DateTime.now().toFormat("yyyy-MM-dd"), + }, + }, }) return data.results } const fetchEvents = async (): Promise< - NotionDatabaseQueryType + ( + | PageObjectResponse + | PartialPageObjectResponse + | PartialDatabaseObjectResponse + | DatabaseObjectResponse + )[] > => { - const response = await request({ - url: `v1/databases/${process.env.NOTION_EVENTS_DATABASE}/query`, - method: "POST", + if (!process.env.NOTION_EVENTS_DATABASE) return [] + const data = await notionClient().databases.query({ + database_id: process.env.NOTION_EVENTS_DATABASE, + archived: false, + in_trash: false, + page_size: 1000, + sorts: [ + { + direction: "descending", + property: "Date", + }, + ], + filter: { + property: "Date", + date: { + before: DateTime.now().toFormat("yyyy-MM-dd"), + }, + }, }) - return response.data + return data.results } const fetchCrew = async (): Promise => { @@ -109,6 +166,7 @@ const NotionApiClient = () => { fetchCrew, addSubscriber, fetchLastEvents, + fetchNextEvent, } } diff --git a/src/app/events/page.tsx b/src/app/events/page.tsx index 5d22ee2..bdc7da0 100644 --- a/src/app/events/page.tsx +++ b/src/app/events/page.tsx @@ -12,12 +12,21 @@ export const metadata: Metadata = { export default async function Page() { const pageData = await NotionApiClient().fetchEvents() + const nextEvent = await NotionApiClient().fetchNextEvent(); return <> -

Tutti i nostri eventi

- +

I nostri eventi

+ {nextEvent && +
+

Registrati al prossimo evento

+ +
+ }
- {pageData.results.map((event : any) => ( + {pageData.map((event : any) => ( { const lastEvents = await NotionApiClient().fetchLastEvents(); + const nextEvent = await NotionApiClient().fetchNextEvent(); return ( @@ -33,68 +34,60 @@ const Home = async () => {

Unisciti a noi per crescere, imparare e fare la differenza insieme!

-
-
+
- Meetup + Meetup - -
  • - - Github + Github -
  • -
  • - - - Discord + > + Discord - Telegram + Telegram -
  • -
    @@ -110,8 +103,16 @@ const Home = async () => {
    + {nextEvent && +
    +

    Registrati al prossimo evento

    + +
    + }
    -

    Ultimi eventi

    - - - + diff --git a/src/components/SingleEventCard.tsx b/src/components/SingleEventCard.tsx index c5667d2..3e026d1 100644 --- a/src/components/SingleEventCard.tsx +++ b/src/components/SingleEventCard.tsx @@ -1,16 +1,18 @@ import { getPlainTextFromBlock } from "@/utils/NotionFormatter" import { PageObjectResponse } from "@notionhq/client/build/src/api-endpoints" +import classNames from "classnames" import Link from "next/link" export interface SingleEventCardProps{ event: PageObjectResponse + className?: string } -const SingleEventCard : React.FC = ({event}) =>{ +const SingleEventCard : React.FC = ({event, className}) =>{ - return + return

    {getPlainTextFromBlock(event.properties["Name"])}

    {getPlainTextFromBlock(event.properties["Date"])}