Set notification settings based on session

This commit is contained in:
Maarten 2024-08-09 12:27:15 +02:00
parent af72b25932
commit 85dc440fe8

View file

@ -11,6 +11,7 @@ import { ThemedView } from '@/lib/components/ThemedView';
import { ThemedText } from '@/lib/components/ThemedText'; import { ThemedText } from '@/lib/components/ThemedText';
import { Request } from '@/lib/services/request'; import { Request } from '@/lib/services/request';
import { useToken } from '@/lib/context/AppProvider'; import { useToken } from '@/lib/context/AppProvider';
import { Message } from '@/lib/services/message';
export default function CategoryScreen() { export default function CategoryScreen() {
const colorScheme = useColorScheme() ?? 'light'; const colorScheme = useColorScheme() ?? 'light';
@ -26,15 +27,33 @@ export default function CategoryScreen() {
let currentEdit = ''; let currentEdit = '';
// Load item from storage // Set page title
useEffect( () => { useEffect( () => {
// Set page title // Set page title
navigation.setOptions( { title: ( 'Notificaties' ) } ); 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( () => { useEffect( () => {
updateSession(); updateSession();
}, [isSameDayEnabled, sameDay, isDayBeforeEnabled, dayBefore] ); }, [ isSameDayEnabled, sameDay, isDayBeforeEnabled, dayBefore ] );
// Open time picker // Open time picker
const selectTime = (type: string) => { const selectTime = (type: string) => {
@ -88,9 +107,11 @@ export default function CategoryScreen() {
notification_same_day: isSameDayEnabled ? sameDay : 'off', notification_same_day: isSameDayEnabled ? sameDay : 'off',
}; };
Request.post('sessions/update', postData).then((response) => { Request.post( 'sessions/update', postData ).then( (response) => {
console.log('response', response); if (!response.success) {
}) Message.error( 'Er ging iets mis. Probeer het later opnieuw.' );
}
} )
} }
return ( return (