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

Update email handlers #268

Open
wants to merge 1 commit 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
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,24 @@ public void setEmail(@Nullable String email) {
}

@ReactMethod
public void updateEmail(String email) {
public void updateEmail(String email, final Promise promise) {
IterableLogger.d(TAG, "updateEmail: " + email);
IterableApi.getInstance().updateEmail(email);
}
IterableApi.getInstance().updateEmail(
email,
new IterableHelper.SuccessHandler() {
@Override
public void onSuccess(@NonNull JSONObject data) {
promise.resolve(data);
}
},
new IterableHelper.FailureHandler() {
@Override
public void onFailure(@NonNull String reason, @Nullable JSONObject data) {
promise.reject("", reason);
}
}
);
}

@ReactMethod
public void getEmail(Promise promise) {
Expand Down
4 changes: 3 additions & 1 deletion ios/RNIterableAPI/RNIterableAPI.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ @interface RCT_EXTERN_REMAP_MODULE(RNIterableAPI, ReactIterableAPI, NSObject)
RCT_EXTERN_METHOD(updateUser: (nonnull NSDictionary *) dataFields
mergeNestedObjects: (BOOL) mergeNestedObjects)

RCT_EXTERN_METHOD(updateEmail: (nonnull NSString *) email)
RCT_EXTERN_METHOD(updateEmail: (nonnull NSString *) email
resolver: (RCTPromiseResolveBlock) resolve
rejecter: (RCTPromiseRejectBlock) reject)

RCT_EXTERN_METHOD(handleAppLink: (nonnull NSString *) appLink
resolver: (RCTPromiseResolveBlock) resolve
Expand Down
17 changes: 12 additions & 5 deletions ios/RNIterableAPI/ReactIterableAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,18 @@ class ReactIterableAPI: RCTEventEmitter {
IterableAPI.updateUser(dataFields, mergeNestedObjects: mergeNestedObjects)
}

@objc(updateEmail:)
func updateEmail(email: String) {
ITBInfo()

IterableAPI.updateEmail(email, onSuccess: nil, onFailure: nil)
@objc(updateEmail:resolver:rejecter:)
func updateEmail(email: String, resolver: @escaping RCTPromiseResolveBlock, rejecter: @escaping RCTPromiseRejectBlock) {
let resolve = resolver
let reject = rejecter
ITBInfo()
func onSuccess(_ data: [AnyHashable: Any]?) {
resolve(data)
}
func onFailure(_ reason: String?, _ data: Data?) {
reject("", reason, nil)
}
IterableAPI.updateEmail(email, onSuccess: onSuccess, onFailure: onFailure)
}

@objc(handleAppLink:resolver:rejecter:)
Expand Down
9 changes: 5 additions & 4 deletions ts/Iterable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,11 @@ class Iterable {
*
* @param email the new email to set
*/
static updateEmail(email: string) {
console.log("updateEmail")
RNIterableAPI.updateEmail(email)
}
static updateEmail(email: string): Promise<void> {
return RNIterableAPI.updateEmail(email).catch((e: string) => {
throw new Error(e)
})
}

/**
*
Expand Down