diff --git a/core/type/src/customer-order-management.ts b/core/type/src/customer-order-management.ts index b556506fb..c9725b174 100644 --- a/core/type/src/customer-order-management.ts +++ b/core/type/src/customer-order-management.ts @@ -144,7 +144,7 @@ export interface OrderShippingInfo extends StringifyableRecord { // -- Schema -- -export const orderLadingSchema = { +export const orderShippingInfoSchema = { recipientName: String, recipientNationalCode: String, address: String, diff --git a/uniquely/com-pwa/src/content/l18e-fa.json b/uniquely/com-pwa/src/content/l18e-fa.json index 950a9c0d1..6ad0b5085 100644 --- a/uniquely/com-pwa/src/content/l18e-fa.json +++ b/uniquely/com-pwa/src/content/l18e-fa.json @@ -53,6 +53,8 @@ "order_status_canceled": "لغو شده", "order_status_refunded": "بازپرداخت", + "order_shipping_info_empty_description": "ندارد.", + "order_shipping_address_title": "آدرس تحویل", "order_shipping_recipient_name_title": "نام تحویل گیرنده", "order_shipping_recipient_national_code_title": "کد ملی تحویل گیرنده", diff --git a/uniquely/com-pwa/src/ui/page/new-order.ts b/uniquely/com-pwa/src/ui/page/new-order.ts index 94093ec12..91f5a64c7 100644 --- a/uniquely/com-pwa/src/ui/page/new-order.ts +++ b/uniquely/com-pwa/src/ui/page/new-order.ts @@ -5,7 +5,9 @@ import { UnresolvedMixin, } from '@alwatr/element'; import {message} from '@alwatr/i18n'; +import {orderShippingInfoSchema} from '@alwatr/type/src/customer-order-management.js'; import {IconBoxContent} from '@alwatr/ui-kit/src/card/icon-box.js'; +import {validator} from '@alwatr/validator'; import {buttons, pageNewOrderStateMachine} from '../../manager/controller/new-order.js'; import {AlwatrOrderDetailBase} from '../stuff/order-detail-base.js'; @@ -74,7 +76,6 @@ export class AlwatrPageNewOrder extends StateMachineMixin( protected render_state_shippingForm(): unknown { this._logger.logMethod('render_state_shippingForm'); const order = this.stateMachine.context.order; - // order.shippingInfo ??= getLocalStorageItem('shipping_form_data_x1', {}); order.shippingInfo ??= {}; return [ this.render_part_item_list(order.itemList ?? [], this.stateMachine.context.productStorage, false), @@ -147,7 +148,8 @@ export class AlwatrPageNewOrder extends StateMachineMixin( ${message('page_new_order_submit')} `; @@ -189,4 +191,23 @@ export class AlwatrPageNewOrder extends StateMachineMixin( `; } + + protected isSubmitAble(): boolean { + this._logger.logMethod('isSubmitAble'); + const shippingInfo = pageNewOrderStateMachine.context.order.shippingInfo; + if ( + pageNewOrderStateMachine.context.order.itemList?.length === 0 || + shippingInfo == null + ) return false; + + try { + validator(orderShippingInfoSchema, shippingInfo, true); + } + catch (err) { + this._logger.error('isSubmitAble', (err as Error).message, {err}); + return false; + } + + return true; + } }