Untitled
unknown
plain_text
2 years ago
2.9 kB
6
Indexable
import React from 'react'; import { Text, TouchableOpacity, View } from 'react-native-ui-lib'; import { useTranslation } from 'react-i18next'; import { Icon } from '../ui'; import { Dimensions, PermissionsAndroid } from 'react-native'; import * as AddCalendarEvent from 'react-native-add-calendar-event'; import ModalController from './ModalController'; export function AddPhoneCalendar({ title, startDate }: any) { const { t } = useTranslation(); const height = Dimensions.get('screen').height; const addEventToCalendar = async () => { try { const permission = PermissionsAndroid.PERMISSIONS.WRITE_CALENDAR; const granted = await PermissionsAndroid.request(permission, { title: 'Calendar Permission', message: 'This app needs calendar access to add events', buttonNegative: 'Cancel', buttonPositive: 'OK', }); if (granted === PermissionsAndroid.RESULTS.GRANTED) { const calendarEvent = { title: title, startDate: startDate, notes: title, }; AddCalendarEvent.presentEventCreatingDialog(calendarEvent) .then(() => { ModalController.showModal({ type: 'success', externalHeight: height - 350, props: { title: t('addEventCalendar', { type: t('Buy'), }), }, }); }) .catch(() => { ModalController.showModal({ type: 'errorEvent', externalHeight: height - 300, props: {}, }); }); } else { ModalController.showModal({ type: 'errorEvent', externalHeight: height - 300, props: {}, }); } } catch (error) { ModalController.showModal({ type: 'errorEvent', externalHeight: height - 300, props: {}, }); } }; const handleFirstTouchableOpacityPress = () => { addEventToCalendar(); }; return ( <View marginL-20 marginT-10> <Text heading3 primaryText> {t('addPhoneCalendar')} </Text> <View marginT-20> <TouchableOpacity onPress={handleFirstTouchableOpacityPress}> <View row> <Icon name="email" width={20} height={25} /> <Text centerV marginL-4 primaryText> {t('mailAdress')} </Text> </View> </TouchableOpacity> <View marginT-20 /> <TouchableOpacity onPress={handleFirstTouchableOpacityPress}> <View row> <View> <Icon name="email" width={20} height={25} /> </View> <Text marginL-4 primaryText> {t('work')} </Text> </View> </TouchableOpacity> </View> </View> ); }
Editor is loading...
Leave a Comment