diff --git a/ui/ui-kit/src/button/button.ts b/ui/ui-kit/src/button/button.ts index db45f5d71..2f8c8cc68 100644 --- a/ui/ui-kit/src/button/button.ts +++ b/ui/ui-kit/src/button/button.ts @@ -1,10 +1,11 @@ -import {css, customElement, html, property} from '@alwatr/element'; +import {PropertyValues, css, customElement, html, nothing, property} from '@alwatr/element'; +import {message} from '@alwatr/i18n'; import '@alwatr/icon'; import {eventTrigger} from '@alwatr/signal'; import {AlwatrSurface} from '../card/surface.js'; -import type {ClickSignalType, Stringifyable} from '@alwatr/type'; +import type {ClickSignalType, Stringifyable, StringifyableRecord} from '@alwatr/type'; declare global { interface HTMLElementTagNameMap { @@ -12,6 +13,40 @@ declare global { } } +export interface ButtonContent extends StringifyableRecord { + /** + * Label. + */ + label?: string + + /** + * Label i18n key. + */ + labelKey?: string; + + /** + * Icon name. + */ + icon?: string; + + /** + * Flip icon on rtl + */ + flipRtl?: true; + + /** + * Unique name for identify click event over signal. + */ + clickSignalId?: string; + + /** + * Dispatched signal with ClickSignalType and this detail. + */ + clickDetail?: Stringifyable; + + disabled?: boolean; +} + /** * Alwatr outlined text field. * @@ -50,18 +85,16 @@ export class AlwatrButton extends AlwatrSurface { `, ]; - @property() - icon?: string; + @property({type: Object}) + content?: ButtonContent; - @property({attribute: 'click-signal-id'}) - clickSignalId?: string; - - @property({attribute: false}) - detail?: Stringifyable; + protected override firstUpdated(_changedProperties: PropertyValues): void { + super.firstUpdated(_changedProperties); + this.setAttribute('stated', ''); + } override connectedCallback(): void { super.connectedCallback(); - this.setAttribute('stated', ''); this.addEventListener('click', this._click); } @@ -70,30 +103,37 @@ export class AlwatrButton extends AlwatrSurface { this.removeEventListener('click', this._click); } + protected override update(changedProperties: PropertyValues): void { + super.update(changedProperties); + + const disabled = Boolean(this.content?.disabled); + if (this.hasAttribute('disabled') !== disabled) { + this.toggleAttribute('disabled', disabled); + } + } + override render(): unknown { this._logger.logMethod('render'); - if (this.icon) { - return html` - - button - `; - } - else { - return html`button`; - } + const content = this.content || {}; + + return [ + content.icon + ? html`` + : nothing, + html`${content.label ?? message(content.labelKey)}`, + ]; } protected _click(event: MouseEvent): void { - this._logger.logMethodArgs('click', {clickSignalId: this.clickSignalId}); - if (this.clickSignalId) { - eventTrigger.dispatch(this.clickSignalId, { - x: event.clientX, - y: event.clientY, - altKey: event.altKey, - ctrlKey: event.ctrlKey, - metaKey: event.metaKey, - detail: this.detail, - }); - } + if (this.content?.clickSignalId == null) return; + this._logger.logMethodArgs('click', {clickSignalId: this.content.clickSignalId}); + eventTrigger.dispatch(this.content.clickSignalId, { + x: event.clientX, + y: event.clientY, + altKey: event.altKey, + ctrlKey: event.ctrlKey, + metaKey: event.metaKey, + detail: this.content.clickDetail, + }); } } diff --git a/ui/ui-kit/src/button/icon-button.ts b/ui/ui-kit/src/button/icon-button.ts index 384be9d5e..f78a63245 100644 --- a/ui/ui-kit/src/button/icon-button.ts +++ b/ui/ui-kit/src/button/icon-button.ts @@ -76,12 +76,16 @@ export class AlwatrStandardIconButton extends AlwatrSurface { `, ]; - @property({type: Object, attribute: false}) + @property({type: Object}) content?: IconButtonContent; + protected override firstUpdated(_changedProperties: PropertyValues): void { + super.firstUpdated(_changedProperties); + this.setAttribute('stated', ''); + } + override connectedCallback(): void { super.connectedCallback(); - this.setAttribute('stated', ''); this.addEventListener('click', this._click); } @@ -90,20 +94,20 @@ export class AlwatrStandardIconButton extends AlwatrSurface { this.removeEventListener('click', this._click); } - protected override shouldUpdate(changedProperties: PropertyValues): boolean { - return super.shouldUpdate(changedProperties) && this.content != null; - } - - override render(): unknown { - this._logger.logMethod('render'); - if (this.content == null) return; + protected override update(changedProperties: PropertyValues): void { + super.update(changedProperties); - const disabled = Boolean(this.content.disabled); + const disabled = Boolean(this.content?.disabled); if (this.hasAttribute('disabled') !== disabled) { this.toggleAttribute('disabled', disabled); } + } + + override render(): unknown { + this._logger.logMethod('render'); + const content = this.content || {icon: ''}; - return html``; + return html``; } protected _click(event: MouseEvent): void { diff --git a/ui/ui-kit/src/snackbar/element.ts b/ui/ui-kit/src/snackbar/element.ts index 95fd88396..5261a856a 100644 --- a/ui/ui-kit/src/snackbar/element.ts +++ b/ui/ui-kit/src/snackbar/element.ts @@ -121,7 +121,11 @@ export class AlwatrSnackbar extends AlwatrSurface { this._logger.logMethod('render'); return html`${this.message}${when( this.actionLabel, - () => html`${this.actionLabel}`, + () => + html``, )}`; } diff --git a/uniquely/com-pwa/src/manager/buttons.ts b/uniquely/com-pwa/src/manager/buttons.ts index b74b31b10..7e4904d4a 100644 --- a/uniquely/com-pwa/src/manager/buttons.ts +++ b/uniquely/com-pwa/src/manager/buttons.ts @@ -15,9 +15,18 @@ export const buttons = { flipRtl: true, clickSignalId: 'browser_back_click_event', }, + print: { + icon: 'print-outline', + clickSignalId: 'order_detail_print', + }, + + reload: { + icon: 'reload-outline', + }, reloadOrderStorage: { icon: 'reload-outline', + flipRtl: true, clickSignalId: 'reload_order_storage', }, @@ -26,16 +35,79 @@ export const buttons = { clickSignalId: 'new_order_click_event', }, showOrderDetail: { + labelKey: 'page_new_order_detail_button', + icon: 'information-outline', clickSignalId: 'show_order_detail_click_event', }, + backToOrderList: { + icon: 'arrow-back-outline', + flipRtl: true, + clickSignalId: 'back_to_order_list_event', + }, + + editItems: { + labelKey: 'page_new_order_edit_items', + icon: 'create-outline', + clickSignalId: 'edit_items_click_event', + }, + submit: { + labelKey: 'page_new_order_submit', + icon: 'checkmark-outline', + clickSignalId: 'submit_click_event', + }, + selectProductSubmit: { + labelKey: 'select_product_submit_button', + icon: 'checkmark-outline', + clickSignalId: 'select_product_submit_click_event', + }, + editOrder: { + labelKey: 'page_new_order_edit', + icon: 'create-outline', + clickSignalId: 'edit_order_click_event', + }, + submitFinal: { + labelKey: 'page_new_order_submit_final', + icon: 'checkmark-outline', + clickSignalId: 'submit_final_click_event', + }, + submitShippingForm: { + labelKey: 'page_new_order_shipping_submit', + icon: 'checkmark-outline', + clickSignalId: 'submit_shipping_form_click_event', + }, + editShippingForm: { + labelKey: 'page_new_order_shipping_edit', + icon: 'create-outline', + clickSignalId: 'edit_shipping_form_click_event', + }, + showRegisteredOrderDetail: { + labelKey: 'page_new_order_detail_button', + icon: 'information-outline', + clickSignalId: 'show_registered_order_detail_click_event', + }, + showRegisteredOrderTracking: { + icon: 'chatbox-outline', + clickSignalId: 'show_registered_order_tracking_click_event', + }, + retry: { + labelKey: 'page_new_order_retry_button', + icon: 'reload-outline', + clickSignalId: 'retry_click_event', + }, } as const; -eventListener.subscribe('new_order_click_event', () => { - redirect({ - sectionList: ['new-order'], - }); +eventListener.subscribe(buttons.newOrder.clickSignalId, () => { + redirect({sectionList: ['new-order']}); +}); + +eventListener.subscribe(buttons.print.clickSignalId, () => { + window.print(); }); -eventListener.subscribe('show_order_detail_click_event', (event: ClickSignalType): void => { +eventListener.subscribe(buttons.showOrderDetail.clickSignalId, (event: ClickSignalType): void => { redirect({sectionList: ['order-detail', event.detail.id]}); }); + +eventListener.subscribe(buttons.backToOrderList.clickSignalId, (): void => { + redirect({sectionList: ['order-list']}); +}); diff --git a/uniquely/com-pwa/src/ui/page/new-order.ts b/uniquely/com-pwa/src/ui/page/new-order.ts index d058dcb71..9fcff30d2 100644 --- a/uniquely/com-pwa/src/ui/page/new-order.ts +++ b/uniquely/com-pwa/src/ui/page/new-order.ts @@ -5,6 +5,7 @@ import {redirect} from '@alwatr/router'; import '@alwatr/ui-kit/card/icon-box.js'; +import {buttons} from '../../manager/buttons.js'; import {scrollToTopCommand, topAppBarContextProvider} from '../../manager/context.js'; import {AlwatrOrderDetailBase} from '../stuff/order-detail-base.js'; import '../stuff/select-product.js'; @@ -13,76 +14,12 @@ import type {NewOrderFsm} from '../../manager/controller/new-order.js'; import type {Order, OrderShippingInfo} from '@alwatr/type/customer-order-management.js'; import type {IconBoxContent} from '@alwatr/ui-kit/card/icon-box.js'; - declare global { interface HTMLElementTagNameMap { 'alwatr-page-new-order': AlwatrPageNewOrder; } } -const buttons = { - back: { - icon: 'arrow-back-outline', - flipRtl: true, - clickSignalId: 'page_new_order_back_click_event', - }, - backToHome: { - icon: 'arrow-back-outline', - flipRtl: true, - clickSignalId: 'back_to_home_click_event', - }, - editItems: { - icon: 'create-outline', - clickSignalId: 'page_new_order_edit_items_click_event', - }, - submit: { - icon: 'checkmark-outline', - clickSignalId: 'page_new_order_submit_click_event', - }, - edit: { - icon: 'create-outline', - clickSignalId: 'page_new_order_edit_click_event', - }, - submitFinal: { - icon: 'checkmark-outline', - clickSignalId: 'page_new_order_submit_final_click_event', - }, - submitShippingForm: { - icon: 'checkmark-outline', - clickSignalId: 'page_new_order_submit_shipping_form_click_event', - }, - editShippingForm: { - icon: 'checkmark-outline', - clickSignalId: 'page_new_order_edit_shipping_form_click_event', - }, - newOrder: { - icon: 'add-outline', - clickSignalId: 'page_new_order_new_order_click_event', - }, - detail: { - icon: 'information-outline', - clickSignalId: 'page_new_order_detail_click_event', - }, - tracking: { - icon: 'chatbox-outline', - clickSignalId: 'page_new_order_tracking_click_event', - }, - reload: { - icon: 'reload-outline', - // flipRtl: true, - clickSignalId: 'order_list_reload_click_event', - }, - retry: { - icon: 'reload-outline', - clickSignalId: 'page_new_order_retry_click_event', - }, - backToOrderList: { - icon: 'arrow-back-outline', - flipRtl: true, - clickSignalId: 'order_detail_back_to_order_list_event', - }, -} as const; - /** * Alwatr Customer Order Management Order Form Page */ @@ -125,7 +62,11 @@ export class AlwatrPageNewOrder extends UnresolvedMixin(AlwatrOrderDetailBase) { transition: 'submit', }, { - signalId: buttons.edit.clickSignalId, + signalId: buttons.selectProductSubmit.clickSignalId, + transition: 'submit', + }, + { + signalId: buttons.editOrder.clickSignalId, transition: 'back', }, { @@ -145,7 +86,7 @@ export class AlwatrPageNewOrder extends UnresolvedMixin(AlwatrOrderDetailBase) { transition: 'edit_shipping', }, { - signalId: buttons.detail.clickSignalId, + signalId: buttons.showRegisteredOrderDetail.clickSignalId, callback: (): void => { redirect({sectionList: ['order-detail', this.fsm.getContext().orderId ?? '']}); }, @@ -202,7 +143,7 @@ export class AlwatrPageNewOrder extends UnresolvedMixin(AlwatrOrderDetailBase) { topAppBarContextProvider.setValue({ headlineKey: 'page_order_list_headline', startIcon: buttons.backToOrderList, - endIconList: [buttons.reload], + endIconList: [buttons.print, buttons.reload], }); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const order = this.fsm.getContext().orderStorage!.data[this.fsm.getContext().orderId]; @@ -223,30 +164,19 @@ export class AlwatrPageNewOrder extends UnresolvedMixin(AlwatrOrderDetailBase) { this.render_part_item_list(order.itemList ?? [], this.fsm.getContext().productStorage, true), html`
- - ${message('page_new_order_edit_items')} - +
`, this.render_part_shipping_info(order.shippingInfo), html`
- - ${message('page_new_order_shipping_edit')} - +
`, this.render_part_summary(order), html`
- ${message('page_new_order_submit')} - +
`, ]; @@ -287,12 +217,7 @@ export class AlwatrPageNewOrder extends UnresolvedMixin(AlwatrOrderDetailBase) { >`, html`
- ${message('select_product_submit_button')} - +
`, ]; @@ -305,10 +230,7 @@ export class AlwatrPageNewOrder extends UnresolvedMixin(AlwatrOrderDetailBase) { this.render_part_shipping_form(order.shippingInfo as Partial), html`
- ${message('page_new_order_shipping_submit')} +
`, ]; @@ -323,12 +245,8 @@ export class AlwatrPageNewOrder extends UnresolvedMixin(AlwatrOrderDetailBase) { this.render_part_summary(order), html`
- - ${message('page_new_order_edit')} - - - ${message('page_new_order_submit_final')} - + +
`, ]; @@ -353,12 +271,8 @@ export class AlwatrPageNewOrder extends UnresolvedMixin(AlwatrOrderDetailBase) { html``, html`
- - ${message('page_new_order_detail_button')} - - - ${message('page_new_order_headline')} - + + ${message('page_new_order_headline')}
`, ]; @@ -374,9 +288,7 @@ export class AlwatrPageNewOrder extends UnresolvedMixin(AlwatrOrderDetailBase) { html``, html`
- - ${message('page_new_order_retry_button')} - +
`, ]; diff --git a/uniquely/com-pwa/src/ui/page/order-detail.ts b/uniquely/com-pwa/src/ui/page/order-detail.ts index 74457f3b6..0f1afbc4e 100644 --- a/uniquely/com-pwa/src/ui/page/order-detail.ts +++ b/uniquely/com-pwa/src/ui/page/order-detail.ts @@ -2,8 +2,8 @@ import {customElement, html, property, state, UnresolvedMixin} from '@alwatr/ele import {finiteStateMachineConsumer} from '@alwatr/fsm'; import {message} from '@alwatr/i18n'; import {topAppBarContextProvider} from '@alwatr/pwa-helper/context.js'; -import {redirect} from '@alwatr/router'; +import {buttons} from '../../manager/buttons.js'; import {OrderDetailFsm} from '../../manager/controller/order-detail.js'; import {AlwatrOrderDetailBase} from '../stuff/order-detail-base.js'; @@ -15,19 +15,6 @@ declare global { } } -const buttons = { - backToOrderList: { - icon: 'arrow-back-outline', - flipRtl: true, - clickSignalId: 'order_detail_back_to_order_list_event', - }, - reload: { - icon: 'reload-outline', - flipRtl: true, - clickSignalId: 'order_detail_reload_event', - }, -} as const; - /** * Alwatr Customer Order Management Order Detail Page. */ @@ -60,8 +47,8 @@ export class AlwatrPageOrderDetail extends UnresolvedMixin(AlwatrOrderDetailBase receivePrevious: 'NextCycle', }, { - signalId: buttons.backToOrderList.clickSignalId, - callback: (): void => redirect({sectionList: ['order-list']}), + signalId: buttons.reloadOrderStorage.clickSignalId, + transition: 'context_request_complete', // FIXME: set correct transition for reloading }, ])); } @@ -74,7 +61,7 @@ export class AlwatrPageOrderDetail extends UnresolvedMixin(AlwatrOrderDetailBase topAppBarContextProvider.setValue({ headlineKey: 'page_order_list_headline', startIcon: buttons.backToOrderList, - endIconList: [buttons.reload], + endIconList: [buttons.reloadOrderStorage], }); const content: IconBoxContent = { @@ -89,7 +76,7 @@ export class AlwatrPageOrderDetail extends UnresolvedMixin(AlwatrOrderDetailBase topAppBarContextProvider.setValue({ headlineKey: 'page_order_list_headline', startIcon: buttons.backToOrderList, - endIconList: [buttons.reload], + endIconList: [buttons.reloadOrderStorage], }); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const order = this.fsm.getContext().orderStorage!.data[this.fsm.getContext().orderId!]; diff --git a/uniquely/com-pwa/src/ui/page/order-list.ts b/uniquely/com-pwa/src/ui/page/order-list.ts index 5cb90588b..6081b37cd 100644 --- a/uniquely/com-pwa/src/ui/page/order-list.ts +++ b/uniquely/com-pwa/src/ui/page/order-list.ts @@ -112,12 +112,7 @@ export class AlwatrPageOrderList extends ScheduleUpdateToFrameMixin( }; return html` - - ${message('retry')} - + `; }, diff --git a/uniquely/soffit-pwa/src/ui/stuff/lottery-form.ts b/uniquely/soffit-pwa/src/ui/stuff/lottery-form.ts index 2eaface3e..c51f94a45 100644 --- a/uniquely/soffit-pwa/src/ui/stuff/lottery-form.ts +++ b/uniquely/soffit-pwa/src/ui/stuff/lottery-form.ts @@ -151,13 +151,8 @@ export class AlwatrLotteryForm extends LocalizeMixin(SignalMixin(AlwatrBaseEleme protected partButtonTemplate(): unknown { return html`
- ${message('submit_form')} - - ${message('cancel')} + +
`; }