wmcmahan / react-native-calendar-events

📆 React Native Module for iOS and Android Calendar Events
MIT License
905 stars 292 forks source link

Add ICS file details to Calendar #404

Open tragicmj opened 2 years ago

tragicmj commented 2 years ago

Has anyone tried adding ics file details to Calendar using this package?

Environment

"cal-parser": "^1.0.2", "react-native-calendar-events": "^2.2.0", "react": "17.0.2", "react-native": "0.66.1",

Steps to Reproduce

    openCalendar = async (item) => {
        let res = await RNCalendarEvents.findCalendars();
        let calendar = res.filter((x)=>{return x.isPrimary && x.allowsModifications})
        const icsRes = await fetch(item);
        const icsData = await icsRes.text();
        const parsed = ical.parseString(icsData);
        console.log(parsed.events[0])
        let title = parsed?.events[0]?.summary?.value
        let startDate = new Date(parsed?.events[0]?.dtstart.value).toISOString()
        let endDate = new Date(parsed?.events[0]?.dtend.value).toISOString()
        let location = parsed?.events[0]?.location.value
        let description = parsed?.events[0]?.description.value
        // let url = parsed?.events[0]?.x-google-conference?.value
        let id = parsed?.events[0]?.uid.value
        let organizer = parsed?.events[0]?.organizer.params.cn
        console.log( parsed?.events[0]?.(x-google-conference)?.value)
        Permission.requestMultiple([PERMISSION_TYPE.writeCalendar]);
        const granted = await Permission.checkPermission(
            PERMISSION_TYPE.writeCalendar,
        );
        if(granted){
            if(parsed?.events !== undefined && parsed?.events?.length !== 0){
                RNCalendarEvents.saveEvent(title,{
                    calendarId: `${calendar[0].id}`,
                    startDate: startDate,
                    endDate: endDate,
                    organizer: organizer,
                    url: url,
                    location: location,
                    description: description,
                }).then(() => {
                    ShowMessage.message("Event Added Successfully to calendars")
                })
                .catch((error) => {
                    console.log(error)
                });
            }   
        } else{
            Permission.requestMultiple([PERMISSION_TYPE.writeCalendar]);
        }
    }

Expected Behavior

The above code should add start Date, endD ate, organizer, url, location & description to calendar.

Actual Behavior

I am using cal-parser to convert vcalendar to JSON string I am unable to add description and organizer into calendar If anyone has anyone better one please let me know in comments below