Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SFR-2263: Add submit feedback error handling and audit data #545

Merged
merged 3 commits into from
Oct 23, 2024
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGE LOG

## [Prerelease]
- Add submit feedback error handling and new fields

## [0.18.5]
- Make NYPL footer sticky

Expand Down
34 changes: 21 additions & 13 deletions src/lib/api/FeedbackApi.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
import appConfig from "~/config/appConfig";
import { Feedback } from "~/src/types/Feedback";
import { log } from "../newrelic/NewRelic";

// TODO: disable feedback in development

export const submitFeedback = async (feedback: Feedback) => {
return await fetch(appConfig.feedback.formURL, {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.NEXT_PUBLIC_AIRTABLE_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
fields: {
Feedback: feedback.feedback,
Category: feedback.category,
URL: feedback.url,
try {
return await fetch(appConfig.feedback.formURL, {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.NEXT_PUBLIC_AIRTABLE_API_KEY}`,
"Content-Type": "application/json",
},
}),
});
body: JSON.stringify({
fields: {
Feedback: feedback.feedback,
Category: feedback.category,
Date: new Date().toLocaleDateString("en-US"),
Environment: process.env.APP_ENV,
URL: feedback.url,
},
}),
});
} catch (error) {
log(error, "Failed to submit feedback");
throw new Error(`Failed to submit feedback: ${error.message}`);
}
};
Loading