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

Feat: Integrated the functionality to include attendees in the native calendar. #178

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ eventConfig object:
| allDay | boolean | |
| url | String | iOS only |
| notes | String | The notes (iOS) or description (Android) associated with the event. |
| attendees | Array | An array of attendees for the event. Each attendee should be an object with `name` and `email` properties. |
| navigationBarIOS | Object | config object for the navbar, see below |

The dates passed to this module are strings. If you use moment, you may get the right format via `momentInUTC.format('YYYY-MM-DDTHH:mm:ss.SSS[Z]')` the string may look eg. like this: `'2017-09-25T08:00:00.000Z'`.
Expand Down
18 changes: 18 additions & 0 deletions android/src/main/java/com/vonovak/AddCalendarEventModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,24 @@ private void presentEventAddingActivity(ReadableMap config) {
calendarIntent.putExtra("allDay", config.getBoolean("allDay"));
}

if (config.hasKey("attendees")) {
String emails = "";
ReadableArray attendees = config.getArray("attendees");
for (int i = 0; i < attendees.size(); i++) {
ReadableMap attendee = attendees.getMap(i);
ReadableType type = attendee.getType("email");

if (type == ReadableType.String) {
String email = attendee.getString("email");

emails += email;
emails += ",";
}
}

calendarIntent.putExtra(Intent.EXTRA_EMAIL, emails);

}

getReactApplicationContext().startActivityForResult(calendarIntent, ADD_EVENT_REQUEST_CODE, Bundle.EMPTY);
} catch (Exception e) {
Expand Down
25 changes: 25 additions & 0 deletions ios/AddCalendarEvent.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ - (NSDictionary *)constantsToExport
static NSString *const _notes = @"notes";
static NSString *const _url = @"url";
static NSString *const _allDay = @"allDay";
static NSString *const _attendees = @"attendees";

static NSString *const MODULE_NAME= @"AddCalendarEvent";

Expand Down Expand Up @@ -264,6 +265,30 @@ - (EKEvent *)createNewEventInstance {
if (options[_allDay]) {
event.allDay = [RCTConvert BOOL:options[_allDay]];
}
if (options[_attendees]) {
NSArray *invitees = [RCTConvert NSArray:options[_attendees]];

NSMutableArray *attendees = [NSMutableArray new];
for (int i = 0; i < [invitees count]; i++) {
Class className = NSClassFromString(@"EKAttendee");
id attendee = [className new];
NSDictionary *invitee = [invitees objectAtIndex:i];
NSString *name = [invitee valueForKey:@"name"];
NSString *email = [invitee valueForKey:@"email"];

[attendee setValue:email forKey:@"emailAddress"];
if(name && ![name isEqualToString:@"(null)"]) {
[attendee setValue:name forKey:@"firstName"];
}
else {
[attendee setValue:email forKey:@"firstName"];
}

[attendees addObject:attendee];
}

[event setValue:attendees forKey:_attendees];
}
return event;
}

Expand Down