Skip to content

Commit

Permalink
[FIX] One of the triggers was not working correctly (#25409)
Browse files Browse the repository at this point in the history
* [FIX] One of the triggers was not working correctly

* fix html iteration

* eslint fix

Co-authored-by: Tiago Evangelista Pinto <tiago.evangelista@rocket.chat>
  • Loading branch information
MartinSchoeler and tiagoevanp committed May 18, 2022
1 parent bbd534a commit 71d57bd
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
1 change: 1 addition & 0 deletions packages/livechat/src/components/App/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export class App extends Component {
} else {
dispatchRestore();
}
Triggers.callbacks.emit('chat-opened-by-visitor');
}

handleOpenWindow = () => {
Expand Down
25 changes: 11 additions & 14 deletions packages/livechat/src/lib/triggers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import mitt from 'mitt';
import { route } from 'preact-router';

import { Livechat } from '../api';
Expand Down Expand Up @@ -59,6 +60,7 @@ class Triggers {
this._triggers = [];
this._enabled = true;
Triggers.instance = this;
this.callbacks = mitt();
}

return Triggers.instance;
Expand Down Expand Up @@ -89,8 +91,8 @@ class Triggers {
}

async fire(trigger) {
const { token, firedTriggers = [] } = store.state;
if (!this._enabled) {
const { token, firedTriggers = [], user } = store.state;
if (!this._enabled || user) {
return;
}
const { actions } = trigger;
Expand Down Expand Up @@ -121,7 +123,10 @@ class Triggers {
parentCall('callback', ['assign-agent', normalizeAgent(agent)]);
}

route('/trigger-messages');
const foundCondition = trigger.conditions.find((c) => c.name === 'chat-opened-by-visitor');
if (!foundCondition) {
route('/trigger-messages');
}
store.setState({ minimized: false });
});
}
Expand All @@ -136,11 +141,6 @@ class Triggers {

processRequest(request) {
this._requests.push(request);
if (!this._started) {
return;
}

this.processTriggers();
}

processTriggers() {
Expand All @@ -163,13 +163,10 @@ class Triggers {
break;
case 'chat-opened-by-visitor':
const openFunc = () => {
const { user } = store.state;
if (user) {
store.off('change', openFunc);
this.fire(trigger);
}
this.fire(trigger);
this.callbacks.off('chat-opened-by-visitor', openFunc);
};
store.on('change', openFunc);
this.callbacks.on('chat-opened-by-visitor', openFunc);
break;
}
});
Expand Down
4 changes: 2 additions & 2 deletions packages/livechat/src/routes/TriggerMessage/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class TriggerMessage extends Component {
componentDidUpdate() {
let height = 0;

this.ref.current.base.children.forEach((el) => {
for (const el of this.ref.current.base.children) {
height += el.scrollHeight;
});
}

parentCall('resizeWidget', height);
}
Expand Down
5 changes: 3 additions & 2 deletions packages/livechat/src/routes/TriggerMessage/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ import TriggerMessage from './component';


export class TriggerMessageContainer extends Component {
handleStart() {
handleStart(props) {
parentCall('setFullScreenDocumentMobile');
parentCall('openWidget');
props.onRestore();
route('/');
}

render = (props) => {
parentCall('resetDocumentStyle');
return <TriggerMessage onStartChat={this.handleStart} {...props} />;
return <TriggerMessage onStartChat={() => this.handleStart(props)} {...props} />;
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/livechat/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
},
"exclude": [
"./node_modules",
"./build"
"./dist"
]
}

0 comments on commit 71d57bd

Please sign in to comment.