1 | import { NativeModules, Platform, processColor } from 'react-native';
|
2 | export async function getCalendarsAsync(entityType) {
|
3 | if (!entityType) {
|
4 | return NativeModules.ExponentCalendar.getCalendarsAsync(null);
|
5 | }
|
6 | return NativeModules.ExponentCalendar.getCalendarsAsync(entityType);
|
7 | }
|
8 | export async function createCalendarAsync(details = {}) {
|
9 | let color = details.color ? processColor(details.color) : undefined;
|
10 | const newDetails = { ...details, id: undefined, color };
|
11 | return NativeModules.ExponentCalendar.saveCalendarAsync(newDetails);
|
12 | }
|
13 | export async function updateCalendarAsync(id, details = {}) {
|
14 | if (!id) {
|
15 | throw new Error('updateCalendarAsync must be called with an id (string) of the target calendar');
|
16 | }
|
17 | let color = details.color ? processColor(details.color) : undefined;
|
18 | if (Platform.OS === 'android') {
|
19 | if (details.hasOwnProperty('source') ||
|
20 | details.hasOwnProperty('color') ||
|
21 | details.hasOwnProperty('allowsModifications') ||
|
22 | details.hasOwnProperty('allowedAvailabilities') ||
|
23 | details.hasOwnProperty('isPrimary') ||
|
24 | details.hasOwnProperty('ownerAccount') ||
|
25 | details.hasOwnProperty('timeZone') ||
|
26 | details.hasOwnProperty('allowedReminders') ||
|
27 | details.hasOwnProperty('allowedAttendeeTypes') ||
|
28 | details.hasOwnProperty('accessLevel')) {
|
29 | console.warn('updateCalendarAsync was called with one or more read-only properties, which will not be updated');
|
30 | }
|
31 | }
|
32 | else {
|
33 | if (details.hasOwnProperty('source') ||
|
34 | details.hasOwnProperty('type') ||
|
35 | details.hasOwnProperty('entityType') ||
|
36 | details.hasOwnProperty('allowsModifications') ||
|
37 | details.hasOwnProperty('allowedAvailabilities')) {
|
38 | console.warn('updateCalendarAsync was called with one or more read-only properties, which will not be updated');
|
39 | }
|
40 | }
|
41 | const newDetails = { ...details, id, color };
|
42 | return NativeModules.ExponentCalendar.saveCalendarAsync(newDetails);
|
43 | }
|
44 | export async function deleteCalendarAsync(id) {
|
45 | if (!id) {
|
46 | throw new Error('deleteCalendarAsync must be called with an id (string) of the target calendar');
|
47 | }
|
48 | return NativeModules.ExponentCalendar.deleteCalendarAsync(id);
|
49 | }
|
50 | export async function getEventsAsync(calendarIds, startDate, endDate) {
|
51 | if (!startDate) {
|
52 | throw new Error('getEventsAsync must be called with a startDate (date) to search for events');
|
53 | }
|
54 | if (!endDate) {
|
55 | throw new Error('getEventsAsync must be called with an endDate (date) to search for events');
|
56 | }
|
57 | if (!calendarIds || !calendarIds.length) {
|
58 | throw new Error('getEventsAsync must be called with a non-empty array of calendarIds to search');
|
59 | }
|
60 | return NativeModules.ExponentCalendar.getEventsAsync(startDate, endDate, calendarIds);
|
61 | }
|
62 | export async function getEventAsync(id, { futureEvents = false, instanceStartDate } = {}) {
|
63 | if (!id) {
|
64 | throw new Error('getEventAsync must be called with an id (string) of the target event');
|
65 | }
|
66 | if (Platform.OS === 'ios') {
|
67 | return NativeModules.ExponentCalendar.getEventByIdAsync(id, instanceStartDate);
|
68 | }
|
69 | else {
|
70 | return NativeModules.ExponentCalendar.getEventByIdAsync(id);
|
71 | }
|
72 | }
|
73 | export async function createEventAsync(calendarId, details = {}) {
|
74 | if (!calendarId) {
|
75 | throw new Error('createEventAsync must be called with an id (string) of the target calendar');
|
76 | }
|
77 | if (Platform.OS === 'android') {
|
78 | if (!details.startDate) {
|
79 | throw new Error('createEventAsync requires a startDate (Date)');
|
80 | }
|
81 | if (!details.endDate) {
|
82 | throw new Error('createEventAsync requires an endDate (Date)');
|
83 | }
|
84 | if (!details.timeZone) {
|
85 | throw new Error('createEventAsync requires a timeZone (string)');
|
86 | }
|
87 | }
|
88 | const newDetails = {
|
89 | ...details,
|
90 | id: undefined,
|
91 | calendarId: calendarId === DEFAULT ? undefined : calendarId,
|
92 | };
|
93 | return NativeModules.ExponentCalendar.saveEventAsync(newDetails, {});
|
94 | }
|
95 | export async function updateEventAsync(id, details = {}, { futureEvents = false, instanceStartDate } = {}) {
|
96 | if (!id) {
|
97 | throw new Error('updateEventAsync must be called with an id (string) of the target event');
|
98 | }
|
99 | if (Platform.OS === 'ios') {
|
100 | if (details.hasOwnProperty('creationDate') ||
|
101 | details.hasOwnProperty('lastModifiedDate') ||
|
102 | details.hasOwnProperty('originalStartDate') ||
|
103 | details.hasOwnProperty('isDetached') ||
|
104 | details.hasOwnProperty('status') ||
|
105 | details.hasOwnProperty('organizer')) {
|
106 | console.warn('updateEventAsync was called with one or more read-only properties, which will not be updated');
|
107 | }
|
108 | }
|
109 | const newDetails = { ...details, id, instanceStartDate };
|
110 | return NativeModules.ExponentCalendar.saveEventAsync(newDetails, { futureEvents });
|
111 | }
|
112 | export async function deleteEventAsync(id, { futureEvents = false, instanceStartDate } = {}) {
|
113 | if (!id) {
|
114 | throw new Error('deleteEventAsync must be called with an id (string) of the target event');
|
115 | }
|
116 | return NativeModules.ExponentCalendar.deleteEventAsync({ id, instanceStartDate }, { futureEvents });
|
117 | }
|
118 | export async function getAttendeesForEventAsync(id, { futureEvents = false, instanceStartDate } = {}) {
|
119 | if (!id) {
|
120 | throw new Error('getAttendeesForEventAsync must be called with an id (string) of the target event');
|
121 | }
|
122 |
|
123 | const params = Platform.OS === 'ios' ? { id, instanceStartDate } : id;
|
124 | return NativeModules.ExponentCalendar.getAttendeesForEventAsync(params);
|
125 | }
|
126 | export async function createAttendeeAsync(eventId, details = {}) {
|
127 | if (Platform.OS === 'ios') {
|
128 | throw new Error('createAttendeeAsync is not available on iOS');
|
129 | }
|
130 | if (!eventId) {
|
131 | throw new Error('createAttendeeAsync must be called with an id (string) of the target event');
|
132 | }
|
133 | if (!details.email) {
|
134 | throw new Error('createAttendeeAsync requires an email (string)');
|
135 | }
|
136 | if (!details.role) {
|
137 | throw new Error('createAttendeeAsync requires a role (string)');
|
138 | }
|
139 | if (!details.type) {
|
140 | throw new Error('createAttendeeAsync requires a type (string)');
|
141 | }
|
142 | if (!details.status) {
|
143 | throw new Error('createAttendeeAsync requires a status (string)');
|
144 | }
|
145 | const newDetails = { ...details, id: undefined };
|
146 | return NativeModules.ExponentCalendar.saveAttendeeForEventAsync(newDetails, eventId);
|
147 | }
|
148 | export async function updateAttendeeAsync(id, details = {}) {
|
149 | if (Platform.OS === 'ios') {
|
150 | throw new Error('updateAttendeeAsync is not available on iOS');
|
151 | }
|
152 | if (!id) {
|
153 | throw new Error('updateAttendeeAsync must be called with an id (string) of the target event');
|
154 | }
|
155 | const newDetails = { ...details, id };
|
156 | return NativeModules.ExponentCalendar.saveAttendeeForEventAsync(newDetails, null);
|
157 | }
|
158 | export async function deleteAttendeeAsync(id) {
|
159 | if (Platform.OS === 'ios') {
|
160 | throw new Error('deleteAttendeeAsync is not available on iOS');
|
161 | }
|
162 | if (!id) {
|
163 | throw new Error('deleteAttendeeAsync must be called with an id (string) of the target event');
|
164 | }
|
165 | return NativeModules.ExponentCalendar.deleteAttendeeAsync(id);
|
166 | }
|
167 | export async function getRemindersAsync(calendarIds, status, startDate, endDate) {
|
168 | if (Platform.OS === 'android') {
|
169 | throw new Error('getRemindersAsync is not available on Android');
|
170 | }
|
171 | if (status && !startDate) {
|
172 | throw new Error('getRemindersAsync must be called with a startDate (date) to search for reminders');
|
173 | }
|
174 | if (status && !endDate) {
|
175 | throw new Error('getRemindersAsync must be called with an endDate (date) to search for reminders');
|
176 | }
|
177 | if (!calendarIds || !calendarIds.length) {
|
178 | throw new Error('getRemindersAsync must be called with a non-empty array of calendarIds to search');
|
179 | }
|
180 | return NativeModules.ExponentCalendar.getRemindersAsync(startDate || null, endDate || null, calendarIds, status || null);
|
181 | }
|
182 | export async function getReminderAsync(id) {
|
183 | if (Platform.OS === 'android') {
|
184 | throw new Error('getReminderAsync is not available on Android');
|
185 | }
|
186 | if (!id) {
|
187 | throw new Error('getReminderAsync must be called with an id (string) of the target reminder');
|
188 | }
|
189 | return NativeModules.ExponentCalendar.getReminderByIdAsync(id);
|
190 | }
|
191 | export async function createReminderAsync(calendarId, details = {}) {
|
192 | if (Platform.OS === 'android') {
|
193 | throw new Error('createReminderAsync is not available on Android');
|
194 | }
|
195 | if (!calendarId) {
|
196 | throw new Error('createReminderAsync must be called with an id (string) of the target calendar');
|
197 | }
|
198 | const newDetails = {
|
199 | ...details,
|
200 | id: undefined,
|
201 | calendarId: calendarId === DEFAULT ? undefined : calendarId,
|
202 | };
|
203 | return NativeModules.ExponentCalendar.saveReminderAsync(newDetails);
|
204 | }
|
205 | export async function updateReminderAsync(id, details = {}) {
|
206 | if (Platform.OS === 'android') {
|
207 | throw new Error('updateReminderAsync is not available on Android');
|
208 | }
|
209 | if (!id) {
|
210 | throw new Error('updateReminderAsync must be called with an id (string) of the target reminder');
|
211 | }
|
212 | if (details.hasOwnProperty('creationDate') || details.hasOwnProperty('lastModifiedDate')) {
|
213 | console.warn('updateReminderAsync was called with one or more read-only properties, which will not be updated');
|
214 | }
|
215 | const newDetails = { ...details, id };
|
216 | return NativeModules.ExponentCalendar.saveReminderAsync(newDetails);
|
217 | }
|
218 | export async function deleteReminderAsync(id) {
|
219 | if (Platform.OS === 'android') {
|
220 | throw new Error('deleteReminderAsync is not available on Android');
|
221 | }
|
222 | if (!id) {
|
223 | throw new Error('deleteReminderAsync must be called with an id (string) of the target reminder');
|
224 | }
|
225 | return NativeModules.ExponentCalendar.deleteReminderAsync(id);
|
226 | }
|
227 | export async function getSourcesAsync() {
|
228 | if (Platform.OS === 'android') {
|
229 | throw new Error('getSourcesAsync is not available on Android');
|
230 | }
|
231 | return NativeModules.ExponentCalendar.getSourcesAsync();
|
232 | }
|
233 | export async function getSourceAsync(id) {
|
234 | if (Platform.OS === 'android') {
|
235 | throw new Error('getSourceAsync is not available on Android');
|
236 | }
|
237 | if (!id) {
|
238 | throw new Error('getSourceAsync must be called with an id (string) of the target source');
|
239 | }
|
240 | return NativeModules.ExponentCalendar.getSourceByIdAsync(id);
|
241 | }
|
242 | export function openEventInCalendar(id) {
|
243 | if (Platform.OS === 'ios') {
|
244 | console.warn('openEventInCalendar is not available on iOS');
|
245 | return;
|
246 | }
|
247 | if (!id) {
|
248 | throw new Error('openEventInCalendar must be called with an id (string) of the target event');
|
249 | }
|
250 | return NativeModules.ExponentCalendar.openEventInCalendar(parseInt(id, 10));
|
251 | }
|
252 | export const EntityTypes = {
|
253 | EVENT: 'event',
|
254 | REMINDER: 'reminder',
|
255 | };
|
256 | export const Frequency = {
|
257 | DAILY: 'daily',
|
258 | WEEKLY: 'weekly',
|
259 | MONTHLY: 'monthly',
|
260 | YEARLY: 'yearly',
|
261 | };
|
262 | export const Availability = {
|
263 | NOT_SUPPORTED: 'notSupported',
|
264 | BUSY: 'busy',
|
265 | FREE: 'free',
|
266 | TENTATIVE: 'tentative',
|
267 | UNAVAILABLE: 'unavailable',
|
268 | };
|
269 | export const CalendarType = {
|
270 | LOCAL: 'local',
|
271 | CALDAV: 'caldav',
|
272 | EXCHANGE: 'exchange',
|
273 | SUBSCRIBED: 'subscribed',
|
274 | BIRTHDAYS: 'birthdays',
|
275 | };
|
276 | export const EventStatus = {
|
277 | NONE: 'none',
|
278 | CONFIRMED: 'confirmed',
|
279 | TENTATIVE: 'tentative',
|
280 | CANCELED: 'canceled',
|
281 | };
|
282 | export const SourceType = {
|
283 | LOCAL: 'local',
|
284 | EXCHANGE: 'exchange',
|
285 | CALDAV: 'caldav',
|
286 | MOBILEME: 'mobileme',
|
287 | SUBSCRIBED: 'subscribed',
|
288 | BIRTHDAYS: 'birthdays',
|
289 | };
|
290 | export const AttendeeRole = {
|
291 | UNKNOWN: 'unknown',
|
292 | REQUIRED: 'required',
|
293 | OPTIONAL: 'optional',
|
294 | CHAIR: 'chair',
|
295 | NON_PARTICIPANT: 'nonParticipant',
|
296 | ATTENDEE: 'attendee',
|
297 | ORGANIZER: 'organizer',
|
298 | PERFORMER: 'performer',
|
299 | SPEAKER: 'speaker',
|
300 | NONE: 'none',
|
301 | };
|
302 | export const AttendeeStatus = {
|
303 | UNKNOWN: 'unknown',
|
304 | PENDING: 'pending',
|
305 | ACCEPTED: 'accepted',
|
306 | DECLINED: 'declined',
|
307 | TENTATIVE: 'tentative',
|
308 | DELEGATED: 'delegated',
|
309 | COMPLETED: 'completed',
|
310 | IN_PROCESS: 'inProcess',
|
311 | INVITED: 'invited',
|
312 | NONE: 'none',
|
313 | };
|
314 | export const AttendeeType = {
|
315 | UNKNOWN: 'unknown',
|
316 | PERSON: 'person',
|
317 | ROOM: 'room',
|
318 | GROUP: 'group',
|
319 | RESOURCE: 'resource',
|
320 | OPTIONAL: 'optional',
|
321 | REQUIRED: 'required',
|
322 | NONE: 'none',
|
323 | };
|
324 | export const AlarmMethod = {
|
325 | ALARM: 'alarm',
|
326 | ALERT: 'alert',
|
327 | EMAIL: 'email',
|
328 | SMS: 'sms',
|
329 | DEFAULT: 'default',
|
330 | };
|
331 | export const EventAccessLevel = {
|
332 | CONFIDENTIAL: 'confidential',
|
333 | PRIVATE: 'private',
|
334 | PUBLIC: 'public',
|
335 | DEFAULT: 'default',
|
336 | };
|
337 | export const CalendarAccessLevel = {
|
338 | CONTRIBUTOR: 'contributor',
|
339 | EDITOR: 'editor',
|
340 | FREEBUSY: 'freebusy',
|
341 | OVERRIDE: 'override',
|
342 | OWNER: 'owner',
|
343 | READ: 'read',
|
344 | RESPOND: 'respond',
|
345 | ROOT: 'root',
|
346 | NONE: 'none',
|
347 | };
|
348 | export const ReminderStatus = {
|
349 | COMPLETED: 'completed',
|
350 | INCOMPLETE: 'incomplete',
|
351 | };
|
352 | export const DEFAULT = 'default';
|
353 |
|
\ | No newline at end of file |