From 85dc440fe8f5c4d0e6bee8b5926ffcb1c9d52901 Mon Sep 17 00:00:00 2001 From: Maarten Date: Fri, 9 Aug 2024 12:27:15 +0200 Subject: [PATCH] Set notification settings based on session --- app/(settings)/notifications.tsx | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/app/(settings)/notifications.tsx b/app/(settings)/notifications.tsx index 7ad436a..f15d66c 100644 --- a/app/(settings)/notifications.tsx +++ b/app/(settings)/notifications.tsx @@ -11,6 +11,7 @@ import { ThemedView } from '@/lib/components/ThemedView'; import { ThemedText } from '@/lib/components/ThemedText'; import { Request } from '@/lib/services/request'; import { useToken } from '@/lib/context/AppProvider'; +import { Message } from '@/lib/services/message'; export default function CategoryScreen() { const colorScheme = useColorScheme() ?? 'light'; @@ -26,15 +27,33 @@ export default function CategoryScreen() { let currentEdit = ''; - // Load item from storage + // Set page title useEffect( () => { // Set page title navigation.setOptions( { title: ( 'Notificaties' ) } ); }, [] ); + // Set session data + useEffect( () => { + if (session.notifications.dayBefore === 'off') { + setIsDayBeforeEnabled( false ); + } else { + setIsDayBeforeEnabled( true ); + setDayBefore( session.notifications.dayBefore ); + } + + if (session.notifications.sameDay === 'off') { + setIsSameDayEnabled( false ); + } else { + setIsSameDayEnabled( true ); + setSameDay( session.notifications.dayBefore ); + } + }, [ session ] ); + + // Update session when something changes useEffect( () => { updateSession(); - }, [isSameDayEnabled, sameDay, isDayBeforeEnabled, dayBefore] ); + }, [ isSameDayEnabled, sameDay, isDayBeforeEnabled, dayBefore ] ); // Open time picker const selectTime = (type: string) => { @@ -88,9 +107,11 @@ export default function CategoryScreen() { notification_same_day: isSameDayEnabled ? sameDay : 'off', }; - Request.post('sessions/update', postData).then((response) => { - console.log('response', response); - }) + Request.post( 'sessions/update', postData ).then( (response) => { + if (!response.success) { + Message.error( 'Er ging iets mis. Probeer het later opnieuw.' ); + } + } ) } return (