@salla.sa/twilight-components
Version:
Salla Web Component
87 lines (80 loc) • 10.9 kB
JavaScript
/*!
* Crafted with ❤ by Salla
*/
import { r as registerInstance, h, H as Host } from './index-BHYtfMwX.js';
var Bullhorn = `<!-- Generated by IcoMoon.io -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
<title>bullhorn</title>
<path d="M30.129 0.264c-0.339-0.252-0.776-0.328-1.179-0.208l-24.951 7.485v-0.216c0-0.736-0.597-1.333-1.333-1.333s-1.333 0.597-1.333 1.333v14.667c0 0.736 0.597 1.333 1.333 1.333s1.333-0.597 1.333-1.333v-0.112l3.448 1.207-0.595 1.704c-0.321 1.019-0.227 2.103 0.267 3.051s1.327 1.647 2.345 1.968l6.359 2.004c0.399 0.127 0.804 0.187 1.201 0.187 1.699 0 3.277-1.091 3.812-2.785l0.423-1.295 7.633 2.672c0.143 0.049 0.292 0.075 0.44 0.075 0.273 0 0.543-0.084 0.772-0.247 0.352-0.249 0.561-0.655 0.561-1.087v-28c0-0.421-0.199-0.819-0.537-1.069zM18.297 28.4c-0.221 0.701-0.973 1.089-1.673 0.871l-6.357-2.004c-0.34-0.108-0.617-0.34-0.781-0.656s-0.196-0.676-0.101-0.977l0.581-1.665 8.777 3.072zM28 27.453l-24-8.4v-8.728l24-7.2z"></path>
</svg>
`;
var UserOff = `<!-- Generated by IcoMoon.io -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
<title>user-off</title>
<path d="M10.837 19.309c-4.963 1.284-8.171 4.303-8.171 7.691v3.667c0 0.736 0.597 1.333 1.333 1.333s1.333-0.597 1.333-1.333v-3.667c0-2.101 2.48-4.155 6.172-5.109 0.713-0.184 1.141-0.912 0.957-1.625-0.184-0.711-0.908-1.137-1.625-0.956zM12.859 3.715c0.933-0.685 2.020-1.048 3.141-1.048 2.941 0 5.333 2.392 5.333 5.333 0 1.121-0.363 2.208-1.048 3.141-0.436 0.593-0.308 1.428 0.284 1.864 0.239 0.175 0.515 0.259 0.788 0.259 0.411 0 0.815-0.188 1.076-0.544 1.025-1.393 1.567-3.025 1.567-4.72 0-4.412-3.588-8-8-8-1.695 0-3.327 0.541-4.721 1.567-0.592 0.435-0.72 1.269-0.284 1.864 0.436 0.593 1.269 0.721 1.864 0.284zM31.609 29.724l-29.333-29.333c-0.521-0.521-1.364-0.521-1.885 0s-0.521 1.364 0 1.885l29.333 29.333c0.26 0.26 0.601 0.391 0.943 0.391s0.683-0.131 0.943-0.391c0.521-0.521 0.521-1.364 0-1.885z"></path>
</svg>
`;
var UserCancel = `<!-- Generated by IcoMoon.io -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
<title>user-cancel</title>
<path d="M29.885 16l1.724-1.724c0.521-0.521 0.521-1.364 0-1.885s-1.364-0.521-1.885 0l-1.724 1.724-1.724-1.724c-0.521-0.521-1.364-0.521-1.885 0s-0.521 1.364 0 1.885l1.724 1.724-1.724 1.724c-0.521 0.521-0.521 1.364 0 1.885 0.26 0.26 0.601 0.391 0.943 0.391s0.683-0.131 0.943-0.391l1.724-1.724 1.724 1.724c0.26 0.26 0.601 0.391 0.943 0.391s0.683-0.131 0.943-0.391c0.521-0.521 0.521-1.364 0-1.885zM10.667 16c4.043 0 7.333-3.289 7.333-7.333s-3.291-7.333-7.333-7.333-7.333 3.289-7.333 7.333 3.291 7.333 7.333 7.333zM10.667 4c2.573 0 4.667 2.093 4.667 4.667s-2.093 4.667-4.667 4.667-4.667-2.093-4.667-4.667 2.093-4.667 4.667-4.667zM10.667 18.667c-5.881 0-10.667 3.813-10.667 8.5v2.167c0 0.736 0.596 1.333 1.333 1.333s1.333-0.597 1.333-1.333v-2.167c0-3.217 3.588-5.833 8-5.833s8 2.616 8 5.833v2.167c0 0.736 0.596 1.333 1.333 1.333s1.333-0.597 1.333-1.333v-2.167c0-4.687-4.785-8.5-10.667-8.5z"></path>
</svg>
`;
const sallaUserSettingsCss = "";
const SallaUserSettings = class {
constructor(hostRef) {
registerInstance(this, hostRef);
// Texts
this.deactivateAccount = salla.lang.get('pages.profile.deactivate_account');
this.promotionalMsgs = salla.lang.get('pages.profile.promotional_messages');
this.hideMyName = salla.lang.get('pages.profile.hide_my_name');
this.hideMyNameDesc = salla.lang.get('pages.profile.hide_my_name_desc');
this.deactivateDesc = salla.lang.get('pages.profile.deactivate_account_description');
this.promotionalMsgsDesc = salla.lang.get('pages.profile.promotional_messages_description');
this.sorryForLeavingText = salla.lang.get('pages.profile.warning_for_deactivate');
this.warningText = salla.lang.get('pages.profile.sorry_for_leaving');
this.keepAccount = salla.lang.get('pages.profile.keep_account');
this.buttonLoading = false;
this.canHideName = salla.config.get('store.settings.rating.can_customer_hide_name');
salla.onReady(() => {
this.isHiddenName = salla.config.get('user.is_hidden_name');
this.isNotifiable = salla.config.get('user.is_notifiable');
this.canHideName = salla.config.get('store.settings.rating.can_customer_hide_name');
if (!this.isNotifiable || !this.isHiddenName) {
salla.event.on('profile::info.fetched', res => {
this.isHiddenName = res.data.is_hidden_name;
this.isNotifiable = res.data.is_notifiable;
});
}
});
salla.lang.onLoaded(() => {
this.deactivateAccount = salla.lang.get('pages.profile.deactivate_account');
this.promotionalMsgs = salla.lang.get('pages.profile.promotional_messages');
this.hideMyName = salla.lang.get('pages.profile.hide_my_name');
this.hideMyNameDesc = salla.lang.get('pages.profile.hide_my_name_desc');
this.deactivateDesc = salla.lang.get('pages.profile.deactivate_account_description');
this.promotionalMsgsDesc = salla.lang.get('pages.profile.promotional_messages_description');
this.warningText = salla.lang.get('pages.profile.warning_for_deactivate');
this.sorryForLeavingText = salla.lang.get('pages.profile.sorry_for_leaving');
this.keepAccount = salla.lang.get('pages.profile.keep_account');
});
}
toggleSetting(setting, event) {
salla.profile.updateSettings({ name: setting, value: event.target.checked });
}
capitalizeText(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
openDeactivateModal() {
this.confirmationModal.setTitle(this.capitalizeText(this.deactivateAccount));
this.confirmationModal.open();
}
async deleteAccount() {
await salla.profile.delete().finally(() => this.confirmationModal.close());
}
render() {
return (h(Host, { key: 'd49fe1cc125040388326a346cf6349cdff3e8827', class: "s-user-settings-wrapper" }, this.canHideName && h("div", { key: '4f6227afbf0f1a9ac4ae6c0404c04de65ef2c22d', class: "s-user-settings-section" }, h("salla-list-tile", { key: 'd084e7c978e0f41b8997299690e1b419f1dcecea' }, h("div", { key: '732f09a315529dd23a690ec2e2db2ca157f30b3f', slot: "icon", class: "s-user-settings-section-icon" }, h("span", { key: '57854cdcd75e9bdf261cc10108b9dd03ba886c9a', innerHTML: UserCancel })), h("div", { key: '4d42778a9a52a6a539f9c84103a4e35ab10eadce', slot: "title", class: "s-user-settings-section-title" }, this.capitalizeText(this.hideMyName)), h("div", { key: '45ea0bf9bbc5d055e50de279ed21c77f69194a83', slot: "subtitle", class: "s-user-settings-section-subtitle" }, this.capitalizeText(this.hideMyNameDesc)), h("div", { key: 'addf60ce92d9bd5d7307af22f8e08ca627f52692', slot: 'action', class: "s-user-settings-section-action" }, h("label", { key: 'db9bfdd607f9578349051126893fcd77eccc8aea', class: "s-toggle" }, h("input", { key: '5c56ac1adffc24c7d1190251713d99214ef242e3', class: "s-toggle-input", checked: this.isHiddenName, onChange: (e) => this.toggleSetting('is_hidden_name', e), type: "checkbox" }), h("div", { key: '5f275e5c3517a6df99e781537ac17135d54b5d9a', class: "s-toggle-switcher" }))))), h("div", { key: '0cb50e709e0dbc49f769b4f107002eadadb41c32', class: "s-user-settings-section" }, h("salla-list-tile", { key: 'f710c59a481aedca13fb36d003ddb5b71905771f' }, h("div", { key: 'b8e81786c8cea4cc36d81ad4e5a53381fea20ed4', slot: "icon", class: "s-user-settings-section-icon" }, h("span", { key: 'b4b3b36769c216f4981fcebec511e33461e703d5', innerHTML: Bullhorn })), h("div", { key: 'a5a9271e04367bbc512656176bf7b9c59855c497', slot: "title", class: "s-user-settings-section-title" }, this.capitalizeText(this.promotionalMsgs)), h("div", { key: 'f7191566d7fea659a0d080f7680ace28f74fc5e1', slot: "subtitle", class: "s-user-settings-section-subtitle" }, this.capitalizeText(this.promotionalMsgsDesc)), h("div", { key: 'edaed3be64edc7e98640d33ae57112e8586e3354', slot: 'action', class: "s-user-settings-section-action" }, h("label", { key: '9a444d833c61719f65200b6a16ce8bf47406b84f', class: "s-toggle" }, h("input", { key: 'bd18d96449c3eb4d6b263bc5cbf7a9b8d639bd6d', class: "s-toggle-input", checked: this.isNotifiable, onChange: (e) => this.toggleSetting('is_notifiable', e), type: "checkbox" }), h("div", { key: '5742974d46ab2e1084f85d3902ead64a4d2340e3', class: "s-toggle-switcher" }))))), h("div", { key: 'cd920209f8188531735c0a12b40f290ffafd31ab', class: "s-user-settings-section s-user-settings-section-deactivate-user" }, h("salla-list-tile", { key: '49ea382b58e36475794f8e80e41caf7db938ddc4' }, h("div", { key: '7cb1d0abc1c178862111e49804cb750ddd01aea3', slot: "icon", class: "s-user-settings-section-icon" }, h("span", { key: 'de51a80143d6b44ec3ad1f6422e769e57432dd9e', innerHTML: UserOff })), h("div", { key: '1a00838952cac6c3fafe29b9e7e32f5ed3126f30', slot: "title", class: "s-user-settings-section-title" }, this.capitalizeText(this.deactivateAccount)), h("div", { key: 'f4b2794e0dd8a036ce404b7243986b7ba5a63340', slot: "subtitle", class: "s-user-settings-section-subtitle" }, this.capitalizeText(this.deactivateDesc)), h("div", { key: '72cb29457621699ed1449cdd52eb5151023637ab', slot: 'action', class: "s-user-settings-section-action" }, h("salla-button", { key: 'aba35845332da5f0da393078e06a0e0498bf2d28', fill: "outline", color: "danger", shape: "btn", size: "medium", width: "normal", onClick: () => this.openDeactivateModal() }, this.capitalizeText(this.deactivateAccount))))), h("salla-modal", { key: '4fd811fbbc6e7fcc1a6a8d23e8bfa05b7499dcbc', width: "sm", subTitle: this.capitalizeText(this.sorryForLeavingText), ref: modal => this.confirmationModal = modal }, h("span", { key: '712fe566292404c42aa79970978f03fb23b4d2ab', slot: 'icon', class: "s-user-settings-confirmation-icon", innerHTML: UserOff }), h("div", { key: '69ce40edbcaf775e33d62a3e242e5fcc9cce3cef', class: "s-user-settings-confirmation" }, h("div", { key: 'f71c23f124449b12ad7db1f523ca3b80b5c50a2b', class: "s-user-settings-confirmation-warning" }, this.capitalizeText(this.warningText)), h("div", { key: '6995699f126fb98cc6271a0f476dd6b4f53cfd3c', class: "s-user-settings-confirmation-actions" }, h("salla-button", { key: 'f45563215e757ee3b172622c346cd40fca1a79a6', width: "wide", onClick: () => this.confirmationModal.close() }, this.capitalizeText(this.keepAccount)), h("salla-button", { key: '1ba83fc0690f0a10176008bb2470759878471cee', fill: 'outline', loading: this.buttonLoading, width: "wide", onClick: () => this.deleteAccount() }, this.capitalizeText(this.deactivateAccount)))))));
}
};
SallaUserSettings.style = sallaUserSettingsCss;
export { SallaUserSettings as salla_user_settings };