@salla.sa/twilight-components 2.12.9 → 2.12.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -90,12 +90,18 @@ export class SallaUserMenu {
90
90
  * //todo:: cover two requests in customer pages
91
91
  * //todo:: make sure to run this only after token is set
92
92
  */
93
- if (salla.url.is_page('customer.notifications')
93
+ const shouldFetchProfile = !this.inline && (salla.url.is_page('customer.notifications')
94
94
  || salla.url.is_page('customer.orders.index.pending')
95
95
  || salla.url.is_page('customer.profile')
96
- || ((Date.now() - (salla.storage.get('user.fetched_at') || 0)) / 1000 / 60) > 30) {
96
+ || ((Date.now() - (salla.storage.get('user.fetched_at') || 0)) / 1000 / 60) > 30);
97
+ if (shouldFetchProfile) {
97
98
  this.fetchFreshProfile();
98
99
  }
100
+ else {
101
+ salla.event.on('profile::info.fetched', res => {
102
+ this.updateProfileState(res);
103
+ });
104
+ }
99
105
  });
100
106
  }
101
107
  fetchFreshProfile() {
@@ -106,14 +112,19 @@ export class SallaUserMenu {
106
112
  }
107
113
  salla.profile.api.info()
108
114
  .then((res) => {
109
- this.badges.pending_orders = salla.helpers.number(res.data.pending_orders || 0);
110
- this.badges.notifications = salla.helpers.number(res.data.notifications || 0);
111
- this.hasBadges = Number(res.data.pending_orders) > 0 || Number(res.data.notifications) > 0;
112
- this.first_name = res.data.first_name;
113
- this.last_name = res.data.last_name;
114
- this.avatar = res.data.avatar || salla.url.cdn('images/avatar.png');
115
+ this.updateProfileState(res);
115
116
  });
116
117
  }
