diff --git a/android/src/main/java/com/saranshmalik/rnzendeskchat/RNZendeskChat.java b/android/src/main/java/com/saranshmalik/rnzendeskchat/RNZendeskChat.java index ce47f27..e1de74e 100644 --- a/android/src/main/java/com/saranshmalik/rnzendeskchat/RNZendeskChat.java +++ b/android/src/main/java/com/saranshmalik/rnzendeskchat/RNZendeskChat.java @@ -39,6 +39,7 @@ import zendesk.answerbot.AnswerBotEngine; import zendesk.support.SupportEngine; import zendesk.support.request.RequestActivity; +import zendesk.support.requestlist.RequestListActivity; public class RNZendeskChat extends ReactContextBaseJavaModule { @@ -165,18 +166,26 @@ public void setUserIdentity(ReadableMap options) { checkIdentity(); } + @ReactMethod + public void openTicket(){ + Activity activity = getCurrentActivity(); + + // Open a ticket + RequestActivity.builder(). + withCustomFields(customFields).show(activity); + } + + @ReactMethod + public void showTickets(){ + Activity activity = getCurrentActivity(); + + // Show the user's tickets + RequestListActivity.builder().show(activity); + } + @ReactMethod public void showHelpCenter(ReadableMap options) { Activity activity = getCurrentActivity(); - /* - // config must be passed as 2nd parameter to show method - List customFields = new ArrayList<>(); - customFields.add(new CustomField(360028434358L, "testValoreDaApp")); - Configuration config = RequestActivity.builder() - .withCustomFields(customFields) - .withTags("tag1","tag2") - .config(); - */ Boolean withChat = getBoolean(options,"withChat"); Boolean disableTicketCreation = getBoolean(options,"withChat"); if (withChat) { diff --git a/index.d.ts b/index.d.ts index a08d1f1..9ad12a8 100644 --- a/index.d.ts +++ b/index.d.ts @@ -15,6 +15,12 @@ declare module 'io-react-native-zendesk' { // function to display help center UI export function showHelpCenter(chatOptions: ChatOptions): void; + // function to open a ticket + export function openTicket(): void; + + // function to shows all the tickets of the user + export function showTickets(): void; + // function to set visitor info in chat export function setVisitorInfo(visitorInfo: UserInfo): void; diff --git a/ios/RNZendeskChat.m b/ios/RNZendeskChat.m index 4577d38..13befd5 100644 --- a/ios/RNZendeskChat.m +++ b/ios/RNZendeskChat.m @@ -59,6 +59,17 @@ @implementation RNZendeskChat }); } +RCT_EXPORT_METHOD(openTicket) { + dispatch_sync(dispatch_get_main_queue(), ^{ + [self openTicketFunction]; + }); +} +RCT_EXPORT_METHOD(showTickets) { + dispatch_sync(dispatch_get_main_queue(), ^{ + [self showTicketsFunction]; + }); +} + RCT_EXPORT_METHOD(showHelpCenter:(NSDictionary *)options) { [self setVisitorInfo:options]; dispatch_sync(dispatch_get_main_queue(), ^{ @@ -142,6 +153,26 @@ - (void) showHelpCenterFunction:(NSDictionary *)options { [topController presentViewController:navControl animated:YES completion:nil]; } +- (void) openTicketFunction { + UIViewController *openTicketController = [ZDKRequestUi buildRequestUiWith:@[]]; + UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController; + while (topController.presentedViewController) { + topController = topController.presentedViewController; + } + UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController: openTicketController]; + [topController presentViewController:navControl animated:YES completion:nil]; + } + +- (void) showTicketsFunction { + UIViewController *showTicketsController = [ZDKRequestUi buildRequestListWith:@[]]; + UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController; + while (topController.presentedViewController) { + topController = topController.presentedViewController; + } + UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController: showTicketsController]; + [topController presentViewController:navControl animated:YES completion:nil]; + } + - (void) startChatFunction:(NSDictionary *)options { ZDKMessagingConfiguration *messagingConfiguration = [[ZDKMessagingConfiguration alloc] init]; NSString *botName = @"ChatBot"; diff --git a/package.json b/package.json index c31c698..6428ee4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "io-react-native-zendesk", - "version": "0.3.6", + "version": "0.3.7", "description": "React native wrapper for Zendesk Unified SDK", "main": "index.js", "scripts": {