@faststore/core 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@generated/graphql/index.ts +221 -0
- package/@generated/graphql/persisted.json +2 -1
- package/CHANGELOG.md +7 -0
- package/bun.lockb +0 -0
- package/package.json +2 -2
- package/src/components/sections/ProductDetails/ProductDetails.tsx +11 -6
- package/src/components/ui/ShippingSimulation/ShippingSimulation.tsx +15 -7
- package/src/components/ui/ShippingSimulation/useShippingSimulation.ts +58 -56
- package/src/sdk/shipping/index.ts +54 -0
|
@@ -82,6 +82,43 @@ export type Scalars = {
|
|
|
82
82
|
VariantsByName: any
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
/** Address information. */
|
|
86
|
+
export type Address = {
|
|
87
|
+
/** Address city */
|
|
88
|
+
city: Maybe<Scalars['String']>
|
|
89
|
+
/** Address complement */
|
|
90
|
+
complement: Maybe<Scalars['String']>
|
|
91
|
+
/** Address country */
|
|
92
|
+
country: Maybe<Scalars['String']>
|
|
93
|
+
/** Address geoCoordinates */
|
|
94
|
+
geoCoordinates: Maybe<Array<Maybe<Scalars['Float']>>>
|
|
95
|
+
/** Address neighborhood */
|
|
96
|
+
neighborhood: Maybe<Scalars['String']>
|
|
97
|
+
/** Address number */
|
|
98
|
+
number: Maybe<Scalars['String']>
|
|
99
|
+
/** Address postal code */
|
|
100
|
+
postalCode: Maybe<Scalars['String']>
|
|
101
|
+
/** Address reference */
|
|
102
|
+
reference: Maybe<Scalars['String']>
|
|
103
|
+
/** Address state */
|
|
104
|
+
state: Maybe<Scalars['String']>
|
|
105
|
+
/** Address street */
|
|
106
|
+
street: Maybe<Scalars['String']>
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export type DeliveryIds = {
|
|
110
|
+
/** DeliveryIds courier id */
|
|
111
|
+
courierId: Maybe<Scalars['String']>
|
|
112
|
+
/** DeliveryIds courier name */
|
|
113
|
+
courierName: Maybe<Scalars['String']>
|
|
114
|
+
/** DeliveryIds dock id */
|
|
115
|
+
dockId: Maybe<Scalars['String']>
|
|
116
|
+
/** DeliveryIds quantity */
|
|
117
|
+
quantity: Maybe<Scalars['Int']>
|
|
118
|
+
/** DeliveryIds warehouse id */
|
|
119
|
+
warehouseId: Maybe<Scalars['String']>
|
|
120
|
+
}
|
|
121
|
+
|
|
85
122
|
/** Person data input to the newsletter. */
|
|
86
123
|
export type IPersonNewsletter = {
|
|
87
124
|
/** Person's email. */
|
|
@@ -90,6 +127,16 @@ export type IPersonNewsletter = {
|
|
|
90
127
|
name: Scalars['String']
|
|
91
128
|
}
|
|
92
129
|
|
|
130
|
+
/** Shipping Simulation item input. */
|
|
131
|
+
export type IShippingItem = {
|
|
132
|
+
/** ShippingItem ID / Sku. */
|
|
133
|
+
id: Scalars['String']
|
|
134
|
+
/** Number of items. */
|
|
135
|
+
quantity: Scalars['Int']
|
|
136
|
+
/** Seller responsible for the ShippingItem. */
|
|
137
|
+
seller: Scalars['String']
|
|
138
|
+
}
|
|
139
|
+
|
|
93
140
|
/** Shopping cart input. */
|
|
94
141
|
export type IStoreCart = {
|
|
95
142
|
/** Order information, including `orderNumber` and `acceptedOffer`. */
|
|
@@ -198,6 +245,66 @@ export type IStoreSession = {
|
|
|
198
245
|
postalCode: InputMaybe<Scalars['String']>
|
|
199
246
|
}
|
|
200
247
|
|
|
248
|
+
export type LogisticsInfo = {
|
|
249
|
+
/** LogisticsInfo itemIndex. */
|
|
250
|
+
itemIndex: Maybe<Scalars['String']>
|
|
251
|
+
/** LogisticsInfo selectedSla. */
|
|
252
|
+
selectedSla: Maybe<Scalars['String']>
|
|
253
|
+
/** List of LogisticsInfo ShippingSLA. */
|
|
254
|
+
slas: Maybe<Array<Maybe<ShippingSla>>>
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** Shipping Simulation Logistic Item. */
|
|
258
|
+
export type LogisticsItem = {
|
|
259
|
+
/** LogisticsItem availability. */
|
|
260
|
+
availability: Maybe<Scalars['String']>
|
|
261
|
+
/** LogisticsItem ID / Sku. */
|
|
262
|
+
id: Maybe<Scalars['String']>
|
|
263
|
+
/** LogisticsItem listPrice. */
|
|
264
|
+
listPrice: Maybe<Scalars['Int']>
|
|
265
|
+
/** LogisticsItem measurementUnit. */
|
|
266
|
+
measurementUnit: Maybe<Scalars['String']>
|
|
267
|
+
/** LogisticsItem price. */
|
|
268
|
+
price: Maybe<Scalars['Int']>
|
|
269
|
+
/** Next date in which price is scheduled to change. If there is no scheduled change, this will be set a year in the future from current time. */
|
|
270
|
+
priceValidUntil: Maybe<Scalars['String']>
|
|
271
|
+
/** Number of items. */
|
|
272
|
+
quantity: Maybe<Scalars['Int']>
|
|
273
|
+
requestIndex: Maybe<Scalars['Int']>
|
|
274
|
+
/** LogisticsItem rewardValue. */
|
|
275
|
+
rewardValue: Maybe<Scalars['Int']>
|
|
276
|
+
/** Seller responsible for the ShippingItem. */
|
|
277
|
+
seller: Maybe<Scalars['String']>
|
|
278
|
+
/** List of Sellers. */
|
|
279
|
+
sellerChain: Maybe<Array<Maybe<Scalars['String']>>>
|
|
280
|
+
/** LogisticsItem sellingPrice. */
|
|
281
|
+
sellingPrice: Maybe<Scalars['Int']>
|
|
282
|
+
/** LogisticsItem tax. */
|
|
283
|
+
tax: Maybe<Scalars['Int']>
|
|
284
|
+
/** LogisticsItem unitMultiplier. */
|
|
285
|
+
unitMultiplier: Maybe<Scalars['Int']>
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export type MessageFields = {
|
|
289
|
+
/** MessageFields ean. */
|
|
290
|
+
ean: Maybe<Scalars['String']>
|
|
291
|
+
/** MessageFields item index. */
|
|
292
|
+
itemIndex: Maybe<Scalars['String']>
|
|
293
|
+
/** MessageFields sku name. */
|
|
294
|
+
skuName: Maybe<Scalars['String']>
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export type MessageInfo = {
|
|
298
|
+
/** MessageInfo code. */
|
|
299
|
+
code: Maybe<Scalars['String']>
|
|
300
|
+
/** MessageInfo fields. */
|
|
301
|
+
fields: Maybe<MessageFields>
|
|
302
|
+
/** MessageInfo status. */
|
|
303
|
+
status: Maybe<Scalars['String']>
|
|
304
|
+
/** MessageInfo text. */
|
|
305
|
+
text: Maybe<Scalars['String']>
|
|
306
|
+
}
|
|
307
|
+
|
|
201
308
|
export type Mutation = {
|
|
202
309
|
/** Subscribes a new person to the newsletter list. */
|
|
203
310
|
subscribeToNewsletter: Maybe<PersonNewsletter>
|
|
@@ -227,6 +334,48 @@ export type PersonNewsletter = {
|
|
|
227
334
|
id: Scalars['String']
|
|
228
335
|
}
|
|
229
336
|
|
|
337
|
+
export type PickupAddress = {
|
|
338
|
+
/** PickupAddress address id. */
|
|
339
|
+
addressId: Maybe<Scalars['String']>
|
|
340
|
+
/** PickupAddress address type. */
|
|
341
|
+
addressType: Maybe<Scalars['String']>
|
|
342
|
+
/** PickupAddress city. */
|
|
343
|
+
city: Maybe<Scalars['String']>
|
|
344
|
+
/** PickupAddress complement. */
|
|
345
|
+
complement: Maybe<Scalars['String']>
|
|
346
|
+
/** PickupAddress country. */
|
|
347
|
+
country: Maybe<Scalars['String']>
|
|
348
|
+
/** PickupAddress geo coordinates. */
|
|
349
|
+
geoCoordinates: Maybe<Array<Maybe<Scalars['Float']>>>
|
|
350
|
+
/** PickupAddress neighborhood. */
|
|
351
|
+
neighborhood: Maybe<Scalars['String']>
|
|
352
|
+
/** PickupAddress number. */
|
|
353
|
+
number: Maybe<Scalars['String']>
|
|
354
|
+
/** PickupAddress postal code. */
|
|
355
|
+
postalCode: Maybe<Scalars['String']>
|
|
356
|
+
/** PickupAddress receiver name. */
|
|
357
|
+
receiverName: Maybe<Scalars['String']>
|
|
358
|
+
/** PickupAddress reference. */
|
|
359
|
+
reference: Maybe<Scalars['String']>
|
|
360
|
+
/** PickupAddress state. */
|
|
361
|
+
state: Maybe<Scalars['String']>
|
|
362
|
+
/** PickupAddress street. */
|
|
363
|
+
street: Maybe<Scalars['String']>
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export type PickupStoreInfo = {
|
|
367
|
+
/** PickupStoreInfo additional information. */
|
|
368
|
+
additionalInfo: Maybe<Scalars['String']>
|
|
369
|
+
/** PickupStoreInfo address. */
|
|
370
|
+
address: Maybe<PickupAddress>
|
|
371
|
+
/** PickupStoreInfo dock id. */
|
|
372
|
+
dockId: Maybe<Scalars['String']>
|
|
373
|
+
/** PickupStoreInfo friendly name. */
|
|
374
|
+
friendlyName: Maybe<Scalars['String']>
|
|
375
|
+
/** Information if the store has pickup enable. */
|
|
376
|
+
isPickupStore: Maybe<Scalars['Boolean']>
|
|
377
|
+
}
|
|
378
|
+
|
|
230
379
|
export type Query = {
|
|
231
380
|
/** Returns information about all collections. */
|
|
232
381
|
allCollections: StoreCollectionConnection
|
|
@@ -238,6 +387,8 @@ export type Query = {
|
|
|
238
387
|
product: StoreProduct
|
|
239
388
|
/** Returns the result of a product, facet, or suggestion search. */
|
|
240
389
|
search: StoreSearchResult
|
|
390
|
+
/** Returns information about shipping simulation. */
|
|
391
|
+
shipping: Maybe<ShippingData>
|
|
241
392
|
}
|
|
242
393
|
|
|
243
394
|
export type QueryAllCollectionsArgs = {
|
|
@@ -266,6 +417,56 @@ export type QuerySearchArgs = {
|
|
|
266
417
|
term?: InputMaybe<Scalars['String']>
|
|
267
418
|
}
|
|
268
419
|
|
|
420
|
+
export type QueryShippingArgs = {
|
|
421
|
+
country: Scalars['String']
|
|
422
|
+
items: Array<IShippingItem>
|
|
423
|
+
postalCode: Scalars['String']
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/** Shipping Simulation information. */
|
|
427
|
+
export type ShippingData = {
|
|
428
|
+
/** Address information. */
|
|
429
|
+
address: Maybe<Address>
|
|
430
|
+
/** List of LogisticsItem. */
|
|
431
|
+
items: Maybe<Array<Maybe<LogisticsItem>>>
|
|
432
|
+
/** List of LogisticsInfo. */
|
|
433
|
+
logisticsInfo: Maybe<Array<Maybe<LogisticsInfo>>>
|
|
434
|
+
/** List of MessageInfo. */
|
|
435
|
+
messages: Maybe<Array<Maybe<MessageInfo>>>
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
export type ShippingSla = {
|
|
439
|
+
/** ShippingSLA carrier. */
|
|
440
|
+
carrier: Maybe<Scalars['String']>
|
|
441
|
+
/** ShippingSLA delivery channel. */
|
|
442
|
+
deliveryChannel: Maybe<Scalars['String']>
|
|
443
|
+
/** List of ShippingSLA delivery ids. */
|
|
444
|
+
deliveryIds: Maybe<Array<Maybe<DeliveryIds>>>
|
|
445
|
+
/** ShippingSLA friendly name. */
|
|
446
|
+
friendlyName: Maybe<Scalars['String']>
|
|
447
|
+
/** ShippingSLA id. */
|
|
448
|
+
id: Maybe<Scalars['String']>
|
|
449
|
+
/**
|
|
450
|
+
* ShippingSLA localized shipping estimate.
|
|
451
|
+
* Note: this will always return a localized string for locale `en-US`.
|
|
452
|
+
*/
|
|
453
|
+
localizedEstimates: Maybe<Scalars['String']>
|
|
454
|
+
/** ShippingSLA name. */
|
|
455
|
+
name: Maybe<Scalars['String']>
|
|
456
|
+
/** ShippingSLA pickup distance. */
|
|
457
|
+
pickupDistance: Maybe<Scalars['Float']>
|
|
458
|
+
/** ShippingSLA pickup point id. */
|
|
459
|
+
pickupPointId: Maybe<Scalars['String']>
|
|
460
|
+
/** ShippingSLA pickup store info. */
|
|
461
|
+
pickupStoreInfo: Maybe<PickupStoreInfo>
|
|
462
|
+
/** ShippingSLA price. */
|
|
463
|
+
price: Maybe<Scalars['Float']>
|
|
464
|
+
/** ShippingSLA shipping estimate. */
|
|
465
|
+
shippingEstimate: Maybe<Scalars['String']>
|
|
466
|
+
/** ShippingSLA shipping estimate date. */
|
|
467
|
+
shippingEstimateDate: Maybe<Scalars['String']>
|
|
468
|
+
}
|
|
469
|
+
|
|
269
470
|
export type SkuVariants = {
|
|
270
471
|
/** SKU property values for the current SKU. */
|
|
271
472
|
activeVariations: Maybe<Scalars['ActiveVariations']>
|
|
@@ -1131,3 +1332,23 @@ export type ValidateSessionMutation = {
|
|
|
1131
1332
|
} | null
|
|
1132
1333
|
} | null
|
|
1133
1334
|
}
|
|
1335
|
+
|
|
1336
|
+
export type ShippingSimulationQueryQueryVariables = Exact<{
|
|
1337
|
+
postalCode: Scalars['String']
|
|
1338
|
+
country: Scalars['String']
|
|
1339
|
+
items: Array<IShippingItem> | IShippingItem
|
|
1340
|
+
}>
|
|
1341
|
+
|
|
1342
|
+
export type ShippingSimulationQueryQuery = {
|
|
1343
|
+
shipping: {
|
|
1344
|
+
logisticsInfo: Array<{
|
|
1345
|
+
slas: Array<{
|
|
1346
|
+
carrier: string | null
|
|
1347
|
+
price: number | null
|
|
1348
|
+
shippingEstimate: string | null
|
|
1349
|
+
localizedEstimates: string | null
|
|
1350
|
+
} | null> | null
|
|
1351
|
+
} | null> | null
|
|
1352
|
+
address: { city: string | null; neighborhood: string | null } | null
|
|
1353
|
+
} | null
|
|
1354
|
+
}
|
|
@@ -8,5 +8,6 @@
|
|
|
8
8
|
"ProductsQuery": "query ProductsQuery($first: Int!, $after: String, $sort: StoreSort!, $term: String!, $selectedFacets: [IStoreSelectedFacet!]!) {\n search(\n first: $first\n after: $after\n sort: $sort\n term: $term\n selectedFacets: $selectedFacets\n ) {\n products {\n pageInfo {\n totalCount\n }\n edges {\n node {\n id: productID\n slug\n sku\n brand {\n brandName: name\n name\n }\n name\n gtin\n isVariantOf {\n productGroupID\n name\n }\n image {\n url\n alternateName\n }\n offers {\n lowPrice\n offers {\n availability\n price\n listPrice\n quantity\n seller {\n identifier\n }\n }\n }\n }\n }\n }\n }\n}\n",
|
|
9
9
|
"SearchSuggestionsQuery": "query SearchSuggestionsQuery($term: String!, $selectedFacets: [IStoreSelectedFacet!]) {\n search(first: 5, term: $term, selectedFacets: $selectedFacets) {\n suggestions {\n terms {\n value\n }\n products {\n id: productID\n slug\n sku\n brand {\n brandName: name\n name\n }\n name\n gtin\n isVariantOf {\n productGroupID\n name\n }\n image {\n url\n alternateName\n }\n offers {\n lowPrice\n offers {\n availability\n price\n listPrice\n quantity\n seller {\n identifier\n }\n }\n }\n }\n }\n }\n}\n",
|
|
10
10
|
"TopSearchSuggestionsQuery": "query TopSearchSuggestionsQuery($term: String!, $selectedFacets: [IStoreSelectedFacet!]) {\n search(first: 5, term: $term, selectedFacets: $selectedFacets) {\n suggestions {\n terms {\n value\n }\n }\n }\n}\n",
|
|
11
|
-
"ValidateSession": "mutation ValidateSession($session: IStoreSession!, $search: String!) {\n validateSession(session: $session, search: $search) {\n locale\n channel\n country\n postalCode\n currency {\n code\n symbol\n }\n person {\n id\n email\n givenName\n familyName\n }\n }\n}\n"
|
|
11
|
+
"ValidateSession": "mutation ValidateSession($session: IStoreSession!, $search: String!) {\n validateSession(session: $session, search: $search) {\n locale\n channel\n country\n postalCode\n currency {\n code\n symbol\n }\n person {\n id\n email\n givenName\n familyName\n }\n }\n}\n",
|
|
12
|
+
"ShippingSimulationQuery": "query ShippingSimulationQuery($postalCode: String!, $country: String!, $items: [IShippingItem!]!) {\n shipping(items: $items, postalCode: $postalCode, country: $country) {\n logisticsInfo {\n slas {\n carrier\n price\n shippingEstimate\n localizedEstimates\n }\n }\n address {\n city\n neighborhood\n }\n }\n}\n"
|
|
12
13
|
}
|
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Conventional Changelog](https://github.com/conventional-changelog/conventional-changelog),
|
|
6
6
|
and this project adheres to [Calendar Versioning](https://calver.org/).
|
|
7
7
|
|
|
8
|
+
### [0.3.3](https://github.com/vtex-sites/nextjs.store/compare/0.3.2...0.3.3) (2022-11-14)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* Shipping Simulation API ([#210](https://github.com/vtex-sites/nextjs.store/issues/210)) ([f391389](https://github.com/vtex-sites/nextjs.store/commit/f3913896261e404d6a93d8bb7e5c805ae00e52a5))
|
|
14
|
+
|
|
8
15
|
### [0.3.2](https://github.com/vtex-sites/nextjs.store/compare/0.3.1...0.3.2) (2022-11-08)
|
|
9
16
|
|
|
10
17
|
|
package/bun.lockb
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faststore/core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"browserslist": "supports es6-module and not dead",
|
|
6
6
|
"scripts": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@envelop/graphql-jit": "^1.1.1",
|
|
31
31
|
"@envelop/parser-cache": "^2.2.0",
|
|
32
32
|
"@envelop/validation-cache": "^2.2.0",
|
|
33
|
-
"@faststore/api": "^1.12.
|
|
33
|
+
"@faststore/api": "^1.12.29",
|
|
34
34
|
"@faststore/graphql-utils": "^1.11.8",
|
|
35
35
|
"@faststore/sdk": "^1.11.8",
|
|
36
36
|
"@faststore/ui": "^1.12.23",
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { gql } from '@faststore/graphql-utils'
|
|
2
|
+
import type { CurrencyCode, ViewItemEvent } from '@faststore/sdk'
|
|
2
3
|
import { sendAnalyticsEvent } from '@faststore/sdk'
|
|
3
4
|
import { useEffect, useState } from 'react'
|
|
4
|
-
import type { CurrencyCode, ViewItemEvent } from '@faststore/sdk'
|
|
5
5
|
|
|
6
|
+
import type { ProductDetailsFragment_ProductFragment } from '@generated/graphql'
|
|
6
7
|
import OutOfStock from 'src/components/product/OutOfStock'
|
|
7
8
|
import { DiscountBadge } from 'src/components/ui/Badge'
|
|
8
9
|
import Breadcrumb from 'src/components/ui/Breadcrumb'
|
|
@@ -12,17 +13,16 @@ import Price from 'src/components/ui/Price'
|
|
|
12
13
|
import ProductTitle from 'src/components/ui/ProductTitle'
|
|
13
14
|
import QuantitySelector from 'src/components/ui/QuantitySelector'
|
|
14
15
|
import ShippingSimulation from 'src/components/ui/ShippingSimulation'
|
|
16
|
+
import Selectors from 'src/components/ui/SkuSelector'
|
|
17
|
+
import type { AnalyticsItem } from 'src/sdk/analytics/types'
|
|
15
18
|
import { useBuyButton } from 'src/sdk/cart/useBuyButton'
|
|
16
19
|
import { useFormattedPrice } from 'src/sdk/product/useFormattedPrice'
|
|
17
20
|
import { useProduct } from 'src/sdk/product/useProduct'
|
|
18
21
|
import { useSession } from 'src/sdk/session'
|
|
19
|
-
import type { ProductDetailsFragment_ProductFragment } from '@generated/graphql'
|
|
20
|
-
import type { AnalyticsItem } from 'src/sdk/analytics/types'
|
|
21
|
-
import Selectors from 'src/components/ui/SkuSelector'
|
|
22
22
|
|
|
23
|
-
import styles from './product-details.module.scss'
|
|
24
|
-
import Section from '../Section'
|
|
25
23
|
import ProductDetailsContent from '../ProducDetailsContent'
|
|
24
|
+
import Section from '../Section'
|
|
25
|
+
import styles from './product-details.module.scss'
|
|
26
26
|
|
|
27
27
|
interface Props {
|
|
28
28
|
context: ProductDetailsFragment_ProductFragment
|
|
@@ -194,6 +194,11 @@ function ProductDetails({ context: staleProduct }: Props) {
|
|
|
194
194
|
<ShippingSimulation
|
|
195
195
|
data-fs-product-details-section
|
|
196
196
|
data-fs-product-details-shipping
|
|
197
|
+
shippingItem={{
|
|
198
|
+
id,
|
|
199
|
+
quantity: addQuantity,
|
|
200
|
+
seller: seller.identifier,
|
|
201
|
+
}}
|
|
197
202
|
/>
|
|
198
203
|
</section>
|
|
199
204
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { IShippingItem } from '@faststore/api'
|
|
1
2
|
import { Table, TableBody, TableCell, TableRow } from '@faststore/ui'
|
|
2
3
|
import type { HTMLAttributes } from 'react'
|
|
3
4
|
|
|
@@ -16,14 +17,19 @@ interface ShippingSimulationProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
16
17
|
* testing-library, and jest).
|
|
17
18
|
*/
|
|
18
19
|
testId?: string
|
|
20
|
+
/**
|
|
21
|
+
* Object used for simulating shippings
|
|
22
|
+
*/
|
|
23
|
+
shippingItem: IShippingItem
|
|
19
24
|
}
|
|
20
25
|
|
|
21
26
|
function ShippingSimulation({
|
|
22
27
|
testId = 'store-shipping-simulation',
|
|
28
|
+
shippingItem,
|
|
23
29
|
...otherProps
|
|
24
30
|
}: ShippingSimulationProps) {
|
|
25
31
|
const { dispatch, input, shippingSimulation, handleSubmit, handleOnInput } =
|
|
26
|
-
useShippingSimulation()
|
|
32
|
+
useShippingSimulation(shippingItem)
|
|
27
33
|
|
|
28
34
|
const {
|
|
29
35
|
postalCode: shippingPostalCode,
|
|
@@ -87,14 +93,16 @@ function ShippingSimulation({
|
|
|
87
93
|
{option.carrier}
|
|
88
94
|
</TableCell>
|
|
89
95
|
<TableCell data-fs-shipping-simulation-table-cell>
|
|
90
|
-
{option.
|
|
96
|
+
{option.localizedEstimates}
|
|
91
97
|
</TableCell>
|
|
92
98
|
<TableCell data-fs-shipping-simulation-table-cell>
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
99
|
+
{option.price && (
|
|
100
|
+
<Price
|
|
101
|
+
formatter={formatter}
|
|
102
|
+
value={option.price}
|
|
103
|
+
SRText="price"
|
|
104
|
+
/>
|
|
105
|
+
)}
|
|
98
106
|
</TableCell>
|
|
99
107
|
</TableRow>
|
|
100
108
|
))}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import type { ChangeEvent } from 'react'
|
|
2
2
|
import { useCallback, useEffect, useReducer } from 'react'
|
|
3
3
|
|
|
4
|
+
import type {
|
|
5
|
+
IShippingItem,
|
|
6
|
+
ShippingSimulationQueryQuery,
|
|
7
|
+
ShippingSla,
|
|
8
|
+
} from '@generated/graphql'
|
|
4
9
|
import { useSession } from 'src/sdk/session'
|
|
10
|
+
import { getShippingSimulation } from 'src/sdk/shipping'
|
|
5
11
|
|
|
6
12
|
type InputProps = {
|
|
7
13
|
postalCode?: string
|
|
@@ -9,15 +15,9 @@ type InputProps = {
|
|
|
9
15
|
errorMessage?: string
|
|
10
16
|
}
|
|
11
17
|
|
|
12
|
-
type ShippingOptionProps = {
|
|
13
|
-
carrier: string
|
|
14
|
-
estimate: string
|
|
15
|
-
price: number
|
|
16
|
-
}
|
|
17
|
-
|
|
18
18
|
type ShippingSimulationProps = {
|
|
19
19
|
location?: string
|
|
20
|
-
options?:
|
|
20
|
+
options?: ShippingSla[]
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
type State = {
|
|
@@ -42,35 +42,6 @@ type Action =
|
|
|
42
42
|
type: 'clear'
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
// TODO Remove Mocked data after API integration
|
|
46
|
-
const mockShippingOptions: ShippingOptionProps[] = [
|
|
47
|
-
{
|
|
48
|
-
carrier: 'Regular',
|
|
49
|
-
estimate: '12 days',
|
|
50
|
-
price: 21,
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
carrier: 'Fedex',
|
|
54
|
-
estimate: '12 days',
|
|
55
|
-
price: 23,
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
carrier: 'Same day',
|
|
59
|
-
estimate: '1 day',
|
|
60
|
-
price: 89,
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
carrier: 'DHL',
|
|
64
|
-
estimate: '1 day',
|
|
65
|
-
price: 100,
|
|
66
|
-
},
|
|
67
|
-
]
|
|
68
|
-
|
|
69
|
-
const mockShippingSimulation: ShippingSimulationProps = {
|
|
70
|
-
location: 'Street Default — Newark, NY',
|
|
71
|
-
options: mockShippingOptions,
|
|
72
|
-
}
|
|
73
|
-
|
|
74
45
|
const createEmptySimulation = () => ({
|
|
75
46
|
input: {
|
|
76
47
|
postalCode: '',
|
|
@@ -134,8 +105,21 @@ const reducer = (state: State, action: Action) => {
|
|
|
134
105
|
}
|
|
135
106
|
}
|
|
136
107
|
|
|
137
|
-
|
|
138
|
-
|
|
108
|
+
function getShippingInformation(
|
|
109
|
+
shipping: ShippingSimulationQueryQuery['shipping']
|
|
110
|
+
): [string, ShippingSla[]] {
|
|
111
|
+
const location =
|
|
112
|
+
[shipping?.address?.neighborhood, shipping?.address?.city]
|
|
113
|
+
.filter(Boolean)
|
|
114
|
+
.join(' / ') ?? ''
|
|
115
|
+
|
|
116
|
+
const options = shipping?.logisticsInfo?.[0]?.slas ?? []
|
|
117
|
+
|
|
118
|
+
return [location, options as ShippingSla[]]
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export const useShippingSimulation = (shippingItem: IShippingItem) => {
|
|
122
|
+
const { postalCode: sessionPostalCode, country } = useSession()
|
|
139
123
|
const [{ input, shippingSimulation }, dispatch] = useReducer(
|
|
140
124
|
reducer,
|
|
141
125
|
null,
|
|
@@ -150,28 +134,46 @@ export const useShippingSimulation = () => {
|
|
|
150
134
|
}
|
|
151
135
|
|
|
152
136
|
// Use sessionPostalCode if there is no shippingPostalCode
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
137
|
+
async function fetchShipping() {
|
|
138
|
+
const shipping = await getShippingSimulation({
|
|
139
|
+
country,
|
|
140
|
+
postalCode: sessionPostalCode ?? '',
|
|
141
|
+
items: [shippingItem],
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
const [location, options] = getShippingInformation(shipping)
|
|
145
|
+
|
|
146
|
+
dispatch({
|
|
147
|
+
type: 'update',
|
|
148
|
+
payload: {
|
|
149
|
+
input: {
|
|
150
|
+
postalCode: sessionPostalCode ?? '',
|
|
151
|
+
displayClearButton: true,
|
|
152
|
+
errorMessage: '',
|
|
153
|
+
},
|
|
154
|
+
shippingSimulation: {
|
|
155
|
+
location,
|
|
156
|
+
options,
|
|
157
|
+
},
|
|
165
158
|
},
|
|
166
|
-
}
|
|
167
|
-
}
|
|
159
|
+
})
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
fetchShipping()
|
|
168
163
|
|
|
169
164
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
170
165
|
}, [sessionPostalCode])
|
|
171
166
|
|
|
172
|
-
const handleSubmit = useCallback(() => {
|
|
167
|
+
const handleSubmit = useCallback(async () => {
|
|
173
168
|
try {
|
|
174
|
-
|
|
169
|
+
const shipping = await getShippingSimulation({
|
|
170
|
+
country,
|
|
171
|
+
postalCode: shippingPostalCode ?? '',
|
|
172
|
+
items: [shippingItem],
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
const [location, options] = getShippingInformation(shipping)
|
|
176
|
+
|
|
175
177
|
dispatch({
|
|
176
178
|
type: 'update',
|
|
177
179
|
payload: {
|
|
@@ -180,8 +182,8 @@ export const useShippingSimulation = () => {
|
|
|
180
182
|
errorMessage: '',
|
|
181
183
|
},
|
|
182
184
|
shippingSimulation: {
|
|
183
|
-
location
|
|
184
|
-
options
|
|
185
|
+
location,
|
|
186
|
+
options,
|
|
185
187
|
},
|
|
186
188
|
},
|
|
187
189
|
})
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { IShippingItem } from '@faststore/api'
|
|
2
|
+
import { gql } from '@faststore/graphql-utils'
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
ShippingSimulationQueryQuery as Query,
|
|
6
|
+
ShippingSimulationQueryQueryVariables as Variables,
|
|
7
|
+
} from '@generated/graphql'
|
|
8
|
+
|
|
9
|
+
import { request } from '../graphql/request'
|
|
10
|
+
|
|
11
|
+
const query = gql`
|
|
12
|
+
query ShippingSimulationQuery(
|
|
13
|
+
$postalCode: String!
|
|
14
|
+
$country: String!
|
|
15
|
+
$items: [IShippingItem!]!
|
|
16
|
+
) {
|
|
17
|
+
shipping(items: $items, postalCode: $postalCode, country: $country) {
|
|
18
|
+
logisticsInfo {
|
|
19
|
+
slas {
|
|
20
|
+
carrier
|
|
21
|
+
price
|
|
22
|
+
shippingEstimate
|
|
23
|
+
localizedEstimates
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
address {
|
|
27
|
+
city
|
|
28
|
+
neighborhood
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
`
|
|
33
|
+
|
|
34
|
+
export type ShippingQueryData = {
|
|
35
|
+
items: IShippingItem[]
|
|
36
|
+
postalCode: string
|
|
37
|
+
country: string
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const getShippingSimulation = async ({
|
|
41
|
+
items,
|
|
42
|
+
postalCode,
|
|
43
|
+
country,
|
|
44
|
+
}: ShippingQueryData) => {
|
|
45
|
+
const data = await request<Query, Variables>(query, {
|
|
46
|
+
items,
|
|
47
|
+
postalCode,
|
|
48
|
+
country,
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
return data.shipping
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export default getShippingSimulation
|