import React, { useEffect, useLayoutEffect, useState } from 'react'; import { StackNavigationProp } from '@react-navigation/stack'; import { useNavigation } from '@react-navigation/native'; import StatusBar from '../../containers/StatusBar'; import * as List from '../../containers/List'; import I18n from '../../i18n'; import SafeAreaView from '../../containers/SafeAreaView'; import ActivityIndicator from '../../containers/ActivityIndicator'; import { getUserSelector } from '../../selectors/login'; import { ProfileStackParamList } from '../../stacks/types'; import { INotificationPreferences } from '../../definitions'; import { Services } from '../../lib/services'; import { useAppSelector } from '../../lib/hooks'; import ListPicker from './ListPicker'; import log from '../../lib/methods/helpers/log'; const UserNotificationPreferencesView = () => { const [preferences, setPreferences] = useState({} as INotificationPreferences); const [loading, setLoading] = useState(false); const navigation = useNavigation>(); const userId = useAppSelector(state => getUserSelector(state).id); useLayoutEffect(() => { navigation.setOptions({ title: I18n.t('Notification_Preferences') }); }, [navigation]); useEffect(() => { async function getPreferences() { try { const result = await Services.getUserPreferences(userId); if (result.success) { setLoading(true); setPreferences(result.preferences); } } catch (error) { log(error); } } getPreferences(); }, [userId]); const onValueChangePicker = async (param: { [key: string]: string }, onError: () => void) => { try { const result = await Services.setUserPreferences(userId, param); if (result.success) { const { user: { settings } } = result; setPreferences(settings.preferences); } } catch (error) { log(error); onError(); } }; return ( {loading ? ( <> ) : ( )} ); }; export default UserNotificationPreferencesView;