mirror of
https://github.com/m1ngsama/FUJI.git
synced 2025-12-24 10:51:27 +00:00
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:
parent
450d339237
commit
c6e5a9535a
1 changed files with 11 additions and 10 deletions
|
|
@ -4,7 +4,7 @@ import { saturdayClient } from "../../utils/client"
|
|||
import type { components } from "../../types/saturday"
|
||||
|
||||
type NotificationPreferenceItem = components["schemas"]["NotificationPreferenceItem"]
|
||||
type UpdateNotificationPreferencesInputBody = components["schemas"]["UpdateNotificationPreferencesInputBody"]
|
||||
type Item = components["schemas"]["Item"]
|
||||
|
||||
interface NotificationPreferencesProps {
|
||||
token: string
|
||||
|
|
@ -28,7 +28,7 @@ export default function NotificationPreferences({ token }: NotificationPreferenc
|
|||
setErrorMessage("")
|
||||
|
||||
try {
|
||||
const { data, error } = await saturdayClient.GET("/notification-preferences", {
|
||||
const { data, error } = await saturdayClient.GET("/member/notification-preferences", {
|
||||
params: {
|
||||
header: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
|
|
@ -63,20 +63,21 @@ export default function NotificationPreferences({ token }: NotificationPreferenc
|
|||
))
|
||||
|
||||
try {
|
||||
// Create the request body with all preferences
|
||||
const requestBody: UpdateNotificationPreferencesInputBody = preferences.reduce((acc, pref) => {
|
||||
const enabled = pref.notificationType === notificationType ? newValue : pref.enabled
|
||||
acc[pref.notificationType] = enabled
|
||||
return acc
|
||||
}, {} as UpdateNotificationPreferencesInputBody)
|
||||
// Create the request body with all preferences as an array of Item objects
|
||||
const preferencesArray: Item[] = preferences.map(pref => ({
|
||||
notificationType: pref.notificationType,
|
||||
enabled: pref.notificationType === notificationType ? newValue : pref.enabled,
|
||||
}))
|
||||
|
||||
const { error } = await saturdayClient.PUT("/notification-preferences", {
|
||||
const { error } = await saturdayClient.PUT("/member/notification-preferences", {
|
||||
params: {
|
||||
header: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
},
|
||||
body: requestBody,
|
||||
body: {
|
||||
preferences: preferencesArray,
|
||||
},
|
||||
})
|
||||
|
||||
if (error) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue