@hanzo/commerce 7.2.0 → 7.3.1
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/components/buy/buy-card.tsx +1 -1
- package/components/buy/carousel-buy-card.tsx +1 -1
- package/components/cart/cart-panel/cart-line-item.tsx +1 -1
- package/components/cart/cart-panel/index.tsx +1 -1
- package/components/cart/cart-panel/promo-code.tsx +11 -3
- package/components/cart/cart-panel/total-area.tsx +1 -1
- package/components/checkout/payment-step-form/index.tsx +1 -1
- package/components/checkout/payment-step-form/methods/card.tsx +1 -1
- package/components/checkout/payment-step-form/methods/crypto.tsx +1 -1
- package/components/checkout/shipping-step-form.tsx +1 -1
- package/components/item-selector/carousel/index.tsx +1 -1
- package/index.ts +2 -2
- package/package.json +1 -1
- package/{context/index.tsx → service/context.tsx} +1 -1
- package/service/impls/standalone/actual-line-item.ts +1 -0
- package/service/impls/standalone/get-instance.ts +64 -0
- package/service/impls/standalone/index.ts +559 -42
- package/service/impls/standalone/{orders → order}/index.ts +2 -2
- package/service/impls/standalone/persistence.ts +33 -0
- package/util/use-sync-sku-param-w-current-item.ts +1 -1
- package/service/get-instance.ts +0 -3
- package/service/impls/standalone/localStorage.ts +0 -34
- package/service/impls/standalone/standalone-service.ts +0 -574
- /package/service/impls/standalone/{orders/firebase-app.ts → order/firebase.ts} +0 -0
|
@@ -14,7 +14,7 @@ import type {
|
|
|
14
14
|
CategoryNode,
|
|
15
15
|
} from '../../types'
|
|
16
16
|
|
|
17
|
-
import { useCommerce } from '../../context'
|
|
17
|
+
import { useCommerce } from '../../service/context'
|
|
18
18
|
import * as pathUtils from '../../service/path-utils'
|
|
19
19
|
import { getFacetValuesMutator, ObsStringMutator } from '../../util'
|
|
20
20
|
|
|
@@ -21,7 +21,7 @@ import type {
|
|
|
21
21
|
MultiFamilySelectorOptions,
|
|
22
22
|
} from '../../types'
|
|
23
23
|
|
|
24
|
-
import { useCommerce } from '../../context'
|
|
24
|
+
import { useCommerce } from '../../service/context'
|
|
25
25
|
import { getSelectionUISpecifier } from '../../util'
|
|
26
26
|
|
|
27
27
|
import { CarouselItemSelector, ButtonItemSelector } from '../item-selector'
|
|
@@ -9,7 +9,7 @@ import { Image } from '@hanzo/ui/primitives'
|
|
|
9
9
|
import type { LineItem } from '../../../types'
|
|
10
10
|
import { formatCurrencyValue } from '../../../util'
|
|
11
11
|
import AddToCartWidget from '../../add-to-cart-widget'
|
|
12
|
-
import { useCommerce } from '../../../context'
|
|
12
|
+
import { useCommerce } from '../../../service/context'
|
|
13
13
|
|
|
14
14
|
const DEF_IMG_SIZE=40
|
|
15
15
|
|
|
@@ -7,7 +7,7 @@ import { Button, ScrollArea } from '@hanzo/ui/primitives'
|
|
|
7
7
|
import { cn } from '@hanzo/ui/util'
|
|
8
8
|
|
|
9
9
|
import type { LineItem } from '../../../types'
|
|
10
|
-
import { useCommerce } from '../../../context'
|
|
10
|
+
import { useCommerce } from '../../../service/context'
|
|
11
11
|
import { sendFBEvent, sendGAEvent } from '../../../util/analytics'
|
|
12
12
|
|
|
13
13
|
import CartLineItem from './cart-line-item'
|
|
@@ -2,15 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
import { useEffect, useState } from 'react'
|
|
4
4
|
import { useSearchParams } from 'next/navigation'
|
|
5
|
+
import { observer } from 'mobx-react-lite'
|
|
6
|
+
|
|
5
7
|
import { useForm } from 'react-hook-form'
|
|
6
8
|
import * as z from 'zod'
|
|
7
9
|
import { zodResolver } from '@hookform/resolvers/zod'
|
|
8
10
|
import { Check } from 'lucide-react'
|
|
9
|
-
import { observer } from 'mobx-react-lite'
|
|
10
11
|
|
|
11
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
Button,
|
|
14
|
+
Form,
|
|
15
|
+
FormControl,
|
|
16
|
+
FormField,
|
|
17
|
+
FormItem,
|
|
18
|
+
Input
|
|
19
|
+
} from '@hanzo/ui/primitives'
|
|
12
20
|
|
|
13
|
-
import { useCommerce } from '../../../context'
|
|
21
|
+
import { useCommerce } from '../../../service/context'
|
|
14
22
|
import type { Promo } from '../../../types'
|
|
15
23
|
import getPromoFromApi from '../../../util/promo-codes'
|
|
16
24
|
|
|
@@ -6,7 +6,7 @@ import { cn } from '@hanzo/ui/util'
|
|
|
6
6
|
|
|
7
7
|
import { formatCurrencyValue } from '../../../util'
|
|
8
8
|
import PromoCode from './promo-code'
|
|
9
|
-
import { useCommerce } from '../../../context'
|
|
9
|
+
import { useCommerce } from '../../../service/context'
|
|
10
10
|
|
|
11
11
|
const TotalArea: React.FC<{
|
|
12
12
|
showPromoCode?: boolean
|
|
@@ -9,7 +9,7 @@ import { useForm } from 'react-hook-form'
|
|
|
9
9
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@hanzo/ui/primitives'
|
|
10
10
|
import { useAuth } from '@hanzo/auth/service'
|
|
11
11
|
|
|
12
|
-
import { useCommerce } from '../../../context'
|
|
12
|
+
import { useCommerce } from '../../../service/context'
|
|
13
13
|
import { sendFBEvent, sendGAEvent } from '../../../util/analytics'
|
|
14
14
|
import type { CheckoutStepComponentProps, TransactionStatus } from '../../../types'
|
|
15
15
|
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
|
|
16
16
|
import { cn } from '@hanzo/ui/util'
|
|
17
17
|
|
|
18
|
-
import { useCommerce } from '../../../../context'
|
|
18
|
+
import { useCommerce } from '../../../../service/context'
|
|
19
19
|
import { processSquareCardPayment } from '../../../../util'
|
|
20
20
|
import type { PaymentMethodComponentProps } from '../../../../types'
|
|
21
21
|
import { sendFBEvent, sendGAEvent } from '../../../../util/analytics'
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
} from '@hanzo/ui/primitives'
|
|
20
20
|
|
|
21
21
|
import Eth from '../crypto-icons/eth'
|
|
22
|
-
import { useCommerce } from '../../../../context'
|
|
22
|
+
import { useCommerce } from '../../../../service/context'
|
|
23
23
|
import type { PaymentMethodComponentProps } from '../../../../types'
|
|
24
24
|
import { sendFBEvent, sendGAEvent } from '../../../../util/analytics'
|
|
25
25
|
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
SelectValue
|
|
20
20
|
} from '@hanzo/ui/primitives'
|
|
21
21
|
|
|
22
|
-
import { useCommerce } from '../../context'
|
|
22
|
+
import { useCommerce } from '../../service/context'
|
|
23
23
|
|
|
24
24
|
import countries from '../../util/countries'
|
|
25
25
|
import { sendGAEvent } from '../../util/analytics'
|
|
@@ -178,7 +178,7 @@ const CarouselItemSelector: React.FC<ItemSelectorProps> = observer(({
|
|
|
178
178
|
</div>
|
|
179
179
|
{showByline && itemRef.item.byline && (<p>{itemRef.item.byline}</p>)}
|
|
180
180
|
</ApplyTypography>
|
|
181
|
-
{showSlider && (
|
|
181
|
+
{showSlider && items.length > 1 && (
|
|
182
182
|
<ItemCarouselSlider
|
|
183
183
|
clx='mt-5 w-[320px]'
|
|
184
184
|
numStops={items.length}
|
package/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from './context'
|
|
1
|
+
export * from './service/context'
|
|
2
2
|
export * from './components'
|
|
3
3
|
// Impl-dependent, so leave w impl
|
|
4
|
-
export type { StandaloneServiceOptions as ServiceOptions } from './service/impls/standalone
|
|
4
|
+
export type { StandaloneServiceOptions as ServiceOptions } from './service/impls/standalone'
|
|
5
5
|
export {
|
|
6
6
|
useSyncSkuParamWithCurrentItem,
|
|
7
7
|
getFacetValuesMutator,
|
package/package.json
CHANGED
|
@@ -11,8 +11,8 @@ import { enableStaticRendering } from 'mobx-react-lite'
|
|
|
11
11
|
enableStaticRendering(typeof window === "undefined")
|
|
12
12
|
|
|
13
13
|
import type CommerceService from '../types/commerce-service'
|
|
14
|
-
import getInstance from '../service/get-instance'
|
|
15
14
|
import type { CommerceConfig } from '../types'
|
|
15
|
+
import { getInstance } from './impls/standalone'
|
|
16
16
|
|
|
17
17
|
const CommerceContext = createContext<CommerceService | undefined>(undefined)
|
|
18
18
|
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { enableStaticRendering } from 'mobx-react-lite'
|
|
2
|
+
|
|
3
|
+
import type { CommerceService, CommerceConfig } from '../../../types'
|
|
4
|
+
import { StandaloneService } from './index'
|
|
5
|
+
import { initSelectionUI } from '../../../util'
|
|
6
|
+
|
|
7
|
+
import { readSnapshot, writeSnapshotsOnChange } from './persistence'
|
|
8
|
+
|
|
9
|
+
enableStaticRendering(typeof window === "undefined")
|
|
10
|
+
|
|
11
|
+
const _LOG = false
|
|
12
|
+
const _log = (s: string) => {
|
|
13
|
+
if (!_LOG) return;
|
|
14
|
+
const d = new Date()
|
|
15
|
+
console.log(`TIMESTAMPED: ${d.getUTCMinutes()}:${d.getUTCSeconds()}:${d.getUTCMilliseconds()}`)
|
|
16
|
+
console.log(s)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// https://dev.to/ivandotv/mobx-server-side-rendering-with-next-js-4m18
|
|
20
|
+
|
|
21
|
+
let instance: StandaloneService | undefined = undefined
|
|
22
|
+
|
|
23
|
+
export const getInstance = ({
|
|
24
|
+
families,
|
|
25
|
+
rootNode,
|
|
26
|
+
options,
|
|
27
|
+
uiSpecifiers
|
|
28
|
+
}: CommerceConfig) : CommerceService => {
|
|
29
|
+
|
|
30
|
+
if (!options) {
|
|
31
|
+
throw new Error('cmmc getInstance(): Standalone Commerce Service requires config options!')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (typeof window === "undefined") {
|
|
35
|
+
if (uiSpecifiers) {
|
|
36
|
+
initSelectionUI(uiSpecifiers)
|
|
37
|
+
}
|
|
38
|
+
_log("NEW INSTANCE: SERVER") //////////
|
|
39
|
+
return new StandaloneService(
|
|
40
|
+
families,
|
|
41
|
+
rootNode,
|
|
42
|
+
options
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Client side, create the store only once in the client
|
|
47
|
+
if (!instance) {
|
|
48
|
+
if (uiSpecifiers) {
|
|
49
|
+
initSelectionUI(uiSpecifiers)
|
|
50
|
+
}
|
|
51
|
+
_log("NEW INSTANCE: CLIENT") ///////////
|
|
52
|
+
const snapShot = readSnapshot(options.localStorageKey)
|
|
53
|
+
instance = new StandaloneService(
|
|
54
|
+
families,
|
|
55
|
+
rootNode,
|
|
56
|
+
options,
|
|
57
|
+
snapShot
|
|
58
|
+
)
|
|
59
|
+
writeSnapshotsOnChange(instance, options.localStorageKey)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return instance
|
|
63
|
+
}
|
|
64
|
+
|