Skip to content
Draft
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
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ MAILGUN_API_KEY=
MAILGUN_DOMAIN=
MAILGUN_API_HOST=
MAILGUN_TO_EMAIL=

# Notion settings
NOTION_API_KEY=
NOTION_APPLICATION_FORMS_PAGE_ID=
6 changes: 5 additions & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};
const nextConfig = {
images: {
domains: ['prod-files-secure.s3.us-west-2.amazonaws.com'],
},
};

export default nextConfig;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"mailgun-js": "^0.22.0",
"next": "14.2.13",
"react": "^18",
"react-dom": "^18"
"react-dom": "^18",
"react-query": "^3.39.3"
},
"devDependencies": {
"@types/node": "^20",
Expand Down
105 changes: 105 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions src/app/api/get-application-forms/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { type NextRequest } from 'next/server';

import {
fetchApplicationFormsPageData,
fetchAllPageBlocks,
fetchApplicationFormsData,
} from '@/app/helpers/notionHelper';

export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> },
) {
const { id } = await params;

try {
// First fetch page data
const pageData = await fetchApplicationFormsPageData(id);

// Fetch all blocks (content) of the page
const pageBlocks = await fetchAllPageBlocks(id);

// Check if block contains a child database
for (const block of pageBlocks.results) {
if (block && block.type === 'child_database') {
if (block.id) {
block.child_database_data = await fetchApplicationFormsData(block.id);
}
}
}

// Combine both page data and blocks into one object
const combinedData = {
pageData,
pageBlocks,
};

// Return the combined data in the response
return new Response(JSON.stringify(combinedData), {
status: 200,
headers: { 'Content-Type': 'application/json' },
});
} catch (error) {
console.error('Error fetching page data or blocks:', error);
return new Response(
JSON.stringify({
error: 'Failed to fetch data for page and page blocks from Notion',
}),
{
status: 500,
headers: { 'Content-Type': 'application/json' },
},
);
}
}
16 changes: 16 additions & 0 deletions src/app/api/get-application-forms/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { NextResponse } from 'next/server';

import { fetchApplicationFormsData } from '@/app/helpers/notionHelper';

export async function GET() {
try {
const pageId = process.env.NOTION_APPLICATION_FORMS_PAGE_ID || '';
const data = await fetchApplicationFormsData(pageId);
return NextResponse.json(data, { status: 200 });
} catch (error) {
return NextResponse.json(
{ message: (error as Error).message },
{ status: 500 },
);
}
}
Loading