Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,21 @@ export const action = async ({ params, request }: ActionFunctionArgs) => {
await validateRequest(request, userId);

const formData = await request.formData();
const contentReachValue = formData.get('contentReach');
const content_reach: ContentReach =
contentReachValue === 'all' || contentReachValue === 'important' ? contentReachValue : null;
const preferences =
formData.get('List-Unsubscribe') === 'One-Click'
? { is_unsubscribed: true }
: {
comments: formData.get('comments') === 'true',
content_reach: formData.get('contentReach') as ContentReach,
content_reach,
replies: formData.get('replies') === 'true',
research_updates: formData.get('researchUpdates') === 'true',
is_unsubscribed: formData.get('isUnsubscribed') === 'true',
};

await client.from('notifications_preferences').upsert(
const result = await client.from('notifications_preferences').upsert(
{
...NotificationsPreferencesDefaults,
...preferences,
Expand All @@ -101,6 +104,10 @@ export const action = async ({ params, request }: ActionFunctionArgs) => {
{ onConflict: 'user_id' },
);

if (result.error) {
throw new Error(result.error.code + ': ' + result.error.message + result.error.details);
}

return Response.json({}, { headers, status: 200 });
} catch (error) {
logger.error(error);
Expand Down
4 changes: 3 additions & 1 deletion src/routes/api.notifications-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export const action = async ({ request }: ActionFunctionArgs) => {
try {
const formData = await request.formData();
const comments = formData.get('comments') === 'true';
const content_reach: ContentReach = (formData.get('contentReach') as ContentReach) || null;
const contentReachValue = formData.get('contentReach');
const content_reach: ContentReach =
contentReachValue === 'all' || contentReachValue === 'important' ? contentReachValue : null;
const is_unsubscribed = formData.get('isUnsubscribed') === 'true';
const replies = formData.get('replies') === 'true';
const research_updates = formData.get('researchUpdates') === 'true';
Expand Down
1 change: 0 additions & 1 deletion src/services/notificationsPreferencesService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const unsubscribe = async () => {
body.append('news', 'false');
body.append('replies', 'false');
body.append('researchUpdates', 'false');
body.append('contentReach', 'null');
body.append('isUnsubscribed', 'true');

return fetch('/api/notifications-preferences', {
Expand Down
1 change: 0 additions & 1 deletion src/services/notificationsPreferencesViaEmailService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const unsubscribe = async (userCode: string): Promise<Response> => {
body.append('comments', 'false');
body.append('replies', 'false');
body.append('researchUpdates', 'false');
body.append('contentReach', 'null');
body.append('isUnsubscribed', 'true');

return fetch(`/api/notifications-preferences-via-email/${userCode}`, {
Expand Down
Loading