Skip to content

Commit e23f803

Browse files
jason301cedwnlmonash-codingoliverhuangcodeje-zhou
authored
Add lru-cache to job fetching (#233)
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: ed <edwinli123456@gmail.com> Co-authored-by: monash-coding <64454397+monash-coding@users.noreply.github.com> Co-authored-by: oliverhuangcode <95962305+oliverhuangcode@users.noreply.github.com> Co-authored-by: Jerry Zhou <81694589+je-zhou@users.noreply.github.com> Co-authored-by: Brian-w-m <111062353+Brian-w-m@users.noreply.github.com> Co-authored-by: kyranaus <kyranmenezesaus@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: AdityaZDesai <119026042+AdityaZDesai@users.noreply.github.com>
1 parent b768bbc commit e23f803

File tree

8 files changed

+416
-8
lines changed

8 files changed

+416
-8
lines changed

frontend/package-lock.json

Lines changed: 33 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"dompurify": "^3.2.3",
2222
"isomorphic-dompurify": "^2.22.0",
2323
"jsdom": "^26.0.0",
24+
"lru-cache": "^11.2.2",
2425
"mongodb": "^6.14.2",
2526
"next": "15.1.7",
2627
"pino": "^9.11.0",
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
"use server";
2+
3+
import logger from "@/lib/logger";
4+
5+
// Type for our form data
6+
export interface FeedbackFormData {
7+
email?: string;
8+
message: string;
9+
}
10+
11+
export async function submitFeedback(data: FeedbackFormData) {
12+
const databaseId = process.env.NOTION_DATABASE_ID;
13+
const notionApiKey = process.env.NOTION_API_KEY;
14+
15+
if (!databaseId) {
16+
logger.error("NOTION_DATABASE_ID environment variable is not set");
17+
throw new Error("NOTION_DATABASE_ID environment variable is not set");
18+
}
19+
20+
if (!notionApiKey) {
21+
logger.error("NOTION_API_KEY environment variable is not set");
22+
throw new Error("NOTION_API_KEY environment variable is not set");
23+
}
24+
25+
try {
26+
const response = await fetch("https://api.notion.com/v1/pages", {
27+
method: "POST",
28+
headers: {
29+
Authorization: `Bearer ${notionApiKey}`,
30+
"Content-Type": "application/json",
31+
"Notion-Version": "2022-06-28",
32+
},
33+
body: JSON.stringify({
34+
parent: {
35+
database_id: databaseId,
36+
},
37+
properties: {
38+
Email: {
39+
title: [
40+
{
41+
text: {
42+
content: data.email || "Anonymous",
43+
},
44+
},
45+
],
46+
},
47+
Feedback: {
48+
rich_text: [
49+
{
50+
text: {
51+
content: data.message,
52+
},
53+
},
54+
],
55+
},
56+
Date: {
57+
date: {
58+
start: new Date().toISOString(),
59+
},
60+
},
61+
},
62+
}),
63+
});
64+
65+
if (!response.ok) {
66+
const errorData = await response.json();
67+
logger.error(
68+
{ error: errorData, status: response.status },
69+
"Notion API error during feedback submission",
70+
);
71+
return {
72+
success: false,
73+
message: `We're sorry, but there was an issue submitting your feedback. Please try again later.`,
74+
};
75+
}
76+
77+
logger.info(
78+
{ email: data.email || "Anonymous" },
79+
"Feedback submitted successfully",
80+
);
81+
return {
82+
success: true,
83+
message: "Thank you! Your feedback has been submitted successfully.",
84+
};
85+
} catch (error) {
86+
logger.error(error, "Unexpected error during feedback submission");
87+
return {
88+
success: false,
89+
message: `An unexpected error occurred while submitting your feedback. Please try again.`,
90+
};
91+
}
92+
}

0 commit comments

Comments
 (0)