diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..c8edec5 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1,3 @@ +# see https://help.github.com/en/articles/about-code-owners#example-of-a-codeowners-file + +* @pagopa/io-app \ No newline at end of file diff --git a/android/src/main/java/com/saranshmalik/rnzendeskchat/RNZendeskChat.java b/android/src/main/java/com/saranshmalik/rnzendeskchat/RNZendeskChat.java index ce6d074..16e8487 100644 --- a/android/src/main/java/com/saranshmalik/rnzendeskchat/RNZendeskChat.java +++ b/android/src/main/java/com/saranshmalik/rnzendeskchat/RNZendeskChat.java @@ -4,8 +4,16 @@ import android.app.Activity; import android.content.Context; +import android.content.Intent; + +import com.facebook.react.bridge.ActivityEventListener; import android.util.Log; +import androidx.annotation.Nullable; + +import com.facebook.react.bridge.Callback; + + import com.facebook.react.bridge.Promise; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContext; @@ -46,7 +54,7 @@ import zendesk.support.request.RequestActivity; import zendesk.support.requestlist.RequestListActivity; -public class RNZendeskChat extends ReactContextBaseJavaModule { +public class RNZendeskChat extends ReactContextBaseJavaModule implements ActivityEventListener { private ReactContext appContext; private static final String TAG = "ZendeskChat"; @@ -58,12 +66,18 @@ public class RNZendeskChat extends ReactContextBaseJavaModule { private String logId; private RequestProvider requestProvider; + @Nullable + private Callback onOpenTicketDismiss; + public RNZendeskChat(ReactApplicationContext reactContext) { super(reactContext); appContext = reactContext; customFields = new HashMap<>(); log = new StringBuffer(); tags = new ArrayList<>(); + + onOpenTicketDismiss = null; + reactContext.addActivityEventListener(this); } @ReactMethod @@ -101,6 +115,7 @@ private String getString(ReadableMap options, String key){ return null; } + private final int INTENT_REQUEST_CODE = 100; @ReactMethod public void setVisitorInfo(ReadableMap options) { @@ -228,19 +243,23 @@ public void appendLog(String log){ } @ReactMethod - public void openTicket(){ + public void openTicket(Callback onClose){ Activity activity = getCurrentActivity(); + onOpenTicketDismiss = onClose; + if(this.logId != null) { // Add log custom field customFields.put(this.logId, new CustomField(Long.parseLong(this.logId), this.log.toString())); } // Open a ticket - RequestActivity.builder() + Intent requestActivityIntent = RequestActivity.builder() .withCustomFields(new ArrayList(customFields.values())) .withTags(this.tags) - .show(activity); + .intent(activity); + + activity.startActivityForResult(requestActivityIntent, INTENT_REQUEST_CODE); } @ReactMethod @@ -278,13 +297,16 @@ public void onError(ErrorResponse errorResponse) { } @ReactMethod - public void showTickets(){ + public void showTickets(Callback onClose){ Activity activity = getCurrentActivity(); + onOpenTicketDismiss = onClose; // Show the user's tickets - RequestListActivity.builder() + Intent requestActivityIntent = RequestListActivity.builder() .withContactUsButtonVisible(false) - .show(activity); + .intent(activity); + + activity.startActivityForResult(requestActivityIntent, INTENT_REQUEST_CODE); } @ReactMethod @@ -336,7 +358,10 @@ public void startChat(ReadableMap options) { @ReactMethod public void dismiss() { - // do nothing see https://pagopa.atlassian.net/browse/IABT-1348?focusedCommentId=31396 + Activity activity = getCurrentActivity(); + if (activity != null) { + activity.finishActivity(INTENT_REQUEST_CODE); + } } @@ -347,4 +372,17 @@ public void setNotificationToken(String token) { pushProvider.registerPushToken(token); } } -} + + @Override + public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) { + if (requestCode == INTENT_REQUEST_CODE && onOpenTicketDismiss != null) { + onOpenTicketDismiss.invoke(); + onOpenTicketDismiss = null; + } + } + + @Override + public void onNewIntent(Intent intent) { + Log.d(TAG, "onNewIntent"); + } +} \ No newline at end of file diff --git a/index.d.ts b/index.d.ts index f2c5766..8ac4966 100644 --- a/index.d.ts +++ b/index.d.ts @@ -37,10 +37,10 @@ declare module 'io-react-native-zendesk' { export function dismiss(): void; // function to open a ticket - export function openTicket(): void; + export function openTicket(onClose: () => void): void; // function to shows all the tickets of the user - export function showTickets(): void; + export function showTickets(onClose: () => void): void; // function that return the number of tickets created by the user export function hasOpenedTickets(): Promise; diff --git a/ios/RNZendeskChat.h b/ios/RNZendeskChat.h index 7d14912..cb55b78 100644 --- a/ios/RNZendeskChat.h +++ b/ios/RNZendeskChat.h @@ -3,5 +3,4 @@ #import @interface RNZendeskChat : NSObject - @end \ No newline at end of file diff --git a/ios/RNZendeskChat.m b/ios/RNZendeskChat.m index be4661c..26754d8 100644 --- a/ios/RNZendeskChat.m +++ b/ios/RNZendeskChat.m @@ -10,6 +10,11 @@ #import #import #import + +@interface NavigationControllerWithCompletion : UINavigationController +@property (nonatomic, copy, nullable) RCTResponseSenderBlock completion; +@end + @implementation RNZendeskChat RCT_EXPORT_MODULE() RCT_EXPORT_METHOD(setVisitorInfo:(NSDictionary *)options) { @@ -65,14 +70,14 @@ - (void)executeOnMainThread:(void (^)(void))block [self startChatFunction:options]; }]; } -RCT_EXPORT_METHOD(openTicket) { +RCT_EXPORT_METHOD(openTicket:(RCTResponseSenderBlock)onClose) { [self executeOnMainThread:^{ - [self openTicketFunction]; + [self openTicketFunction:onClose]; }]; } -RCT_EXPORT_METHOD(showTickets) { +RCT_EXPORT_METHOD(showTickets:(RCTResponseSenderBlock)onClose) { [self executeOnMainThread:^{ - [self showTicketsFunction]; + [self showTicketsFunction:onClose]; }]; } RCT_EXPORT_METHOD(showHelpCenter:(NSDictionary *)options) { @@ -260,7 +265,7 @@ - (void) showHelpCenterFunction:(NSDictionary *)options { UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController: controller]; [topController presentViewController:navControl animated:YES completion:nil]; } -- (void) openTicketFunction { +- (void) openTicketFunction:(RCTResponseSenderBlock)onClose { [self initGlobals]; if(logId != nil){ [self addTicketCustomFieldFunction:logId withValue:mutableLog]; @@ -276,10 +281,12 @@ - (void) openTicketFunction { topController = topController.presentedViewController; } currentController = topController; - UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController: openTicketController]; + NavigationControllerWithCompletion *navControl = [[NavigationControllerWithCompletion alloc] initWithRootViewController: openTicketController]; + navControl.completion = onClose; + [topController presentViewController:navControl animated:YES completion:nil]; } -- (void) showTicketsFunction { +- (void) showTicketsFunction:(RCTResponseSenderBlock)onClose { ZDKRequestListUiConfiguration * config = [ZDKRequestListUiConfiguration new]; config.allowRequestCreation = false; UIViewController *showTicketsController = [ZDKRequestUi buildRequestListWith:@[config]]; @@ -288,7 +295,9 @@ - (void) showTicketsFunction { topController = topController.presentedViewController; } currentController = topController; - UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController: showTicketsController]; + NavigationControllerWithCompletion *navControl = [[NavigationControllerWithCompletion alloc] initWithRootViewController: showTicketsController]; + navControl.completion = onClose; + [topController presentViewController:navControl animated:YES completion:nil]; } - (void) startChatFunction:(NSDictionary *)options { @@ -346,3 +355,15 @@ - (void) registerForNotifications:(NSData *)deviceToken { [ZDKChat registerPushToken:deviceToken]; } @end + +@implementation NavigationControllerWithCompletion + +- (void)viewDidDisappear:(BOOL)animated { + [super viewDidDisappear:animated]; + if (self.completion) { + self.completion(@[[NSNull null]]); + self.completion = nil; + } +} + +@end