118
+ updateProfileState(res) {
119
+ this.badges = {
120
+ notifications: salla.helpers.number(res.data.notifications || 0),
121
+ pending_orders: salla.helpers.number(res.data.pending_orders || 0)
122
+ };
123
+ this.hasBadges = Number(res.data.pending_orders) > 0 || Number(res.data.notifications) > 0;
124
+ this.first_name = res.data.first_name;
125
+ this.last_name = res.data.last_name;
126
+ this.avatar = res.data.avatar || salla.url.cdn('images/avatar.png');
127
+ }
117
128
  async open(e) {
118
129
  this.opened = !this.opened;
119
130
  e.stopPropagation();
@@ -1 +1 @@
1
- {"version":3,"file":"salla-user-menu.js","sourceRoot":"","sources":["../../../src/components/salla-user-menu/salla-user-menu.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAC,MAAM,eAAe,CAAC;AACvE,QAAQ;AACR,OAAO,SAAS,MAAM,0CAA0C,CAAA;AAChE,OAAO,QAAQ,MAAM,gCAAgC,CAAA;AACrD,OAAO,SAAS,MAAM,kCAAkC,CAAA;AACxD,OAAO,iBAAiB,MAAM,2BAA2B,CAAA;AACzD,OAAO,YAAY,MAAM,2BAA2B,CAAA;AACpD,OAAO,WAAW,MAAM,kCAAkC,CAAA;AAC1D,OAAO,UAAU,MAAM,+BAA+B,CAAA;AACtD,OAAO,MAAM,MAAM,6BAA6B,CAAA;AAChD,OAAO,IAAI,MAAM,4BAA4B,CAAC;AAC9C,OAAO,UAAU,MAAM,kCAAkC,CAAC;AAE1D;;;GAGG;AAKH,MAAM,OAAO,aAAa;EACxB;;IAmDQ,UAAK,GAAQ;MACnB,aAAa,EAAE,QAAQ;MACvB,MAAM,EAAE,SAAS;MACjB,cAAc,EAAE,iBAAiB;MACjC,QAAQ,EAAE,YAAY;MACtB,OAAO,EAAE,WAAW;KACrB,CAAC;IA4CM,mBAAc,GAAG,GAAG,EAAE;MAC5B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC,CAAA;0BA1CkC,KAAK;kBACb,KAAK;yBACC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,6BAA6B,CAAC;kBACpD,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,sBAAsB,CAAC;0BAC9B,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,8BAA8B,CAAC;oBACpD,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,wBAAwB,CAAC;mBACzC,KAAK,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EACJ,CAAC;EAED,gBAAgB;;IACd,2DAA2D;IAC3D,MAAA,QAAQ,CAAC,gBAAgB,0CAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;EACzE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import {Component, Host, h, State, Element, Prop} from '@stencil/core';\n// Icons\nimport ArrowDown from \"../../assets/svg/keyboard_arrow_down.svg\"\nimport BellRing from \"../../assets/svg/bell-ring.svg\"\nimport OrderIcon from \"../../assets/svg/box-bankers.svg\"\nimport PendingOrdersIcon from \"../../assets/svg/cart.svg\"\nimport WishListIcon from \"../../assets/svg/star.svg\"\nimport ProfileIcon from \"../../assets/svg/user-circle.svg\"\nimport LogoutIcon from \"../../assets/svg/send-out.svg\"\nimport Cancel from \"../../assets/svg/cancel.svg\"\nimport Rate from \"../../assets/svg/star2.svg\";\nimport UserCircle from \"../../assets/svg/user-circle.svg\";\n\n/**\n * @slot trigger - Replaces trigger widget, has replaceable props `{avatar}`, `{hello}`, `{first_name}`, `{last_name}`, `{icon}`.\n * @slot login-btn - Replaces the login button, it must be used with `salla.event.dispatch('login::open')` to open the login modal.\n */\n@Component({\n tag: 'salla-user-menu',\n styleUrl: 'salla-user-menu.scss',\n})\nexport class SallaUserMenu {\n constructor() {\n\n // salla.auth.event.onLoggedIn(() => {\n // this.is_loggedIn = true\n // })\n\n salla.lang.onLoaded(() => {\n this.notifications = salla.lang.get(\"common.titles.notifications\");\n this.orders = salla.lang.get(\"common.titles.orders\");\n this.pending_orders = salla.lang.get(\"common.titles.pending_orders\");\n this.wishlist = salla.lang.get(\"common.titles.wishlist\");\n this.profile = salla.lang.get(\"common.titles.profile\");\n this.hello = salla.lang.get(\"pages.checkout.hello\");\n this.rating = salla.lang.get(\"common.titles.rating\");\n this.logout = salla.lang.get(\"blocks.header.logout\");\n });\n\n //we need it only in theme-y\n if (this.host.hasAttribute('with-rating')) {\n this.items.rating = Rate;\n }\n //we need it to be the last item\n this.items.logout = LogoutIcon;\n\n this.triggerSlot = this.host.querySelector('[slot=\"trigger\"]')?.innerHTML || '<div class=\"s-user-menu-trigger\"><div class=\"s-user-menu-avatar-wrap\"><img class=\"s-user-menu-trigger-avatar\" src=\"{avatar}\" alt=\"{first_name}{last_name}\" /></div><div class=\"s-user-menu-trigger-content\"><span class=\"s-user-menu-trigger-hello\">{hello}</span><p class=\"s-user-menu-trigger-name\">{first_name} {last_name}</p></div> <i class=\"s-user-menu-trigger-icon\">{icon}</i></div>';\n salla.onReady(() => {\n if (salla.config.isGuest()) {\n return;\n }\n\n this.is_loggedIn = true;\n /**\n * Get Fresh Notifications In These Cases:\n * - is notification page, if user already changed the status of his orders (to reset notification badge)\n * - is pending orders page, if user already changed the status of his orders (to reset orders badge)\n * - is profile page, in case user changed his name or avatar, we need to update it\n * - half hour is passed from the last user data fetched\n *\n * //todo:: update the data in the storage in customer pages\n * //todo:: cover two requests in customer pages\n * //todo:: make sure to run this only after token is set\n */\n if (salla.url.is_page('customer.notifications')\n || salla.url.is_page('customer.orders.index.pending')\n || salla.url.is_page('customer.profile')\n || ((Date.now() - (salla.storage.get('user.fetched_at') || 0)) / 1000 / 60) > 30) {\n this.fetchFreshProfile();\n }\n });\n }\n\n private items: any = {\n notifications: BellRing,\n orders: OrderIcon,\n pending_orders: PendingOrdersIcon,\n wishlist: WishListIcon,\n profile: ProfileIcon,\n };\n\n @Element() host: HTMLElement;\n private readonly triggerSlot: string;\n @State() accountLoading: boolean = false;\n @State() opened: boolean = false;\n @State() notifications: string = salla.lang.get(\"common.titles.notifications\");\n @State() orders: string = salla.lang.get(\"common.titles.orders\");\n @State() pending_orders: string = salla.lang.get(\"common.titles.pending_orders\");\n @State() wishlist: string = salla.lang.get(\"common.titles.wishlist\");\n @State() profile: string = salla.lang.get(\"common.titles.profile\");\n @State() rating: string = salla.lang.get(\"common.titles.rating\");\n @State() logout: string = salla.lang.get(\"blocks.header.logout\");\n @State() hello: string = salla.lang.get(\"pages.checkout.hello\");\n @State() first_name: string = salla.storage.get('user.first_name') || '';\n @State() last_name: string = salla.storage.get('user.last_name') || '';\n @State() avatar: string = salla.storage.get('user.avatar') || salla.url.cdn('images/avatar.png');\n @State() is_loggedIn: boolean;\n @State() badges: any = {\n notifications: salla.helpers.number(salla.storage.get('user.notifications') || 0),\n pending_orders: salla.helpers.number(salla.storage.get('user.pending_orders') || 0)\n };\n\n @State() hasBadges: boolean = Number(salla.storage.get('user.pending_orders')) > 0 || Number(salla.storage.get('user.notifications')) > 0;\n /**\n * To display only the list without the dropdown functionality\n */\n @Prop({reflect: true}) inline: boolean = false;\n\n /**\n * To display the trigger as an avatar only\n */\n @Prop({reflect: true}) avatarOnly: boolean = false;\n\n /**\n * To display the dropdown header in mobile sheet\n */\n @Prop({reflect: true}) showHeader: boolean = false;\n\n /**\n * To Make the dropdown menu relative to parent element or not\n */\n @Prop({reflect: true}) relativeDropdown: boolean = false;\n\n private onClickOutside = () => {\n this.opened = false;\n }\n\n @State() OrderUpdate: number = 0;\n\n private fetchFreshProfile() {\n //don't request fetchFreshProfile unless token is injected into the api\n if (!salla.api.token) {\n salla.log('trying to fetchFreshProfile before injected the token!!');\n return;\n }\n salla.profile.api.info()\n .then((res) => {\n this.badges.pending_orders = salla.helpers.number(res.data.pending_orders || 0);\n this.badges.notifications = salla.helpers.number(res.data.notifications || 0);\n this.hasBadges = Number(res.data.pending_orders) > 0 || Number(res.data.notifications) > 0;\n this.first_name = res.data.first_name;\n this.last_name = res.data.last_name;\n this.avatar = res.data.avatar || salla.url.cdn('images/avatar.png');\n });\n }\n\n async open(e) {\n this.opened = !this.opened;\n e.stopPropagation()\n if (this.opened) {\n window.addEventListener('click', this.onClickOutside);\n }\n }\n\n private menuItemClicked(event: Event, item: string[]) {\n if (item[0] !== 'logout') {\n return;\n }\n event.preventDefault();\n salla.auth.logout('sall-user-menu');\n }\n\n private getTheHeader() {\n return <div class={{\n 's-user-menu-trigger-slot': true,\n 's-user-menu-red-dot': this.hasBadges,\n 's-user-menu-trigger-avatar-only': this.avatarOnly\n }}\n id='trigger-slot' onClick={(e) => this.open(e)} innerHTML={this.triggerSlot\n .replace(/\\{hello\\}/g, this.hello)\n .replace(/\\{first_name\\}/g, this.first_name)\n .replace(/\\{last_name\\}/g, this.last_name)\n .replace(/\\{avatar\\}/g, this.avatar)\n .replace(/\\{icon\\}/g, ArrowDown)}>\n </div>;\n }\n\n private getMenuItem(item: any[], i: number) {\n //todo:: enhancement support slot here\n return <li class={{\n 's-user-menu-dropdown-item': true,\n 's-user-menu-dropdown-item-logout': i + 1 == Object.entries(this.items).length\n }}>\n <a href={salla.url.get(item[0])} onClick={event => this.menuItemClicked(event, item)}>\n <i innerHTML={item[1]}> </i>\n <span class=\"s-user-menu-dropdown-item-title\">{this[item[0]]}</span>\n {!['٠', '0', undefined].includes(this.badges[item[0]])\n ? <span class=\"s-user-menu-dropdown-item-badge\">{this.badges[item[0]]}</span>\n : \"\"}\n </a>\n </li>;\n }\n\n componentShouldUpdate() {\n if (!this.opened) {\n window.removeEventListener('click', this.onClickOutside);\n }\n }\n\n render() {\n if (!this.is_loggedIn) {\n return <Host>\n <slot name='login-btn'>\n <button class=\"s-user-menu-login-btn\" onClick={() => salla.event.dispatch('login::open')}\n innerHTML={UserCircle}>\n </button>\n </slot>\n </Host>\n }\n\n if (this.inline) {\n return <Host>\n <ul class=\"s-user-menu-inline\">\n {Object.entries(this.items).map((item, i) => this.getMenuItem(item, i))}\n </ul>\n </Host>\n }\n\n return (\n <Host>\n <div class={{'s-user-menu-wrapper': true, 's-user-menu-relative-dropdown': this.relativeDropdown}}>\n {this.getTheHeader()}\n <div class={{'s-user-menu-toggler': true, 'opened': this.opened}}>\n <div class=\"s-user-menu-dropdown\" onClick={(e) => e.stopPropagation()}>\n {this.showHeader ? <div class=\"s-user-menu-dropdown-header\">\n <img src={this.avatar} alt={`${this.first_name} ${this.last_name}`}/>\n <div class=\"s-user-menu-dropdown-header-content\">\n <span>{this.hello}</span>\n <p>{this.first_name} {this.last_name}</p>\n </div>\n <button class=\"s-user-menu-dropdown-header-close\" innerHTML={Cancel}\n onClick={() => this.opened = false}>\n </button>\n </div> : ''}\n <ul class=\"s-user-menu-dropdown-list\">\n {Object.entries(this.items).map((item, i) => this.getMenuItem(item, i))}\n </ul>\n </div>\n </div>\n </div>\n </Host>\n );\n }\n\n componentDidLoad() {\n //make sure to load the avatar if it's lazy, we use it in Y\n document.lazyLoadInstance?.update(this.host.querySelectorAll('.lazy'));\n }\n}\n"]}
1
+ {"version":3,"file":"salla-user-menu.js","sourceRoot":"","sources":["../../../src/components/salla-user-menu/salla-user-menu.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAC,MAAM,eAAe,CAAC;AACvE,QAAQ;AACR,OAAO,SAAS,MAAM,0CAA0C,CAAA;AAChE,OAAO,QAAQ,MAAM,gCAAgC,CAAA;AACrD,OAAO,SAAS,MAAM,kCAAkC,CAAA;AACxD,OAAO,iBAAiB,MAAM,2BAA2B,CAAA;AACzD,OAAO,YAAY,MAAM,2BAA2B,CAAA;AACpD,OAAO,WAAW,MAAM,kCAAkC,CAAA;AAC1D,OAAO,UAAU,MAAM,+BAA+B,CAAA;AACtD,OAAO,MAAM,MAAM,6BAA6B,CAAA;AAChD,OAAO,IAAI,MAAM,4BAA4B,CAAC;AAC9C,OAAO,UAAU,MAAM,kCAAkC,CAAC;AAE1D;;;GAGG;AAKH,MAAM,OAAO,aAAa;EACxB;;IA4DQ,UAAK,GAAQ;MACnB,aAAa,EAAE,QAAQ;MACvB,MAAM,EAAE,SAAS;MACjB,cAAc,EAAE,iBAAiB;MACjC,QAAQ,EAAE,YAAY;MACtB,OAAO,EAAE,WAAW;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AC,CAAC,WAAK,KAAK,EAAC,6BAA6B;cACzD,WAAK,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,SAAS,EAAE,GAAG;cACrE,WAAK,KAAK,EAAC,qCAAqC;gBAC9C,gBAAO,IAAI,CAAC,KAAK,CAAQ;gBACzB;kBAAI,IAAI,CAAC,UAAU;;kBAAG,IAAI,CAAC,SAAS,CAAK,CACrC;cACN,cAAQ,KAAK,EAAC,mCAAmC,EAAC,SAAS,EAAE,MAAM,EAC3D,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,KAAK,GACjC,CACL,CAAC,CAAC,CAAC,EAAE;YACX,UAAI,KAAK,EAAC,2BAA2B,IAClC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CACpE,CACD,CACF,CACF,CACD,CACR,CAAC;EACJ,CAAC;EAED,gBAAgB;;IACd,2DAA2D;IAC3D,MAAA,QAAQ,CAAC,gBAAgB,0CAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;EACzE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import {Component, Host, h, State, Element, Prop} from '@stencil/core';\n// Icons\nimport ArrowDown from \"../../assets/svg/keyboard_arrow_down.svg\"\nimport BellRing from \"../../assets/svg/bell-ring.svg\"\nimport OrderIcon from \"../../assets/svg/box-bankers.svg\"\nimport PendingOrdersIcon from \"../../assets/svg/cart.svg\"\nimport WishListIcon from \"../../assets/svg/star.svg\"\nimport ProfileIcon from \"../../assets/svg/user-circle.svg\"\nimport LogoutIcon from \"../../assets/svg/send-out.svg\"\nimport Cancel from \"../../assets/svg/cancel.svg\"\nimport Rate from \"../../assets/svg/star2.svg\";\nimport UserCircle from \"../../assets/svg/user-circle.svg\";\n\n/**\n * @slot trigger - Replaces trigger widget, has replaceable props `{avatar}`, `{hello}`, `{first_name}`, `{last_name}`, `{icon}`.\n * @slot login-btn - Replaces the login button, it must be used with `salla.event.dispatch('login::open')` to open the login modal.\n */\n@Component({\n tag: 'salla-user-menu',\n styleUrl: 'salla-user-menu.scss',\n})\nexport class SallaUserMenu {\n constructor() {\n\n // salla.auth.event.onLoggedIn(() => {\n // this.is_loggedIn = true\n // })\n\n salla.lang.onLoaded(() => {\n this.notifications = salla.lang.get(\"common.titles.notifications\");\n this.orders = salla.lang.get(\"common.titles.orders\");\n this.pending_orders = salla.lang.get(\"common.titles.pending_orders\");\n this.wishlist = salla.lang.get(\"common.titles.wishlist\");\n this.profile = salla.lang.get(\"common.titles.profile\");\n this.hello = salla.lang.get(\"pages.checkout.hello\");\n this.rating = salla.lang.get(\"common.titles.rating\");\n this.logout = salla.lang.get(\"blocks.header.logout\");\n });\n\n //we need it only in theme-y\n if (this.host.hasAttribute('with-rating')) {\n this.items.rating = Rate;\n }\n //we need it to be the last item\n this.items.logout = LogoutIcon;\n\n this.triggerSlot = this.host.querySelector('[slot=\"trigger\"]')?.innerHTML || '<div class=\"s-user-menu-trigger\"><div class=\"s-user-menu-avatar-wrap\"><img class=\"s-user-menu-trigger-avatar\" src=\"{avatar}\" alt=\"{first_name}{last_name}\" /></div><div class=\"s-user-menu-trigger-content\"><span class=\"s-user-menu-trigger-hello\">{hello}</span><p class=\"s-user-menu-trigger-name\">{first_name} {last_name}</p></div> <i class=\"s-user-menu-trigger-icon\">{icon}</i></div>';\n salla.onReady(() => {\n if (salla.config.isGuest()) {\n return;\n }\n\n this.is_loggedIn = true;\n /**\n * Get Fresh Notifications In These Cases:\n * - is notification page, if user already changed the status of his orders (to reset notification badge)\n * - is pending orders page, if user already changed the status of his orders (to reset orders badge)\n * - is profile page, in case user changed his name or avatar, we need to update it\n * - half hour is passed from the last user data fetched\n *\n * //todo:: update the data in the storage in customer pages\n * //todo:: cover two requests in customer pages\n * //todo:: make sure to run this only after token is set\n */\n const shouldFetchProfile = !this.inline && (\n salla.url.is_page('customer.notifications')\n || salla.url.is_page('customer.orders.index.pending')\n || salla.url.is_page('customer.profile')\n || ((Date.now() - (salla.storage.get('user.fetched_at') || 0)) / 1000 / 60) > 30\n );\n\n if(shouldFetchProfile){\n this.fetchFreshProfile()\n }else{\n salla.event.on('profile::info.fetched', res => {\n this.updateProfileState(res)\n });\n }\n\n });\n }\n\n private items: any = {\n notifications: BellRing,\n orders: OrderIcon,\n pending_orders: PendingOrdersIcon,\n wishlist: WishListIcon,\n profile: ProfileIcon,\n };\n\n @Element() host: HTMLElement;\n private readonly triggerSlot: string;\n @State() accountLoading: boolean = false;\n @State() opened: boolean = false;\n @State() notifications: string = salla.lang.get(\"common.titles.notifications\");\n @State() orders: string = salla.lang.get(\"common.titles.orders\");\n @State() pending_orders: string = salla.lang.get(\"common.titles.pending_orders\");\n @State() wishlist: string = salla.lang.get(\"common.titles.wishlist\");\n @State() profile: string = salla.lang.get(\"common.titles.profile\");\n @State() rating: string = salla.lang.get(\"common.titles.rating\");\n @State() logout: string = salla.lang.get(\"blocks.header.logout\");\n @State() hello: string = salla.lang.get(\"pages.checkout.hello\");\n @State() first_name: string = salla.storage.get('user.first_name') || '';\n @State() last_name: string = salla.storage.get('user.last_name') || '';\n @State() avatar: string = salla.storage.get('user.avatar') || salla.url.cdn('images/avatar.png');\n @State() is_loggedIn: boolean;\n @State() badges: any = {\n notifications: salla.helpers.number(salla.storage.get('user.notifications') || 0),\n pending_orders: salla.helpers.number(salla.storage.get('user.pending_orders') || 0)\n };\n\n @State() hasBadges: boolean = Number(salla.storage.get('user.pending_orders')) > 0 || Number(salla.storage.get('user.notifications')) > 0;\n /**\n * To display only the list without the dropdown functionality\n */\n @Prop({reflect: true}) inline: boolean = false;\n\n /**\n * To display the trigger as an avatar only\n */\n @Prop({reflect: true}) avatarOnly: boolean = false;\n\n /**\n * To display the dropdown header in mobile sheet\n */\n @Prop({reflect: true}) showHeader: boolean = false;\n\n /**\n * To Make the dropdown menu relative to parent element or not\n */\n @Prop({reflect: true}) relativeDropdown: boolean = false;\n\n private onClickOutside = () => {\n this.opened = false;\n }\n\n @State() OrderUpdate: number = 0;\n\n private fetchFreshProfile() {\n //don't request fetchFreshProfile unless token is injected into the api\n if (!salla.api.token) {\n salla.log('trying to fetchFreshProfile before injected the token!!');\n return;\n }\n salla.profile.api.info()\n .then((res) => {\n this.updateProfileState(res);\n });\n }\n\n private updateProfileState(res) {\n this.badges = {\n notifications: salla.helpers.number(res.data.notifications || 0),\n pending_orders: salla.helpers.number(res.data.pending_orders || 0)\n }\n this.hasBadges = Number(res.data.pending_orders) > 0 || Number(res.data.notifications) > 0;\n this.first_name = res.data.first_name;\n this.last_name = res.data.last_name;\n this.avatar = res.data.avatar || salla.url.cdn('images/avatar.png');\n }\n\n async open(e) {\n this.opened = !this.opened;\n e.stopPropagation()\n if (this.opened) {\n window.addEventListener('click', this.onClickOutside);\n }\n }\n\n private menuItemClicked(event: Event, item: string[]) {\n if (item[0] !== 'logout') {\n return;\n }\n event.preventDefault();\n salla.auth.logout('sall-user-menu');\n }\n\n private getTheHeader() {\n return <div class={{\n 's-user-menu-trigger-slot': true,\n 's-user-menu-red-dot': this.hasBadges,\n 's-user-menu-trigger-avatar-only': this.avatarOnly\n }}\n id='trigger-slot' onClick={(e) => this.open(e)} innerHTML={this.triggerSlot\n .replace(/\\{hello\\}/g, this.hello)\n .replace(/\\{first_name\\}/g, this.first_name)\n .replace(/\\{last_name\\}/g, this.last_name)\n .replace(/\\{avatar\\}/g, this.avatar)\n .replace(/\\{icon\\}/g, ArrowDown)}>\n </div>;\n }\n\n private getMenuItem(item: any[], i: number) {\n //todo:: enhancement support slot here\n return <li class={{\n 's-user-menu-dropdown-item': true,\n 's-user-menu-dropdown-item-logout': i + 1 == Object.entries(this.items).length\n }}>\n <a href={salla.url.get(item[0])} onClick={event => this.menuItemClicked(event, item)}>\n <i innerHTML={item[1]}> </i>\n <span class=\"s-user-menu-dropdown-item-title\">{this[item[0]]}</span>\n {!['٠', '0', undefined].includes(this.badges[item[0]])\n ? <span class=\"s-user-menu-dropdown-item-badge\">{this.badges[item[0]]}</span>\n : \"\"}\n </a>\n </li>;\n }\n\n componentShouldUpdate() {\n if (!this.opened) {\n window.removeEventListener('click', this.onClickOutside);\n }\n }\n\n render() {\n if (!this.is_loggedIn) {\n return <Host>\n <slot name='login-btn'>\n <button class=\"s-user-menu-login-btn\" onClick={() => salla.event.dispatch('login::open')}\n innerHTML={UserCircle}>\n </button>\n </slot>\n </Host>\n }\n\n if (this.inline) {\n return <Host>\n <ul class=\"s-user-menu-inline\">\n {Object.entries(this.items).map((item, i) => this.getMenuItem(item, i))}\n </ul>\n </Host>\n }\n\n return (\n <Host>\n <div class={{'s-user-menu-wrapper': true, 's-user-menu-relative-dropdown': this.relativeDropdown}}>\n {this.getTheHeader()}\n <div class={{'s-user-menu-toggler': true, 'opened': this.opened}}>\n <div class=\"s-user-menu-dropdown\" onClick={(e) => e.stopPropagation()}>\n {this.showHeader ? <div class=\"s-user-menu-dropdown-header\">\n <img src={this.avatar} alt={`${this.first_name} ${this.last_name}`}/>\n <div class=\"s-user-menu-dropdown-header-content\">\n <span>{this.hello}</span>\n <p>{this.first_name} {this.last_name}</p>\n </div>\n <button class=\"s-user-menu-dropdown-header-close\" innerHTML={Cancel}\n onClick={() => this.opened = false}>\n </button>\n </div> : ''}\n <ul class=\"s-user-menu-dropdown-list\">\n {Object.entries(this.items).map((item, i) => this.getMenuItem(item, i))}\n </ul>\n </div>\n </div>\n </div>\n </Host>\n );\n }\n\n componentDidLoad() {\n //make sure to load the avatar if it's lazy, we use it in Y\n document.lazyLoadInstance?.update(this.host.querySelectorAll('.lazy'));\n }\n}\n"]}
@@ -107,12 +107,18 @@ const SallaUserMenu$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLEleme
107
107
  * //todo:: cover two requests in customer pages
108
108
  * //todo:: make sure to run this only after token is set
109
109
  */
110
- if (salla.url.is_page('customer.notifications')
110
+ const shouldFetchProfile = !this.inline && (salla.url.is_page('customer.notifications')
111
111
  || salla.url.is_page('customer.orders.index.pending')
112
112
  || salla.url.is_page('customer.profile')
113
- || ((Date.now() - (salla.storage.get('user.fetched_at') || 0)) / 1000 / 60) > 30) {
113
+ || ((Date.now() - (salla.storage.get('user.fetched_at') || 0)) / 1000 / 60) > 30);
114
+ if (shouldFetchProfile) {
114
115
  this.fetchFreshProfile();
115
116
  }
117
+ else {
118
+ salla.event.on('profile::info.fetched', res => {
119
+ this.updateProfileState(res);
120
+ });
121
+ }
116
122
  });
