diff --git a/packages/assistify-help-request/client/views/tabbar/HelpRequestActions.js b/packages/assistify-help-request/client/views/tabbar/HelpRequestActions.js index bf57b0732385..aa4710bc5504 100755 --- a/packages/assistify-help-request/client/views/tabbar/HelpRequestActions.js +++ b/packages/assistify-help-request/client/views/tabbar/HelpRequestActions.js @@ -36,7 +36,7 @@ Template.HelpRequestActions.dialogs = { */ display() { const self = this; - return new Promise(function (resolve, reject) { + return new Promise(function(resolve, reject) { swal.withForm(_.extend({ title: t('Closing_chat'), text: '', @@ -64,7 +64,7 @@ Template.HelpRequestActions.dialogs = { }], showCancelButton: true, closeOnConfirm: false - }, self.properties), function (isConfirm) { + }, self.properties), function(isConfirm) { if (!isConfirm) { //on cancel $('.swal-form').remove(); //possible bug? why I have to do this manually reject(); @@ -96,16 +96,16 @@ Template.HelpRequestActions.events({ roomId: instance.data.roomId }), (inputValue) => { /*if (!inputValue) { - swal.showInputError(t('Please_add_a_comment_to_close_the_room')); - return false; - } + swal.showInputError(t('Please_add_a_comment_to_close_the_room')); + return false; + } - if (s.trim(inputValue) === '') { - swal.showInputError(t('Please_add_a_comment_to_close_the_room')); - return false; - }*/ + if (s.trim(inputValue) === '') { + swal.showInputError(t('Please_add_a_comment_to_close_the_room')); + return false; + }*/ - Meteor.call('assistify:closeHelpRequest', this.roomId, {comment: inputValue}, function (error) { + Meteor.call('assistify:closeHelpRequest', this.roomId, {comment: inputValue}, function(error) { if (error) { return handleError(error); } else { @@ -134,17 +134,8 @@ Template.HelpRequestActions.events({ showCancelButton: true, closeOnConfirm: false }, (inputValue) => { - if (!inputValue) { - swal.showInputError(t('Please_add_a_comment_to_close_the_room')); - return false; - } - if (s.trim(inputValue) === '') { - swal.showInputError(t('Please_add_a_comment_to_close_the_room')); - return false; - } - - Meteor.call('livechat:closeRoom', this.rid, inputValue, function (error/*, result*/) { + Meteor.call('livechat:closeRoom', this.roomId, inputValue, function(error/*, result*/) { if (error) { return handleError(error); } @@ -160,26 +151,19 @@ Template.HelpRequestActions.events({ } }); -Template.HelpRequestActions.onCreated(function () { +Template.HelpRequestActions.onCreated(function() { const instance = this; this.helpRequest = new ReactiveVar(null); - - Meteor.subscribe('assistify:helpRequests', instance.data.roomId); //not reactively needed, as roomId doesn't change - + this.room = new ReactiveVar(null); this.autorun(() => { - if (Template.currentData().roomId) { + if (instance.data && instance.data.roomId) { + Meteor.subscribe('assistify:helpRequests', instance.data.roomId); //not reactively needed, as roomId doesn't change + const helpRequest = RocketChat.models.HelpRequests.findOneByRoomId(instance.data.roomId); instance.helpRequest.set(helpRequest); - // if (!instance.helpRequest.get()) { //todo remove after PoC: Non-reactive method call - // Meteor.call('assistify:helpRequestByRoomId', Template.currentData().roomId, (err, result) => { - // if (!err) { - // instance.helpRequest.set(result); - // } else { - // console.log(err); - // } - // }); - // } + const room = ChatSubscription.findOne({rid: instance.data.roomId}); + instance.room.set(room); } }); }); diff --git a/packages/dbs-ai/client/views/app/tabbar/smarti.html b/packages/dbs-ai/client/views/app/tabbar/smarti.html index eb8d04502baf..3e31ffc55e5f 100644 --- a/packages/dbs-ai/client/views/app/tabbar/smarti.html +++ b/packages/dbs-ai/client/views/app/tabbar/smarti.html @@ -11,7 +11,7 @@

HelpRequestActions }} + {{> HelpRequestActions liveChatActions}} {{/if}}
Smarti
diff --git a/packages/dbs-ai/client/views/app/tabbar/smarti.js b/packages/dbs-ai/client/views/app/tabbar/smarti.js index c94127865fd4..2de3f7c0553b 100644 --- a/packages/dbs-ai/client/views/app/tabbar/smarti.js +++ b/packages/dbs-ai/client/views/app/tabbar/smarti.js @@ -1,20 +1,13 @@ Template.dbsAI_smarti.onCreated(function() { this.helpRequest = new ReactiveVar(null); - const instance = this; + Meteor.subscribe('assistify:helpRequests', instance.data.rid); //not reactively needed, as roomId doesn't change + this.autorun(() => { if (instance.data.rid) { - - if (!instance.helpRequest.get()) { //todo remove after PoC: Non-reactive method call - Meteor.call('assistify:helpRequestByRoomId', instance.data.rid, (err, result) => { - if (!err) { - instance.helpRequest.set(result); - } else { - console.log(err); - } - }); - } + const helpRequest = RocketChat.models.HelpRequests.findOneByRoomId(instance.data.rid); + instance.helpRequest.set(helpRequest); } }); @@ -64,6 +57,13 @@ Template.dbsAI_smarti.helpers({ const instance = Template.instance(); return ChatSubscription.findOne({rid: instance.data.rid}).t === 'l'; }, + /** + This helper is needed in order to create an object which matches the actions bar importing parameters + */ + liveChatActions() { + const instance = Template.instance(); + return { roomId: instance.data.rid }; + }, helpRequestByRoom() { const instance = Template.instance(); return instance.helpRequest.get();