fix: update NotificationPreferences to use new API structure

- Update endpoint path from /notification-preferences to /member/notification-preferences
- Change PUT request body to use preferences array format
- Update types to use Item schema instead of UpdateNotificationPreferencesInputBody
This commit is contained in:
Claude 2025-11-23 08:05:41 +00:00
parent 450d339237
commit c6e5a9535a
No known key found for this signature in database

View file

@ -4,7 +4,7 @@ import { saturdayClient } from "../../utils/client"
import type { components } from "../../types/saturday" import type { components } from "../../types/saturday"
type NotificationPreferenceItem = components["schemas"]["NotificationPreferenceItem"] type NotificationPreferenceItem = components["schemas"]["NotificationPreferenceItem"]
type UpdateNotificationPreferencesInputBody = components["schemas"]["UpdateNotificationPreferencesInputBody"] type Item = components["schemas"]["Item"]
interface NotificationPreferencesProps { interface NotificationPreferencesProps {
token: string token: string
@ -28,7 +28,7 @@ export default function NotificationPreferences({ token }: NotificationPreferenc
setErrorMessage("") setErrorMessage("")
try { try {
const { data, error } = await saturdayClient.GET("/notification-preferences", { const { data, error } = await saturdayClient.GET("/member/notification-preferences", {
params: { params: {
header: { header: {
Authorization: `Bearer ${token}`, Authorization: `Bearer ${token}`,
@ -63,20 +63,21 @@ export default function NotificationPreferences({ token }: NotificationPreferenc
)) ))
try { try {
// Create the request body with all preferences // Create the request body with all preferences as an array of Item objects
const requestBody: UpdateNotificationPreferencesInputBody = preferences.reduce((acc, pref) => { const preferencesArray: Item[] = preferences.map(pref => ({
const enabled = pref.notificationType === notificationType ? newValue : pref.enabled notificationType: pref.notificationType,
acc[pref.notificationType] = enabled enabled: pref.notificationType === notificationType ? newValue : pref.enabled,
return acc }))
}, {} as UpdateNotificationPreferencesInputBody)
const { error } = await saturdayClient.PUT("/notification-preferences", { const { error } = await saturdayClient.PUT("/member/notification-preferences", {
params: { params: {
header: { header: {
Authorization: `Bearer ${token}`, Authorization: `Bearer ${token}`,
}, },
}, },
body: requestBody, body: {
preferences: preferencesArray,
},
}) })
if (error) { if (error) {