Skip to content

Commit 8aee183

Browse files
committed
format
1 parent de8df68 commit 8aee183

File tree

3 files changed

+203
-189
lines changed

3 files changed

+203
-189
lines changed

frontend/src/app/actions.ts

Lines changed: 63 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,69 +3,75 @@
33

44
// Type for our form data
55
export interface FeedbackFormData {
6-
email?: string;
7-
message: string;
6+
email?: string;
7+
message: string;
88
}
99

1010
export async function submitFeedback(data: FeedbackFormData) {
11-
const databaseId = process.env.NOTION_DATABASE_ID;
12-
const notionApiKey = process.env.NOTION_API_KEY;
11+
const databaseId = process.env.NOTION_DATABASE_ID;
12+
const notionApiKey = process.env.NOTION_API_KEY;
1313

14-
if (!databaseId) {
15-
throw new Error("NOTION_DATABASE_ID environment variable is not set");
16-
}
14+
if (!databaseId) {
15+
throw new Error("NOTION_DATABASE_ID environment variable is not set");
16+
}
1717

18-
if (!notionApiKey) {
19-
throw new Error("NOTION_API_KEY environment variable is not set");
20-
}
18+
if (!notionApiKey) {
19+
throw new Error("NOTION_API_KEY environment variable is not set");
20+
}
2121

22-
try {
23-
const response = await fetch('https://api.notion.com/v1/pages', {
24-
method: 'POST',
25-
headers: {
26-
'Authorization': `Bearer ${notionApiKey}`,
27-
'Content-Type': 'application/json',
28-
'Notion-Version': '2022-06-28',
29-
},
30-
body: JSON.stringify({
31-
parent: {
32-
database_id: databaseId,
22+
try {
23+
const response = await fetch("https://api.notion.com/v1/pages", {
24+
method: "POST",
25+
headers: {
26+
Authorization: `Bearer ${notionApiKey}`,
27+
"Content-Type": "application/json",
28+
"Notion-Version": "2022-06-28",
29+
},
30+
body: JSON.stringify({
31+
parent: {
32+
database_id: databaseId,
33+
},
34+
properties: {
35+
Email: {
36+
title: [
37+
{
38+
text: {
39+
content: data.email || "Anonymous",
3340
},
34-
properties: {
35-
"Email": {
36-
title: [
37-
{
38-
text: {
39-
content: data.email || "Anonymous"
40-
}
41-
}
42-
]
43-
},
44-
"Feedback": {
45-
rich_text: [
46-
{
47-
text: {
48-
content: data.message
49-
}
50-
}
51-
]
52-
},
53-
"Date": {
54-
date: {
55-
start: new Date().toISOString()
56-
}
57-
}
58-
}
59-
}),
60-
});
61-
62-
if (!response.ok) {
63-
const errorData = await response.json();
64-
return {success: false, message: `Notion returned an API error: ${errorData.message || response.statusText}`};
65-
}
41+
},
42+
],
43+
},
44+
Feedback: {
45+
rich_text: [
46+
{
47+
text: {
48+
content: data.message,
49+
},
50+
},
51+
],
52+
},
53+
Date: {
54+
date: {
55+
start: new Date().toISOString(),
56+
},
57+
},
58+
},
59+
}),
60+
});
6661

67-
return {success: true, message: "Feedback submitted successfully."}
68-
} catch (error) {
69-
return {success: false, message: `Encountered an internal error: ${error}`};
62+
if (!response.ok) {
63+
const errorData = await response.json();
64+
return {
65+
success: false,
66+
message: `Notion returned an API error: ${errorData.message || response.statusText}`,
67+
};
7068
}
71-
}
69+
70+
return { success: true, message: "Feedback submitted successfully." };
71+
} catch (error) {
72+
return {
73+
success: false,
74+
message: `Encountered an internal error: ${error}`,
75+
};
76+
}
77+
}

frontend/src/app/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// the tailwind class passed with className is not applied.
33
import "@mantine/core/styles.css";
44
import "./globals.css";
5-
import '@mantine/notifications/styles.css';
5+
import "@mantine/notifications/styles.css";
66

77
import { Analytics } from "@vercel/analytics/react";
88
import { SpeedInsights } from "@vercel/speed-insights/next";
@@ -19,7 +19,7 @@ import { Poppins } from "next/font/google";
1919
import { FilterProvider } from "@/context/filter/filter-provider";
2020
import { Metadata } from "next";
2121
import FeedbackButton from "@/components/ui/feedback-button";
22-
import {Notifications} from "@mantine/notifications";
22+
import { Notifications } from "@mantine/notifications";
2323

2424
export const metadata: Metadata = {
2525
title: {

0 commit comments

Comments
 (0)