Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(com-pwa): reported issue for admin page #1205

Merged
merged 3 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions uniquely/com-pwa/src/manager/buttons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ export const buttons = {
flipRtl: true,
clickSignalId: 'back_to_order_list_event',
},
backToAdminOrderList: {
icon: 'arrow-back-outline',
flipRtl: true,
clickSignalId: 'back_to_admin_order_list_event',
},

editItems: {
labelKey: 'page_order_edit_items',
Expand Down
64 changes: 53 additions & 11 deletions uniquely/com-pwa/src/ui/page/admin-order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import '@alwatr/icon';
import {calcDiscount} from '@alwatr/math';
import {redirect} from '@alwatr/router';
import {eventListener} from '@alwatr/signal';
import '@alwatr/ui-kit/button/button.js';
import '@alwatr/ui-kit/card/icon-box.js';
import '@alwatr/ui-kit/card/surface.js';

Expand Down Expand Up @@ -166,13 +167,40 @@ export class AlwatrPageAdminOrder extends UnresolvedMixin(LocalizeMixin(SignalMi
override connectedCallback(): void {
super.connectedCallback();

this._addSignalListeners(eventListener.subscribe(buttons.backToOrderList.clickSignalId, (): void => {
this._addSignalListeners(userListIncOrderStorageContextConsumer.subscribe(() => {
this.gotState = userListIncOrderStorageContextConsumer.getState().target;
}, {receivePrevious: 'NextCycle'}));

this._addSignalListeners(productStorageContextConsumer.subscribe(() => {
if (productStorageContextConsumer.getState().target === 'complete') {
this.requestUpdate();
}
}, {receivePrevious: 'NextCycle'}));

this._addSignalListeners(eventListener.subscribe(buttons.backToAdminOrderList.clickSignalId, () => {
redirect({sectionList: ['admin-order-list']});
}));

this._addSignalListeners(eventListener.subscribe(buttons.retry.clickSignalId, () => {
if (userListIncOrderStorageContextConsumer.getState().target !== 'complete') {
userListIncOrderStorageContextConsumer.request();
}
if (productStorageContextConsumer.getState().target !== 'complete') {
productStorageContextConsumer.request();
}
}));

this._addSignalListeners(eventListener.subscribe(buttons.reloadAdminOrderListStorage.clickSignalId, () => {
userListIncOrderStorageContextConsumer.request();
productStorageContextConsumer.request();
}));
}

protected override update(changedProperties: PropertyValues<this>): void {
super.update(changedProperties);
if (changedProperties.has('gotState')) {
this.setAttribute('state', this.gotState);
}
if (changedProperties.has('orderId')) {
scrollToTopCommand.request({smooth: true});
}
Expand All @@ -196,7 +224,8 @@ export class AlwatrPageAdminOrder extends UnresolvedMixin(LocalizeMixin(SignalMi

topAppBarContextProvider.setValue({
headlineKey: 'loading',
startIcon: buttons.backToHome,
startIcon: buttons.backToAdminOrderList,
endIconList: [buttons.reloadAdminOrderListStorage],
});
const content: IconBoxContent = {
tinted: 1,
Expand All @@ -211,8 +240,8 @@ export class AlwatrPageAdminOrder extends UnresolvedMixin(LocalizeMixin(SignalMi

topAppBarContextProvider.setValue({
headlineKey: 'page_order_list_headline',
startIcon: buttons.backToHome,
endIconList: [buttons.reloadOrderStorage],
startIcon: buttons.backToAdminOrderList,
endIconList: [buttons.reloadAdminOrderListStorage],
});
const content: IconBoxContent = {
icon: 'cloud-offline-outline',
Expand All @@ -221,15 +250,21 @@ export class AlwatrPageAdminOrder extends UnresolvedMixin(LocalizeMixin(SignalMi
description: message('fetch_failed_description'),
};

return html`<alwatr-icon-box .content=${content}></alwatr-icon-box>`;
return html`
<alwatr-icon-box .content=${content}></alwatr-icon-box>
<div>
<alwatr-button .content=${buttons.retry}></alwatr-button>
</div>
`;
}

protected _render_notFound(): unknown {
this._logger.logMethod?.('_render_notFound');

topAppBarContextProvider.setValue({
headlineKey: 'page_order_list_headline',
startIcon: buttons.backToOrderList,
startIcon: buttons.backToAdminOrderList,
endIconList: [buttons.reloadAdminOrderListStorage],
});
const content: IconBoxContent = {
headline: message('page_order_detail_not_found'),
Expand All @@ -244,20 +279,27 @@ export class AlwatrPageAdminOrder extends UnresolvedMixin(LocalizeMixin(SignalMi

topAppBarContextProvider.setValue({
headlineKey: 'page_order_list_headline',
startIcon: buttons.backToOrderList,
startIcon: buttons.backToAdminOrderList,
endIconList: [buttons.reloadAdminOrderListStorage],
});

const productStorage = productStorageContextConsumer.getResponse();

if (this.userId == null || this.orderId == null || productStorage == null) {
if (this.userId == null || this.orderId == null) {
return this._render_notFound();
}

const order = userListIncOrderStorageContextConsumer.getResponse()?.data[this.userId]?.orderList[this.orderId];
if (order == null) {
return this._render_notFound();
}

const productStorageStateTarget = productStorageContextConsumer.getState().target;
if (productStorageStateTarget === 'reloadingFailed') {
return this._renderStateLoadingFailed();
}
else if (productStorageStateTarget !== 'complete' && productStorageStateTarget !== 'reloading') {
return this._renderStateLoading();
}
const productStorage = productStorageContextConsumer.getResponse();

return [
this._render_status(order),
this._render_itemList(order.itemList, productStorage),
Expand Down