@@ -128,6 +128,7 @@ export interface WebchatUIProps {
128
128
fileUploadError : boolean ;
129
129
onSetFileUploadError : ( hasError : boolean ) => void ;
130
130
131
+ onShowChatScreen : ( ) => void ;
131
132
showPrevConversations : boolean ;
132
133
onSetShowPrevConversations : ( show : boolean ) => void ;
133
134
prevConversations : PrevConversationsState ;
@@ -740,31 +741,63 @@ export class WebchatUI extends React.PureComponent<
740
741
options,
741
742
} ) ;
742
743
} else {
744
+ this . props . onSwitchSession ( ) ;
743
745
this . props . onSendMessage ( text , data , options ) ;
744
746
}
745
747
} ;
746
748
747
- handleStartConversation = ( ) => {
748
- if ( ! this . props . config . settings . privacyNotice . enabled || this . props . hasAcceptedTerms ) {
749
- const { initialSessionId } = this . props . config ;
750
- if ( ! initialSessionId ) {
751
- this . props . onSwitchSession ( ) ;
752
- }
753
- if ( initialSessionId && initialSessionId !== this . props . currentSession ) {
754
- this . props . onSwitchSession ( initialSessionId ) ;
755
- }
749
+ handleSendActionButtonMessageFromTeaser = (
750
+ text ?: string ,
751
+ data ?: any ,
752
+ options ?: Partial < ISendMessageOptions > ,
753
+ ) => {
754
+ this . props . onSetShowHomeScreen ( false ) ;
755
+ this . props . onSetShowChatOptionsScreen ( false ) ;
756
+
757
+ if ( this . props . config . settings . privacyNotice . enabled && ! this . props . hasAcceptedTerms ) {
758
+ this . props . onSetStoredMessage ( {
759
+ text,
760
+ data,
761
+ options,
762
+ } ) ;
763
+ } else {
764
+ this . props . onShowChatScreen ( ) ;
765
+ this . props . onSendMessage ( text , data , options ) ;
756
766
}
767
+ } ;
757
768
758
- if ( ! this . props . open ) this . props . onToggle ( ) ;
769
+ handleStartConversation = ( ) => {
759
770
this . props . onSetShowHomeScreen ( false ) ;
760
771
this . props . onSetShowChatOptionsScreen ( false ) ;
772
+
773
+ const showPrivacyScreen = this . props . config . settings . privacyNotice . enabled && ! this . props . hasAcceptedTerms ;
774
+ if ( ! showPrivacyScreen ) {
775
+ this . props . onShowChatScreen ( ) ;
776
+ }
761
777
} ;
762
778
779
+ handleFabClick = ( ) => {
780
+ this . props . onToggle ( ) ;
781
+
782
+ const homeScreenEnabled = this . props . config . settings . homeScreen . enabled === true ;
783
+ if ( homeScreenEnabled ) {
784
+ this . setState ( { lastUnseenMessageText : "" } ) ;
785
+ } else {
786
+ this . handleStartConversation ( ) ;
787
+ }
788
+ }
789
+
763
790
openConversationFromTeaser = ( ) => {
764
- // in this case we always open to current session
765
791
this . props . onToggle ( ) ;
766
792
this . props . onSetShowHomeScreen ( false ) ;
767
793
this . props . onSetShowChatOptionsScreen ( false ) ;
794
+
795
+ const showPrivacyScreen = this . props . config . settings . privacyNotice . enabled && ! this . props . hasAcceptedTerms ;
796
+ if ( showPrivacyScreen ) {
797
+ this . setState ( { lastUnseenMessageText : "" } ) ;
798
+ } else {
799
+ this . props . onShowChatScreen ( ) ;
800
+ }
768
801
} ;
769
802
770
803
render ( ) {
@@ -800,6 +833,7 @@ export class WebchatUI extends React.PureComponent<
800
833
onSetHasGivenRating,
801
834
onSetShowPrevConversations,
802
835
onSetShowChatOptionsScreen,
836
+ onShowChatScreen,
803
837
onSwitchSession,
804
838
requestRatingScreenTitle,
805
839
customRatingTitle,
@@ -946,7 +980,7 @@ export class WebchatUI extends React.PureComponent<
946
980
config = { config }
947
981
onEmitAnalytics = { onEmitAnalytics }
948
982
onSendActionButtonMessage = {
949
- this . handleSendActionButtonMessage
983
+ this . handleSendActionButtonMessageFromTeaser
950
984
}
951
985
onHideTeaserMessage = { onHideTeaserMessage }
952
986
wasOpen = { wasOpen }
@@ -974,7 +1008,7 @@ export class WebchatUI extends React.PureComponent<
974
1008
) : (
975
1009
< FAB
976
1010
data-cognigy-webchat-toggle
977
- onClick = { onToggle }
1011
+ onClick = { this . handleFabClick }
978
1012
{ ...webchatToggleProps }
979
1013
type = "button"
980
1014
className = "webchat-toggle-button"
@@ -1025,6 +1059,7 @@ export class WebchatUI extends React.PureComponent<
1025
1059
requestRatingEventBannerText,
1026
1060
showRatingScreen,
1027
1061
onShowRatingScreen,
1062
+ onShowChatScreen,
1028
1063
onSwitchSession,
1029
1064
onClose,
1030
1065
onEmitAnalytics,
@@ -1072,14 +1107,12 @@ export class WebchatUI extends React.PureComponent<
1072
1107
} ;
1073
1108
1074
1109
const handleCloseAndReset = ( ) => {
1075
- onSwitchSession ( ) ;
1076
1110
onSetShowHomeScreen ( true ) ;
1077
1111
onClose ( ) ;
1078
1112
// Restore focus to chat toggle button
1079
1113
this . chatToggleButtonRef ?. current ?. focus ?.( ) ;
1080
1114
}
1081
1115
1082
- // TODO implement proper navigation solution
1083
1116
const handleOnGoBack = ( ) => {
1084
1117
if ( ! showChatOptionsScreen && ! showRatingScreen ) {
1085
1118
onSetShowPrevConversations ( false ) ;
@@ -1100,13 +1133,13 @@ export class WebchatUI extends React.PureComponent<
1100
1133
1101
1134
const handleAcceptTerms = ( ) => {
1102
1135
onAcceptTerms ( this . props ?. options ?. userId || "" ) ;
1136
+ onShowChatScreen ( ) ;
1103
1137
1104
1138
const data = {
1105
1139
_cognigy : {
1106
1140
controlCommands : [ { type : "acceptPrivacyPolicy" } ] ,
1107
1141
} ,
1108
1142
} ;
1109
-
1110
1143
this . props . onSendMessage ( "" , data ) ;
1111
1144
} ;
1112
1145
@@ -1141,6 +1174,7 @@ export class WebchatUI extends React.PureComponent<
1141
1174
onSetShowPrevConversations = { onSetShowPrevConversations }
1142
1175
onSwitchSession = { onSwitchSession }
1143
1176
config = { config }
1177
+ currentSession = { currentSession }
1144
1178
/>
1145
1179
) ;
1146
1180
0 commit comments