EasyCord LogoDocs
Plugin EcosystemData & Storage

Calendar

import { Callout } from 'fumadocs-ui/components/callout';

Read and write events to the device's native calendar application.

Overview

The Calendar API provides bidirectional syncing with native calendars (Apple Calendar, Google Calendar on Android). You can query existing user events or seamlessly add new appointments generated within your application.

Enterprise React Example

In a corporate scheduling tool, you can offer users a way to export meetings straight to their local calendar.

import React, { useState, useEffect } from 'react';

interface EventData {
  title: string;
  startDate: string;
  endDate: string;
  location: string;
}

export default function MeetingExporter({ meeting }: { meeting: EventData }) {
  const [permissionGranted, setPermissionGranted] = useState(false);
  const [syncing, setSyncing] = useState(false);

  useEffect(() => {
    async function checkPerms() {
      const status = await window.easycord.calendar.checkPermission();
      setPermissionGranted(status === 'granted');
    }
    checkPerms();
  }, []);

  const exportToCalendar = async () => {
    try {
      setSyncing(true);
      if (!permissionGranted) {
        const requested = await window.easycord.calendar.requestPermission();
        if (requested !== 'granted') {
          alert('Calendar access is required to export meetings.');
          setSyncing(false);
          return;
        }
        setPermissionGranted(true);
      }

      await window.easycord.calendar.createEvent({
        title: meeting.title,
        startDate: meeting.startDate,
        endDate: meeting.endDate,
        location: meeting.location,
        notes: "Exported from EasyCord Enterprise Scheduling"
      });

      alert('Meeting successfully exported to your device calendar!');
    } catch (err) {
      alert(`Export failed: ${err instanceof Error ? err.message : 'Unknown error'}`);
    } finally {
      setSyncing(false);
    }
  };

  return (
    <div className="border border-gray-200 p-4 rounded-md">
      <h4 className="font-bold mb-2">{meeting.title}</h4>
      <p className="text-sm text-gray-600">{new Date(meeting.startDate).toLocaleString()}</p>
      <button
        onClick={exportToCalendar}
        disabled={syncing}
        className="mt-4 bg-purple-600 text-white px-4 py-2 rounded-md hover:bg-purple-700 disabled:bg-purple-300 transition-colors"
      >
        {syncing ? 'Exporting...' : 'Add to Native Calendar'}
      </button>
    </div>
  );
}

API Reference

checkPermission()

Checks the current authorization status for accessing the user's calendar.

Returns: Promise<'granted' | 'denied' | 'prompt'>

requestPermission()

Prompts the user with a native dialogue to grant calendar access.

Returns: Promise<'granted' | 'denied'>

getEvents(options)

Retrieves events falling within a specific date range.

Parameters:

  • options (Object):
    • startDate (string): ISO 8601 string of the start date.
    • endDate (string): ISO 8601 string of the end date.

Returns: Promise<EventData[]>

createEvent(event)

Creates a new event in the user's default calendar.

Parameters:

  • event (Object):
    • title (string): The title of the event.
    • startDate (string): ISO 8601 string (e.g. 2026-08-01T10:00:00Z).
    • endDate (string): ISO 8601 string.
    • location (string, optional): Physical address or meeting link.
    • notes (string, optional): Additional description.

Returns: Promise<{eventId: string}>