117
123
  }
118
124
  fetchFreshProfile() {
@@ -123,14 +129,19 @@ const SallaUserMenu$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLEleme
123
129
  }
124
130
  salla.profile.api.info()
125
131
  .then((res) => {
126
- this.badges.pending_orders = salla.helpers.number(res.data.pending_orders || 0);
127
- this.badges.notifications = salla.helpers.number(res.data.notifications || 0);
128
- this.hasBadges = Number(res.data.pending_orders) > 0 || Number(res.data.notifications) > 0;
129
- this.first_name = res.data.first_name;
130
- this.last_name = res.data.last_name;
131
- this.avatar = res.data.avatar || salla.url.cdn('images/avatar.png');
132
+ this.updateProfileState(res);
132
133
  });
133
134
  }
135
+ updateProfileState(res) {
136
+ this.badges = {
137
+ notifications: salla.helpers.number(res.data.notifications || 0),
138
+ pending_orders: salla.helpers.number(res.data.pending_orders || 0)
139
+ };
140
+ this.hasBadges = Number(res.data.pending_orders) > 0 || Number(res.data.notifications) > 0;
141
+ this.first_name = res.data.first_name;
142
+ this.last_name = res.data.last_name;
143
+ this.avatar = res.data.avatar || salla.url.cdn('images/avatar.png');
144
+ }
134
145
  async open(e) {
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AC,SAAS,EAAE,MAAM,EAC3D,OAAO,EAAE,MAAM,IAAI,CAAC,MAAM,GAAG,KAAK,GACjC,CACL,GAAG,EAAE,EACX,UAAI,KAAK,EAAC,2BAA2B,IAClC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CACpE,CACD,CACF,CACF,CACD,EACP;GACH;EAED,gBAAgB;;;IAEd,MAAA,QAAQ,CAAC,gBAAgB,0CAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;GACxE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["SallaUserMenu","ProfileIcon"],"sources":["./src/components/salla-user-menu/salla-user-menu.scss?tag=salla-user-menu","./src/components/salla-user-menu/salla-user-menu.tsx"],"sourcesContent":[".s-user-menu{\n &-wrapper{\n\n }\n &-toggler{\n\n }\n // Default trigger\n &-trigger{\n &-avatar{\n\n }\n &-content{\n\n }\n &-hello{\n\n }\n &-name{\n\n }\n &-icon{\n\n }\n }\n // Your custom trigger\n &-trigger-slot{\n\n }\n &-dropdown{\n &-header{\n img{\n\n }\n &-content{\n\n }\n &-close{\n\n }\n }\n &-list{\n\n }\n &-item{\n &-title{\n\n }\n &-badge{\n\n }\n }\n\n }\n &-inline{\n \n }\n}\n","import {Component, Host, h, State, Element, Prop} from '@stencil/core';\n// Icons\nimport ArrowDown from \"../../assets/svg/keyboard_arrow_down.svg\"\nimport BellRing from \"../../assets/svg/bell-ring.svg\"\nimport OrderIcon from \"../../assets/svg/box-bankers.svg\"\nimport PendingOrdersIcon from \"../../assets/svg/cart.svg\"\nimport WishListIcon from \"../../assets/svg/star.svg\"\nimport ProfileIcon from \"../../assets/svg/user-circle.svg\"\nimport LogoutIcon from \"../../assets/svg/send-out.svg\"\nimport Cancel from \"../../assets/svg/cancel.svg\"\nimport Rate from \"../../assets/svg/star2.svg\";\nimport UserCircle from \"../../assets/svg/user-circle.svg\";\n\n/**\n * @slot trigger - Replaces trigger widget, has replaceable props `{avatar}`, `{hello}`, `{first_name}`, `{last_name}`, `{icon}`.\n * @slot login-btn - Replaces the login button, it must be used with `salla.event.dispatch('login::open')` to open the login modal.\n */\n@Component({\n tag: 'salla-user-menu',\n styleUrl: 'salla-user-menu.scss',\n})\nexport class SallaUserMenu {\n constructor() {\n\n // salla.auth.event.onLoggedIn(() => {\n // this.is_loggedIn = true\n // })\n\n salla.lang.onLoaded(() => {\n this.notifications = salla.lang.get(\"common.titles.notifications\");\n this.orders = salla.lang.get(\"common.titles.orders\");\n this.pending_orders = salla.lang.get(\"common.titles.pending_orders\");\n this.wishlist = salla.lang.get(\"common.titles.wishlist\");\n this.profile = salla.lang.get(\"common.titles.profile\");\n this.hello = salla.lang.get(\"pages.checkout.hello\");\n this.rating = salla.lang.get(\"common.titles.rating\");\n this.logout = salla.lang.get(\"blocks.header.logout\");\n });\n\n //we need it only in theme-y\n if (this.host.hasAttribute('with-rating')) {\n this.items.rating = Rate;\n }\n //we need it to be the last item\n this.items.logout = LogoutIcon;\n\n this.triggerSlot = this.host.querySelector('[slot=\"trigger\"]')?.innerHTML || '<div class=\"s-user-menu-trigger\"><div class=\"s-user-menu-avatar-wrap\"><img class=\"s-user-menu-trigger-avatar\" src=\"{avatar}\" alt=\"{first_name}{last_name}\" /></div><div class=\"s-user-menu-trigger-content\"><span class=\"s-user-menu-trigger-hello\">{hello}</span><p class=\"s-user-menu-trigger-name\">{first_name} {last_name}</p></div> <i class=\"s-user-menu-trigger-icon\">{icon}</i></div>';\n salla.onReady(() => {\n if (salla.config.isGuest()) {\n return;\n }\n\n this.is_loggedIn = true;\n /**\n * Get Fresh Notifications In These Cases:\n * - is notification page, if user already changed the status of his orders (to reset notification badge)\n * - is pending orders page, if user already changed the status of his orders (to reset orders badge)\n * - is profile page, in case user changed his name or avatar, we need to update it\n * - half hour is passed from the last user data fetched\n *\n * //todo:: update the data in the storage in customer pages\n * //todo:: cover two requests in customer pages\n * //todo:: make sure to run this only after token is set\n */\n if (salla.url.is_page('customer.notifications')\n || salla.url.is_page('customer.orders.index.pending')\n || salla.url.is_page('customer.profile')\n || ((Date.now() - (salla.storage.get('user.fetched_at') || 0)) / 1000 / 60) > 30) {\n this.fetchFreshProfile();\n }\n });\n }\n\n private items: any = {\n notifications: BellRing,\n orders: OrderIcon,\n pending_orders: PendingOrdersIcon,\n wishlist: WishListIcon,\n profile: ProfileIcon,\n };\n\n @Element() host: HTMLElement;\n private readonly triggerSlot: string;\n @State() accountLoading: boolean = false;\n @State() opened: boolean = false;\n @State() notifications: string = salla.lang.get(\"common.titles.notifications\");\n @State() orders: string = salla.lang.get(\"common.titles.orders\");\n @State() pending_orders: string = salla.lang.get(\"common.titles.pending_orders\");\n @State() wishlist: string = salla.lang.get(\"common.titles.wishlist\");\n @State() profile: string = salla.lang.get(\"common.titles.profile\");\n @State() rating: string = salla.lang.get(\"common.titles.rating\");\n @State() logout: string = salla.lang.get(\"blocks.header.logout\");\n @State() hello: string = salla.lang.get(\"pages.checkout.hello\");\n @State() first_name: string = salla.storage.get('user.first_name') || '';\n @State() last_name: string = salla.storage.get('user.last_name') || '';\n @State() avatar: string = salla.storage.get('user.avatar') || salla.url.cdn('images/avatar.png');\n @State() is_loggedIn: boolean;\n @State() badges: any = {\n notifications: salla.helpers.number(salla.storage.get('user.notifications') || 0),\n pending_orders: salla.helpers.number(salla.storage.get('user.pending_orders') || 0)\n };\n\n @State() hasBadges: boolean = Number(salla.storage.get('user.pending_orders')) > 0 || Number(salla.storage.get('user.notifications')) > 0;\n /**\n * To display only the list without the dropdown functionality\n */\n @Prop({reflect: true}) inline: boolean = false;\n\n /**\n * To display the trigger as an avatar only\n */\n @Prop({reflect: true}) avatarOnly: boolean = false;\n\n /**\n * To display the dropdown header in mobile sheet\n */\n @Prop({reflect: true}) showHeader: boolean = false;\n\n /**\n * To Make the dropdown menu relative to parent element or not\n */\n @Prop({reflect: true}) relativeDropdown: boolean = false;\n\n private onClickOutside = () => {\n this.opened = false;\n }\n\n @State() OrderUpdate: number = 0;\n\n private fetchFreshProfile() {\n //don't request fetchFreshProfile unless token is injected into the api\n if (!salla.api.token) {\n salla.log('trying to fetchFreshProfile before injected the token!!');\n return;\n }\n salla.profile.api.info()\n .then((res) => {\n this.badges.pending_orders = salla.helpers.number(res.data.pending_orders || 0);\n this.badges.notifications = salla.helpers.number(res.data.notifications || 0);\n this.hasBadges = Number(res.data.pending_orders) > 0 || Number(res.data.notifications) > 0;\n this.first_name = res.data.first_name;\n this.last_name = res.data.last_name;\n this.avatar = res.data.avatar || salla.url.cdn('images/avatar.png');\n });\n }\n\n async open(e) {\n this.opened = !this.opened;\n e.stopPropagation()\n if (this.opened) {\n window.addEventListener('click', this.onClickOutside);\n }\n }\n\n private menuItemClicked(event: Event, item: string[]) {\n if (item[0] !== 'logout') {\n return;\n }\n event.preventDefault();\n salla.auth.logout('sall-user-menu');\n }\n\n private getTheHeader() {\n return <div class={{\n 's-user-menu-trigger-slot': true,\n 's-user-menu-red-dot': this.hasBadges,\n 's-user-menu-trigger-avatar-only': this.avatarOnly\n }}\n id='trigger-slot' onClick={(e) => this.open(e)} innerHTML={this.triggerSlot\n .replace(/\\{hello\\}/g, this.hello)\n .replace(/\\{first_name\\}/g, this.first_name)\n .replace(/\\{last_name\\}/g, this.last_name)\n .replace(/\\{avatar\\}/g, this.avatar)\n .replace(/\\{icon\\}/g, ArrowDown)}>\n </div>;\n }\n\n private getMenuItem(item: any[], i: number) {\n //todo:: enhancement support slot here\n return <li class={{\n 's-user-menu-dropdown-item': true,\n 's-user-menu-dropdown-item-logout': i + 1 == Object.entries(this.items).length\n }}>\n <a href={salla.url.get(item[0])} onClick={event => this.menuItemClicked(event, item)}>\n <i innerHTML={item[1]}> </i>\n <span class=\"s-user-menu-dropdown-item-title\">{this[item[0]]}</span>\n {!['٠', '0', undefined].includes(this.badges[item[0]])\n ? <span class=\"s-user-menu-dropdown-item-badge\">{this.badges[item[0]]}</span>\n : \"\"}\n </a>\n </li>;\n }\n\n componentShouldUpdate() {\n if (!this.opened) {\n window.removeEventListener('click', this.onClickOutside);\n }\n }\n\n render() {\n if (!this.is_loggedIn) {\n return <Host>\n <slot name='login-btn'>\n <button class=\"s-user-menu-login-btn\" onClick={() => salla.event.dispatch('login::open')}\n innerHTML={UserCircle}>\n </button>\n </slot>\n </Host>\n }\n\n if (this.inline) {\n return <Host>\n <ul class=\"s-user-menu-inline\">\n {Object.entries(this.items).map((item, i) => this.getMenuItem(item, i))}\n </ul>\n </Host>\n }\n\n return (\n <Host>\n <div class={{'s-user-menu-wrapper': true, 's-user-menu-relative-dropdown': this.relativeDropdown}}>\n {this.getTheHeader()}\n <div class={{'s-user-menu-toggler': true, 'opened': this.opened}}>\n <div class=\"s-user-menu-dropdown\" onClick={(e) => e.stopPropagation()}>\n {this.showHeader ? <div class=\"s-user-menu-dropdown-header\">\n <img src={this.avatar} alt={`${this.first_name} ${this.last_name}`}/>\n <div class=\"s-user-menu-dropdown-header-content\">\n <span>{this.hello}</span>\n <p>{this.first_name} {this.last_name}</p>\n </div>\n <button class=\"s-user-menu-dropdown-header-close\" innerHTML={Cancel}\n onClick={() => this.opened = false}>\n </button>\n </div> : ''}\n <ul class=\"s-user-menu-dropdown-list\">\n {Object.entries(this.items).map((item, i) => this.getMenuItem(item, i))}\n </ul>\n </div>\n </div>\n </div>\n </Host>\n );\n }\n\n componentDidLoad() {\n //make sure to load the avatar if it's lazy, we use it in Y\n document.lazyLoadInstance?.update(this.host.querySelectorAll('.lazy'));\n }\n}\n"],"version":3}
1
+ {"file":"salla-user-menu.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAM,gBAAgB,GAAG,EAAE;;MCqBdA,eAAa;EACxB;;;;IA4DQ,UAAK,GAAQ;MACnB,aAAa,EAA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U,OAAG,IAAI,CAAC,SAAS,CAAK,CACrC,EACN,cAAQ,KAAK,EAAC,mCAAmC,EAAC,SAAS,EAAE,MAAM,EAC3D,OAAO,EAAE,MAAM,IAAI,CAAC,MAAM,GAAG,KAAK,GACjC,CACL,GAAG,EAAE,EACX,UAAI,KAAK,EAAC,2BAA2B,IAClC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CACpE,CACD,CACF,CACF,CACD,EACP;GACH;EAED,gBAAgB;;;IAEd,MAAA,QAAQ,CAAC,gBAAgB,0CAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;GACxE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["SallaUserMenu","ProfileIcon"],"sources":["./src/components/salla-user-menu/salla-user-menu.scss?tag=salla-user-menu","./src/components/salla-user-menu/salla-user-menu.tsx"],"sourcesContent":[".s-user-menu{\n &-wrapper{\n\n }\n &-toggler{\n\n }\n // Default trigger\n &-trigger{\n &-avatar{\n\n }\n &-content{\n\n }\n &-hello{\n\n }\n &-name{\n\n }\n &-icon{\n\n }\n }\n // Your custom trigger\n &-trigger-slot{\n\n }\n &-dropdown{\n &-header{\n img{\n\n }\n &-content{\n\n }\n &-close{\n\n }\n }\n &-list{\n\n }\n &-item{\n &-title{\n\n }\n &-badge{\n\n }\n }\n\n }\n &-inline{\n \n }\n}\n","import {Component, Host, h, State, Element, Prop} from '@stencil/core';\n// Icons\nimport ArrowDown from \"../../assets/svg/keyboard_arrow_down.svg\"\nimport BellRing from \"../../assets/svg/bell-ring.svg\"\nimport OrderIcon from \"../../assets/svg/box-bankers.svg\"\nimport PendingOrdersIcon from \"../../assets/svg/cart.svg\"\nimport WishListIcon from \"../../assets/svg/star.svg\"\nimport ProfileIcon from \"../../assets/svg/user-circle.svg\"\nimport LogoutIcon from \"../../assets/svg/send-out.svg\"\nimport Cancel from \"../../assets/svg/cancel.svg\"\nimport Rate from \"../../assets/svg/star2.svg\";\nimport UserCircle from \"../../assets/svg/user-circle.svg\";\n\n/**\n * @slot trigger - Replaces trigger widget, has replaceable props `{avatar}`, `{hello}`, `{first_name}`, `{last_name}`, `{icon}`.\n * @slot login-btn - Replaces the login button, it must be used with `salla.event.dispatch('login::open')` to open the login modal.\n */\n@Component({\n tag: 'salla-user-menu',\n styleUrl: 'salla-user-menu.scss',\n})\nexport class SallaUserMenu {\n constructor() {\n\n // salla.auth.event.onLoggedIn(() => {\n // this.is_loggedIn = true\n // })\n\n salla.lang.onLoaded(() => {\n this.notifications = salla.lang.get(\"common.titles.notifications\");\n this.orders = salla.lang.get(\"common.titles.orders\");\n this.pending_orders = salla.lang.get(\"common.titles.pending_orders\");\n this.wishlist = salla.lang.get(\"common.titles.wishlist\");\n this.profile = salla.lang.get(\"common.titles.profile\");\n this.hello = salla.lang.get(\"pages.checkout.hello\");\n this.rating = salla.lang.get(\"common.titles.rating\");\n this.logout = salla.lang.get(\"blocks.header.logout\");\n });\n\n //we need it only in theme-y\n if (this.host.hasAttribute('with-rating')) {\n this.items.rating = Rate;\n }\n //we need it to be the last item\n this.items.logout = LogoutIcon;\n\n this.triggerSlot = this.host.querySelector('[slot=\"trigger\"]')?.innerHTML || '<div class=\"s-user-menu-trigger\"><div class=\"s-user-menu-avatar-wrap\"><img class=\"s-user-menu-trigger-avatar\" src=\"{avatar}\" alt=\"{first_name}{last_name}\" /></div><div class=\"s-user-menu-trigger-content\"><span class=\"s-user-menu-trigger-hello\">{hello}</span><p class=\"s-user-menu-trigger-name\">{first_name} {last_name}</p></div> <i class=\"s-user-menu-trigger-icon\">{icon}</i></div>';\n salla.onReady(() => {\n if (salla.config.isGuest()) {\n return;\n }\n\n this.is_loggedIn = true;\n /**\n * Get Fresh Notifications In These Cases:\n * - is notification page, if user already changed the status of his orders (to reset notification badge)\n * - is pending orders page, if user already changed the status of his orders (to reset orders badge)\n * - is profile page, in case user changed his name or avatar, we need to update it\n * - half hour is passed from the last user data fetched\n *\n * //todo:: update the data in the storage in customer pages\n * //todo:: cover two requests in customer pages\n * //todo:: make sure to run this only after token is set\n */\n const shouldFetchProfile = !this.inline && (\n salla.url.is_page('customer.notifications')\n || salla.url.is_page('customer.orders.index.pending')\n || salla.url.is_page('customer.profile')\n || ((Date.now() - (salla.storage.get('user.fetched_at') || 0)) / 1000 / 60) > 30\n );\n\n if(shouldFetchProfile){\n this.fetchFreshProfile()\n }else{\n salla.event.on('profile::info.fetched', res => {\n this.updateProfileState(res)\n });\n }\n\n });\n }\n\n private items: any = {\n notifications: BellRing,\n orders: OrderIcon,\n pending_orders: PendingOrdersIcon,\n wishlist: WishListIcon,\n profile: ProfileIcon,\n };\n\n @Element() host: HTMLElement;\n private readonly triggerSlot: string;\n @State() accountLoading: boolean = false;\n @State() opened: boolean = false;\n @State() notifications: string = salla.lang.get(\"common.titles.notifications\");\n @State() orders: string = salla.lang.get(\"common.titles.orders\");\n @State() pending_orders: string = salla.lang.get(\"common.titles.pending_orders\");\n @State() wishlist: string = salla.lang.get(\"common.titles.wishlist\");\n @State() profile: string = salla.lang.get(\"common.titles.profile\");\n @State() rating: string = salla.lang.get(\"common.titles.rating\");\n @State() logout: string = salla.lang.get(\"blocks.header.logout\");\n @State() hello: string = salla.lang.get(\"pages.checkout.hello\");\n @State() first_name: string = salla.storage.get('user.first_name') || '';\n @State() last_name: string = salla.storage.get('user.last_name') || '';\n @State() avatar: string = salla.storage.get('user.avatar') || salla.url.cdn('images/avatar.png');\n @State() is_loggedIn: boolean;\n @State() badges: any = {\n notifications: salla.helpers.number(salla.storage.get('user.notifications') || 0),\n pending_orders: salla.helpers.number(salla.storage.get('user.pending_orders') || 0)\n };\n\n @State() hasBadges: boolean = Number(salla.storage.get('user.pending_orders')) > 0 || Number(salla.storage.get('user.notifications')) > 0;\n /**\n * To display only the list without the dropdown functionality\n */\n @Prop({reflect: true}) inline: boolean = false;\n\n /**\n * To display the trigger as an avatar only\n */\n @Prop({reflect: true}) avatarOnly: boolean = false;\n\n /**\n * To display the dropdown header in mobile sheet\n */\n @Prop({reflect: true}) showHeader: boolean = false;\n\n /**\n * To Make the dropdown menu relative to parent element or not\n */\n @Prop({reflect: true}) relativeDropdown: boolean = false;\n\n private onClickOutside = () => {\n this.opened = false;\n }\n\n @State() OrderUpdate: number = 0;\n\n private fetchFreshProfile() {\n //don't request fetchFreshProfile unless token is injected into the api\n if (!salla.api.token) {\n salla.log('trying to fetchFreshProfile before injected the token!!');\n return;\n }\n salla.profile.api.info()\n .then((res) => {\n this.updateProfileState(res);\n });\n }\n\n private updateProfileState(res) {\n this.badges = {\n notifications: salla.helpers.number(res.data.notifications || 0),\n pending_orders: salla.helpers.number(res.data.pending_orders || 0)\n }\n this.hasBadges = Number(res.data.pending_orders) > 0 || Number(res.data.notifications) > 0;\n this.first_name = res.data.first_name;\n this.last_name = res.data.last_name;\n this.avatar = res.data.avatar || salla.url.cdn('images/avatar.png');\n }\n\n async open(e) {\n this.opened = !this.opened;\n e.stopPropagation()\n if (this.opened) {\n window.addEventListener('click', this.onClickOutside);\n }\n }\n\n private menuItemClicked(event: Event, item: string[]) {\n if (item[0] !== 'logout') {\n return;\n }\n event.preventDefault();\n salla.auth.logout('sall-user-menu');\n }\n\n private getTheHeader() {\n return <div class={{\n 's-user-menu-trigger-slot': true,\n 's-user-menu-red-dot': this.hasBadges,\n 's-user-menu-trigger-avatar-only': this.avatarOnly\n }}\n id='trigger-slot' onClick={(e) => this.open(e)} innerHTML={this.triggerSlot\n .replace(/\\{hello\\}/g, this.hello)\n .replace(/\\{first_name\\}/g, this.first_name)\n .replace(/\\{last_name\\}/g, this.last_name)\n .replace(/\\{avatar\\}/g, this.avatar)\n .replace(/\\{icon\\}/g, ArrowDown)}>\n </div>;\n }\n\n private getMenuItem(item: any[], i: number) {\n //todo:: enhancement support slot here\n return <li class={{\n 's-user-menu-dropdown-item': true,\n 's-user-menu-dropdown-item-logout': i + 1 == Object.entries(this.items).length\n }}>\n <a href={salla.url.get(item[0])} onClick={event => this.menuItemClicked(event, item)}>\n <i innerHTML={item[1]}> </i>\n <span class=\"s-user-menu-dropdown-item-title\">{this[item[0]]}</span>\n {!['٠', '0', undefined].includes(this.badges[item[0]])\n ? <span class=\"s-user-menu-dropdown-item-badge\">{this.badges[item[0]]}</span>\n : \"\"}\n </a>\n </li>;\n }\n\n componentShouldUpdate() {\n if (!this.opened) {\n window.removeEventListener('click', this.onClickOutside);\n }\n }\n\n render() {\n if (!this.is_loggedIn) {\n return <Host>\n <slot name='login-btn'>\n <button class=\"s-user-menu-login-btn\" onClick={() => salla.event.dispatch('login::open')}\n innerHTML={UserCircle}>\n </button>\n </slot>\n </Host>\n }\n\n if (this.inline) {\n return <Host>\n <ul class=\"s-user-menu-inline\">\n {Object.entries(this.items).map((item, i) => this.getMenuItem(item, i))}\n </ul>\n </Host>\n }\n\n return (\n <Host>\n <div class={{'s-user-menu-wrapper': true, 's-user-menu-relative-dropdown': this.relativeDropdown}}>\n {this.getTheHeader()}\n <div class={{'s-user-menu-toggler': true, 'opened': this.opened}}>\n <div class=\"s-user-menu-dropdown\" onClick={(e) => e.stopPropagation()}>\n {this.showHeader ? <div class=\"s-user-menu-dropdown-header\">\n <img src={this.avatar} alt={`${this.first_name} ${this.last_name}`}/>\n <div class=\"s-user-menu-dropdown-header-content\">\n <span>{this.hello}</span>\n <p>{this.first_name} {this.last_name}</p>\n </div>\n <button class=\"s-user-menu-dropdown-header-close\" innerHTML={Cancel}\n onClick={() => this.opened = false}>\n </button>\n </div> : ''}\n <ul class=\"s-user-menu-dropdown-list\">\n {Object.entries(this.items).map((item, i) => this.getMenuItem(item, i))}\n </ul>\n </div>\n </div>\n </div>\n </Host>\n );\n }\n\n componentDidLoad() {\n //make sure to load the avatar if it's lazy, we use it in Y\n document.lazyLoadInstance?.update(this.host.querySelectorAll('.lazy'));\n }\n}\n"],"version":3}
@@ -27990,12 +27990,18 @@ const SallaUserMenu = class {
27990
27990
  * //todo:: cover two requests in customer pages
27991
27991
  * //todo:: make sure to run this only after token is set
27992
27992
  */
27993
- if (salla.url.is_page('customer.notifications')
27993
+ const shouldFetchProfile = !this.inline && (salla.url.is_page('customer.notifications')
27994
27994
  || salla.url.is_page('customer.orders.index.pending')
27995
27995
  || salla.url.is_page('customer.profile')
27996
- || ((Date.now() - (salla.storage.get('user.fetched_at') || 0)) / 1000 / 60) > 30) {
27996
+ || ((Date.now() - (salla.storage.get('user.fetched_at') || 0)) / 1000 / 60) > 30);
27997
+ if (shouldFetchProfile) {
27997
27998
  this.fetchFreshProfile();
27998
27999
  }
28000
+ else {
28001
+ salla.event.on('profile::info.fetched', res => {
28002
+ this.updateProfileState(res);
28003
+ });
28004
+ }
27999
28005
  });
28000
28006
  }
28001
28007
  fetchFreshProfile() {
@@ -28006,14 +28012,19 @@ const SallaUserMenu = class {
28006
28012
  }
28007
28013
  salla.profile.api.info()
28008
28014
  .then((res) => {
28009
- this.badges.pending_orders = salla.helpers.number(res.data.pending_orders || 0);
28010
- this.badges.notifications = salla.helpers.number(res.data.notifications || 0);
28011
- this.hasBadges = Number(res.data.pending_orders) > 0 || Number(res.data.notifications) > 0;
28012
- this.first_name = res.data.first_name;
28013
- this.last_name = res.data.last_name;
28014
- this.avatar = res.data.avatar || salla.url.cdn('images/avatar.png');
28015
+ this.updateProfileState(res);
28015
28016
  });
28016
28017
  }
28018
+ updateProfileState(res) {
28019
+ this.badges = {
28020
+ notifications: salla.helpers.number(res.data.notifications || 0),
28021
+ pending_orders: salla.helpers.number(res.data.pending_orders || 0)
28022
+ };
28023
+ this.hasBadges = Number(res.data.pending_orders) > 0 || Number(res.data.notifications) > 0;
28024
+ this.first_name = res.data.first_name;
28025
+ this.last_name = res.data.last_name;
28026
+ this.avatar = res.data.avatar || salla.url.cdn('images/avatar.png');
28027
+ }
28017
28028
  async open(e) {
28018
28029
  this.opened = !this.opened;
28019
28030
  e.stopPropagation();