diff --git a/app/routes/account.$accountId.$appId.notifications/components/AppNotificationsAlert/AppNotificationsAlert.tsx b/app/routes/account.$accountId.$appId.notifications/components/AppNotificationsAlert/AppNotificationsAlert.tsx index 727b7b533..a8c3f9b54 100644 --- a/app/routes/account.$accountId.$appId.notifications/components/AppNotificationsAlert/AppNotificationsAlert.tsx +++ b/app/routes/account.$accountId.$appId.notifications/components/AppNotificationsAlert/AppNotificationsAlert.tsx @@ -48,31 +48,43 @@ export default function AppNotificationsAlert({ }: NotificationsAlertFormProps) { const { notifications } = app const fetcher = useFetcher() + useActionNotification(fetcher.data) + + const notificationEvents = notifications[0]?.appNotification?.events const getNotificationCheckedState = useCallback( - (level: NotificationLevel) => { - // @ts-ignore - return Object.keys(notifications).length > 0 && notifications[level] - ? // @ts-ignore - (notifications[level] as boolean) - : DEFAULT_ALERT_PERCENTAGES[level] - }, - [notifications], + (level: NotificationLevel) => + Object.keys(notificationEvents).length > 0 && + notificationEvents.hasOwnProperty(level) + ? (notificationEvents[level] as boolean) + : DEFAULT_ALERT_PERCENTAGES[level], + [notificationEvents], ) const updateNotification = (level: string, value: string) => { + const otherNotificationEventsValues = NOTIFICATIONS_ALERT_LEVELS.filter( + (notificationLevel) => notificationLevel !== level, + ).reduce( + (result, notificationLevel) => ({ + ...result, + [notificationLevel]: getNotificationCheckedState(notificationLevel) + ? "on" + : "off", + }), + {}, + ) + fetcher.submit( { [level]: value, + ...otherNotificationEventsValues, }, { - method: "PUT", + method: "POST", }, ) } - useActionNotification(fetcher.data) - return ( @@ -89,10 +101,10 @@ export default function AppNotificationsAlert({ { - updateNotification(level, event.currentTarget.value) + updateNotification(level, event.currentTarget.checked ? "on" : "off") trackEvent({ category: AnalyticCategories.app, action: AnalyticActions.app_notifications,