Skip to content

Commit 1ad25f9

Browse files
magento-commerce/magento2-login-as-customer#156: Banner disappear when admin edit customer data from Account Information tab.
1 parent a86d2d6 commit 1ad25f9

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

app/code/Magento/LoginAsCustomerFrontendUi/view/frontend/web/js/view/loginAsCustomer.js

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ define([
88
'uiComponent',
99
'Magento_Customer/js/customer-data',
1010
'mage/translate'
11-
], function ($, Component, customerData) {
11+
], function ($, Component, customer) {
1212
'use strict';
1313

1414
return Component.extend({
@@ -19,23 +19,48 @@ define([
1919

2020
/** @inheritdoc */
2121
initialize: function () {
22+
var customerData, loggedAsCustomerData;
23+
2224
this._super();
2325

24-
this.customer = customerData.get('customer');
25-
this.loginAsCustomer = customerData.get('loggedAsCustomer');
26-
this.isVisible(this.loginAsCustomer().adminUserId);
26+
customerData = customer.get('customer');
27+
loggedAsCustomerData = customer.get('loggedAsCustomer');
28+
29+
customerData.subscribe(function (data) {
30+
this.fullname = data.fullname;
31+
this._updateBanner();
32+
}.bind(this));
33+
loggedAsCustomerData.subscribe(function (data) {
34+
this.adminUserId = data.adminUserId;
35+
this.websiteName = data.websiteName;
36+
this._updateBanner();
37+
}.bind(this));
38+
39+
this.fullname = customerData().fullname;
40+
this.adminUserId = loggedAsCustomerData().adminUserId;
41+
this.websiteName = loggedAsCustomerData().websiteName;
2742

28-
this.notificationText = $.mage.__('You are connected as <strong>%1</strong> on %2')
29-
.replace('%1', this.customer().fullname)
30-
.replace('%2', this.loginAsCustomer().websiteName);
43+
this._updateBanner();
3144
},
3245

3346
/** @inheritdoc */
3447
initObservable: function () {
3548
this._super()
36-
.observe('isVisible');
49+
.observe(['isVisible', 'notificationText']);
3750

3851
return this;
52+
},
53+
54+
_updateBanner: function () {
55+
if (this.adminUserId !== undefined) {
56+
this.isVisible(this.adminUserId);
57+
}
58+
59+
if (this.fullname !== undefined && this.websiteName !== undefined) {
60+
this.notificationText($.mage.__('You are connected as <strong>%1</strong> on %2')
61+
.replace('%1', this.fullname)
62+
.replace('%2', this.websiteName));
63+
}
3964
}
4065
});
4166
});

0 commit comments

Comments
 (0)