Skip to content

Commit

Permalink
Feat/shipping info (#1103)
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd authored May 1, 2023
2 parents 500616a + 52e37e7 commit 4021e95
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
3 changes: 0 additions & 3 deletions uniquely/com-pwa/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import {FetchOptions} from '@alwatr/fetch';
import {getConfKey} from '@alwatr/pwa-helper/config.js';

const token = getConfKey<string>('token');
export const config = {
api: getConfKey<string>('api'),
cdn: getConfKey<string>('cdn'),
token,
productStorageList: getConfKey<Array<string>>('productStorageList'),
priceListName: '${productStorage}-market-ir',
finalPriceListName: '${productStorage}-agency-ir',
fetchContextOptions: <Partial<FetchOptions>> {
method: 'GET',
token,
removeDuplicate: 'auto',
retry: 2,
retryDelay: 2_000,
Expand Down
2 changes: 1 addition & 1 deletion uniquely/com-pwa/src/manager/context-provider/sign-in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {contextProvider, serverContextConsumer} from '@alwatr/context';
import {message} from '@alwatr/i18n';
import {simpleHashNumber} from '@alwatr/math';
import {redirect} from '@alwatr/router';
import {snackbarSignalTrigger} from '@alwatr/ui-kit/src/snackbar/show-snackbar.js';
import {snackbarSignalTrigger} from '@alwatr/ui-kit/snackbar/show-snackbar.js';

import {linkPassTokenContextConsumer, userProfileContextConsumer, userTokenContextConsumer} from './user.js';
import {config} from '../../config.js';
Expand Down
19 changes: 18 additions & 1 deletion uniquely/com-pwa/src/manager/controller/order.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {FsmTypeHelper, finiteStateMachineProvider} from '@alwatr/fsm';
import {message} from '@alwatr/i18n';
import {OrderDraft, OrderItem, orderInfoSchema, tileQtyStep} from '@alwatr/type/customer-order-management.js';
import {orderInfoSchema, orderShippingInfoSchema, tileQtyStep} from '@alwatr/type/customer-order-management.js';
import {snackbarSignalTrigger} from '@alwatr/ui-kit/snackbar/show-snackbar.js';
import {getLocalStorageItem, setLocalStorageItem} from '@alwatr/util';
import {validator} from '@alwatr/validator';
Expand All @@ -14,6 +14,7 @@ import {productStorageContextConsumer} from '../context-provider/product-storage
import {submitOrderCommandTrigger} from '../context.js';

import type {ClickSignalType} from '@alwatr/type';
import type {OrderDraft, OrderItem} from '@alwatr/type/customer-order-management.js';

const newOrderLocalStorageKey = 'draft_order_x4';

Expand Down Expand Up @@ -124,6 +125,7 @@ export const orderFsmConstructor = finiteStateMachineProvider.defineConstructor(
on: {
submit: {
target: 'newOrder',
condition: 'validate_shipping_info',
},
},
},
Expand Down Expand Up @@ -263,6 +265,21 @@ finiteStateMachineProvider.defineActions<OrderFsm>('order_fsm', {
}
},

validate_shipping_info: (fsmInstance): boolean => {
try {
const order = fsmInstance.getContext().newOrder;
// else
fsmInstance.getContext().newOrder.shippingInfo = validator(orderShippingInfoSchema, order.shippingInfo, true);
return true;
}
catch (err) {
snackbarSignalTrigger.request({
message: message('page_order_shipping_info_not_valid_message'),
});
return false;
}
},

is_all_context_ready: (): boolean => {
return serverContextList.every((serverContext) => serverContext.getResponse() != null);
},
Expand Down

0 comments on commit 4021e95

Please sign in to comment.