Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ICS file details to Calendar #404

Open
tragicmj opened this issue Apr 12, 2022 · 0 comments
Open

Add ICS file details to Calendar #404

tragicmj opened this issue Apr 12, 2022 · 0 comments

Comments

@tragicmj
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant