@hanzo/commerce 7.1.5 → 7.1.7
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/Icons.tsx +34 -34
- package/components/add-to-cart-widget.tsx +181 -181
- package/components/buy/buy-card.tsx +259 -259
- package/components/buy/carousel-buy-card.tsx +245 -245
- package/components/buy/multi-family/all-variants-carousel.tsx +261 -261
- package/components/buy/multi-family/family-carousel/index.tsx +77 -77
- package/components/buy/multi-family/family-carousel/slide.tsx +83 -83
- package/components/buy/multi-family/family-carousel/state.ts +87 -87
- package/components/buy/multi-family/index.ts +2 -2
- package/components/buy/single-family-selector.tsx +90 -90
- package/components/buy/title-and-byline.tsx +25 -25
- package/components/cart/cart-accordian.tsx +59 -59
- package/components/cart/cart-panel/cart-line-item.tsx +76 -76
- package/components/cart/cart-panel/index.tsx +161 -159
- package/components/cart/cart-panel/promo-code.tsx +98 -98
- package/components/checkout/payment-step-form/card-icon-row.tsx +26 -26
- package/components/checkout/payment-step-form/card-icons/amex.tsx +32 -32
- package/components/checkout/payment-step-form/card-icons/diners-club.tsx +13 -13
- package/components/checkout/payment-step-form/card-icons/discover.tsx +25 -25
- package/components/checkout/payment-step-form/card-icons/jcb.tsx +26 -26
- package/components/checkout/payment-step-form/card-icons/mastercard.tsx +27 -27
- package/components/checkout/payment-step-form/card-icons/visa.tsx +25 -25
- package/components/checkout/payment-step-form/cc-button.tsx +17 -17
- package/components/checkout/payment-step-form/contact-form.tsx +49 -49
- package/components/checkout/payment-step-form/crypto-icons/btc.tsx +11 -11
- package/components/checkout/payment-step-form/crypto-icons/eth.tsx +20 -20
- package/components/checkout/payment-step-form/crypto-icons/usdt.tsx +13 -13
- package/components/checkout/payment-step-form/index.tsx +122 -122
- package/components/checkout/payment-step-form/methods/bank-transfer.tsx +79 -79
- package/components/checkout/payment-step-form/methods/card.tsx +232 -232
- package/components/checkout/payment-step-form/methods/crypto.tsx +227 -227
- package/components/checkout/payment-step-form/methods/index.ts +22 -22
- package/components/checkout/shipping-step-form.tsx +172 -172
- package/components/index.ts +12 -12
- package/components/item/product-card.tsx +48 -48
- package/components/item-selector/button.tsx +188 -188
- package/components/item-selector/carousel/index.tsx +197 -197
- package/components/item-selector/carousel/slider.tsx +40 -40
- package/components/item-selector/index.ts +5 -5
- package/components/item-selector/quantity-indicator.tsx +48 -48
- package/components/node-tabs/index.tsx +91 -91
- package/components/node-tabs/node-image.tsx +31 -31
- package/context/index.tsx +45 -45
- package/index.ts +12 -12
- package/package.json +60 -60
- package/service/debug.ts +41 -41
- package/service/get-instance.ts +2 -2
- package/service/impls/standalone/actual-line-item.ts +121 -121
- package/service/impls/standalone/index.ts +62 -62
- package/service/impls/standalone/localStorage.ts +34 -34
- package/service/impls/standalone/orders/firebase-app.ts +14 -14
- package/service/impls/standalone/orders/index.ts +128 -128
- package/service/impls/standalone/standalone-service.ts +550 -550
- package/service/path-utils.ts +25 -25
- package/service/sep.ts +6 -6
- package/tsconfig.json +10 -10
- package/types/README.md +1 -1
- package/types/category-node.ts +49 -49
- package/types/checkout.ts +46 -46
- package/types/commerce-config.ts +13 -13
- package/types/commerce-service.ts +121 -121
- package/types/family.ts +25 -25
- package/types/index.ts +15 -15
- package/types/item-selector.ts +96 -96
- package/types/line-item.ts +29 -29
- package/types/multi-family-selector-props.ts +19 -19
- package/types/product.ts +20 -20
- package/types/promo.ts +9 -9
- package/types/selection-ui-specifier.ts +51 -51
- package/types/string-mutator.ts +13 -13
- package/types/token-separators.ts +7 -7
- package/util/analytics.ts +20 -20
- package/util/countries.ts +195 -195
- package/util/error.ts +34 -34
- package/util/index.ts +70 -70
- package/util/item-selector-options-accessor.ts +34 -34
- package/util/line-item-ref.ts +23 -23
- package/util/multi-family-selector-options-accessor.ts +14 -14
- package/util/obs-string-mutator.ts +22 -22
- package/util/product-media-accessor.ts +58 -58
- package/util/promo-codes.ts +108 -108
- package/util/selection-ui-specifiers.ts +29 -29
- package/util/square-payment.ts +42 -42
- package/util/use-sync-sku-param-w-current-item.ts +88 -88
|
@@ -1,122 +1,122 @@
|
|
|
1
|
-
import {
|
|
2
|
-
action,
|
|
3
|
-
computed,
|
|
4
|
-
makeObservable,
|
|
5
|
-
observable,
|
|
6
|
-
} from 'mobx'
|
|
7
|
-
|
|
8
|
-
import type { ImageDef, MediaTransform, VideoDef } from '@hanzo/ui/types'
|
|
9
|
-
|
|
10
|
-
import type { Product, LineItem, CommerceService } from '../../../types'
|
|
11
|
-
|
|
12
|
-
interface ActualLineItemSnapshot {
|
|
13
|
-
sku: string
|
|
14
|
-
familyId: string // helps impl of restoreFromSnapshot
|
|
15
|
-
title: string
|
|
16
|
-
price: number
|
|
17
|
-
quantity: number
|
|
18
|
-
timeAdded: number // helps to sort view of order and cart
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
class ActualLineItem
|
|
22
|
-
implements LineItem
|
|
23
|
-
{
|
|
24
|
-
|
|
25
|
-
qu: number = 0
|
|
26
|
-
|
|
27
|
-
id: string
|
|
28
|
-
sku: string
|
|
29
|
-
fullTitle?: string
|
|
30
|
-
optionLabel: string
|
|
31
|
-
optionLabelShort?: string
|
|
32
|
-
familyTitle: string
|
|
33
|
-
familyId: string
|
|
34
|
-
byline?: string
|
|
35
|
-
desc?: string
|
|
36
|
-
price: number
|
|
37
|
-
img?: ImageDef
|
|
38
|
-
video?: VideoDef
|
|
39
|
-
animation?: string
|
|
40
|
-
mediaTransform?: MediaTransform
|
|
41
|
-
optionImg?: ImageDef
|
|
42
|
-
timeAdded: number = 0 // timeAdded of being added to cart
|
|
43
|
-
|
|
44
|
-
constructor(prod: Product, snap?: ActualLineItemSnapshot) {
|
|
45
|
-
this.id = prod.id
|
|
46
|
-
this.sku = prod.sku
|
|
47
|
-
this.fullTitle = prod.fullTitle
|
|
48
|
-
this.optionLabel = prod.optionLabel
|
|
49
|
-
this.optionLabelShort = prod.optionLabelShort
|
|
50
|
-
this.familyTitle = prod.familyTitle
|
|
51
|
-
this.familyId = prod.familyId
|
|
52
|
-
this.byline = prod.byline
|
|
53
|
-
this.desc = prod.desc
|
|
54
|
-
this.price = prod.price
|
|
55
|
-
this.img = prod.img
|
|
56
|
-
this.video = prod.video
|
|
57
|
-
this.animation = prod.animation
|
|
58
|
-
this.optionImg = prod.optionImg
|
|
59
|
-
this.mediaTransform = prod.mediaTransform
|
|
60
|
-
|
|
61
|
-
if (snap) {
|
|
62
|
-
this.qu = snap.quantity
|
|
63
|
-
this.timeAdded = snap.timeAdded
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
makeObservable(this, {
|
|
67
|
-
qu: observable,
|
|
68
|
-
timeAdded: observable,
|
|
69
|
-
canDecrement: computed,
|
|
70
|
-
isInCart: computed,
|
|
71
|
-
title: computed,
|
|
72
|
-
increment: action,
|
|
73
|
-
decrement: action,
|
|
74
|
-
})
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
get title(): string {
|
|
78
|
-
return this.fullTitle ? this.fullTitle : (this.familyTitle + ', ' + this.optionLabel)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
takeSnapshot = (cmmc: CommerceService): ActualLineItemSnapshot => {
|
|
82
|
-
|
|
83
|
-
const title = this.fullTitle ?
|
|
84
|
-
this.fullTitle
|
|
85
|
-
:
|
|
86
|
-
((cmmc.getFamilyById(this.familyId)?.title ?? this.familyTitle) + ', ' + this.optionLabel)
|
|
87
|
-
|
|
88
|
-
return({
|
|
89
|
-
sku: this.sku,
|
|
90
|
-
familyId: this.familyId,
|
|
91
|
-
title,
|
|
92
|
-
price: this.price,
|
|
93
|
-
quantity: this.qu,
|
|
94
|
-
timeAdded: this.timeAdded
|
|
95
|
-
} satisfies ActualLineItemSnapshot)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
get canDecrement(): boolean { return this.qu > 0 }
|
|
99
|
-
get quantity(): number {return this.qu}
|
|
100
|
-
get isInCart(): boolean {return this.qu > 0}
|
|
101
|
-
|
|
102
|
-
increment(): void {
|
|
103
|
-
if (this.qu === 0) {
|
|
104
|
-
this.timeAdded = new Date().getTime()
|
|
105
|
-
}
|
|
106
|
-
this.qu++
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
decrement(): void {
|
|
110
|
-
if (this.canDecrement) {
|
|
111
|
-
this.qu--
|
|
112
|
-
if (this.qu === 0) {
|
|
113
|
-
this.timeAdded = 0
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export {
|
|
120
|
-
type ActualLineItemSnapshot,
|
|
121
|
-
ActualLineItem as default
|
|
1
|
+
import {
|
|
2
|
+
action,
|
|
3
|
+
computed,
|
|
4
|
+
makeObservable,
|
|
5
|
+
observable,
|
|
6
|
+
} from 'mobx'
|
|
7
|
+
|
|
8
|
+
import type { ImageDef, MediaTransform, VideoDef } from '@hanzo/ui/types'
|
|
9
|
+
|
|
10
|
+
import type { Product, LineItem, CommerceService } from '../../../types'
|
|
11
|
+
|
|
12
|
+
interface ActualLineItemSnapshot {
|
|
13
|
+
sku: string
|
|
14
|
+
familyId: string // helps impl of restoreFromSnapshot
|
|
15
|
+
title: string
|
|
16
|
+
price: number
|
|
17
|
+
quantity: number
|
|
18
|
+
timeAdded: number // helps to sort view of order and cart
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
class ActualLineItem
|
|
22
|
+
implements LineItem
|
|
23
|
+
{
|
|
24
|
+
|
|
25
|
+
qu: number = 0
|
|
26
|
+
|
|
27
|
+
id: string
|
|
28
|
+
sku: string
|
|
29
|
+
fullTitle?: string
|
|
30
|
+
optionLabel: string
|
|
31
|
+
optionLabelShort?: string
|
|
32
|
+
familyTitle: string
|
|
33
|
+
familyId: string
|
|
34
|
+
byline?: string
|
|
35
|
+
desc?: string
|
|
36
|
+
price: number
|
|
37
|
+
img?: ImageDef
|
|
38
|
+
video?: VideoDef
|
|
39
|
+
animation?: string
|
|
40
|
+
mediaTransform?: MediaTransform
|
|
41
|
+
optionImg?: ImageDef
|
|
42
|
+
timeAdded: number = 0 // timeAdded of being added to cart
|
|
43
|
+
|
|
44
|
+
constructor(prod: Product, snap?: ActualLineItemSnapshot) {
|
|
45
|
+
this.id = prod.id
|
|
46
|
+
this.sku = prod.sku
|
|
47
|
+
this.fullTitle = prod.fullTitle
|
|
48
|
+
this.optionLabel = prod.optionLabel
|
|
49
|
+
this.optionLabelShort = prod.optionLabelShort
|
|
50
|
+
this.familyTitle = prod.familyTitle
|
|
51
|
+
this.familyId = prod.familyId
|
|
52
|
+
this.byline = prod.byline
|
|
53
|
+
this.desc = prod.desc
|
|
54
|
+
this.price = prod.price
|
|
55
|
+
this.img = prod.img
|
|
56
|
+
this.video = prod.video
|
|
57
|
+
this.animation = prod.animation
|
|
58
|
+
this.optionImg = prod.optionImg
|
|
59
|
+
this.mediaTransform = prod.mediaTransform
|
|
60
|
+
|
|
61
|
+
if (snap) {
|
|
62
|
+
this.qu = snap.quantity
|
|
63
|
+
this.timeAdded = snap.timeAdded
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
makeObservable(this, {
|
|
67
|
+
qu: observable,
|
|
68
|
+
timeAdded: observable,
|
|
69
|
+
canDecrement: computed,
|
|
70
|
+
isInCart: computed,
|
|
71
|
+
title: computed,
|
|
72
|
+
increment: action,
|
|
73
|
+
decrement: action,
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get title(): string {
|
|
78
|
+
return this.fullTitle ? this.fullTitle : (this.familyTitle + ', ' + this.optionLabel)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
takeSnapshot = (cmmc: CommerceService): ActualLineItemSnapshot => {
|
|
82
|
+
|
|
83
|
+
const title = this.fullTitle ?
|
|
84
|
+
this.fullTitle
|
|
85
|
+
:
|
|
86
|
+
((cmmc.getFamilyById(this.familyId)?.title ?? this.familyTitle) + ', ' + this.optionLabel)
|
|
87
|
+
|
|
88
|
+
return({
|
|
89
|
+
sku: this.sku,
|
|
90
|
+
familyId: this.familyId,
|
|
91
|
+
title,
|
|
92
|
+
price: this.price,
|
|
93
|
+
quantity: this.qu,
|
|
94
|
+
timeAdded: this.timeAdded
|
|
95
|
+
} satisfies ActualLineItemSnapshot)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
get canDecrement(): boolean { return this.qu > 0 }
|
|
99
|
+
get quantity(): number {return this.qu}
|
|
100
|
+
get isInCart(): boolean {return this.qu > 0}
|
|
101
|
+
|
|
102
|
+
increment(): void {
|
|
103
|
+
if (this.qu === 0) {
|
|
104
|
+
this.timeAdded = new Date().getTime()
|
|
105
|
+
}
|
|
106
|
+
this.qu++
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
decrement(): void {
|
|
110
|
+
if (this.canDecrement) {
|
|
111
|
+
this.qu--
|
|
112
|
+
if (this.qu === 0) {
|
|
113
|
+
this.timeAdded = 0
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export {
|
|
120
|
+
type ActualLineItemSnapshot,
|
|
121
|
+
ActualLineItem as default
|
|
122
122
|
}
|
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
import { enableStaticRendering } from 'mobx-react-lite'
|
|
2
|
-
|
|
3
|
-
import type { CommerceService, Family, CategoryNode, SelectionUISpecifier, CommerceConfig } from '../../../types'
|
|
4
|
-
import StandaloneService, {type StandaloneServiceOptions} from './standalone-service'
|
|
5
|
-
import { initSelectionUI } from '../../../util'
|
|
6
|
-
|
|
7
|
-
import { readSnapshot, listenAndWriteSnapshots } from './localStorage'
|
|
8
|
-
|
|
9
|
-
enableStaticRendering(typeof window === "undefined")
|
|
10
|
-
|
|
11
|
-
const _log = (s: string) => {
|
|
12
|
-
const d = new Date()
|
|
13
|
-
console.log(`TIMESTAMPED: ${d.getUTCMinutes()}:${d.getUTCSeconds()}:${d.getUTCMilliseconds()}`)
|
|
14
|
-
console.log(s)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// https://dev.to/ivandotv/mobx-server-side-rendering-with-next-js-4m18
|
|
18
|
-
|
|
19
|
-
let instance: StandaloneService | undefined = undefined
|
|
20
|
-
|
|
21
|
-
export const getInstance = ({
|
|
22
|
-
families,
|
|
23
|
-
rootNode,
|
|
24
|
-
options,
|
|
25
|
-
uiSpecifiers
|
|
26
|
-
}: CommerceConfig) : CommerceService => {
|
|
27
|
-
|
|
28
|
-
if (!options) {
|
|
29
|
-
throw new Error('cmmc getInstance(): Standalone Commerce Service requires config options!')
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (typeof window === "undefined") {
|
|
33
|
-
if (uiSpecifiers) {
|
|
34
|
-
initSelectionUI(uiSpecifiers)
|
|
35
|
-
}
|
|
36
|
-
//_log("NEW INSTANCE FOR SERVER")
|
|
37
|
-
return new StandaloneService(
|
|
38
|
-
families,
|
|
39
|
-
rootNode,
|
|
40
|
-
options
|
|
41
|
-
)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Client side, create the store only once in the client
|
|
45
|
-
if (!instance) {
|
|
46
|
-
if (uiSpecifiers) {
|
|
47
|
-
initSelectionUI(uiSpecifiers)
|
|
48
|
-
}
|
|
49
|
-
//_log("NEW INSTANCE FOR CLIENT")
|
|
50
|
-
const snapShot = readSnapshot()
|
|
51
|
-
instance = new StandaloneService(
|
|
52
|
-
families,
|
|
53
|
-
rootNode,
|
|
54
|
-
options,
|
|
55
|
-
snapShot
|
|
56
|
-
)
|
|
57
|
-
listenAndWriteSnapshots(instance)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return instance
|
|
61
|
-
}
|
|
62
|
-
|
|
1
|
+
import { enableStaticRendering } from 'mobx-react-lite'
|
|
2
|
+
|
|
3
|
+
import type { CommerceService, Family, CategoryNode, SelectionUISpecifier, CommerceConfig } from '../../../types'
|
|
4
|
+
import StandaloneService, {type StandaloneServiceOptions} from './standalone-service'
|
|
5
|
+
import { initSelectionUI } from '../../../util'
|
|
6
|
+
|
|
7
|
+
import { readSnapshot, listenAndWriteSnapshots } from './localStorage'
|
|
8
|
+
|
|
9
|
+
enableStaticRendering(typeof window === "undefined")
|
|
10
|
+
|
|
11
|
+
const _log = (s: string) => {
|
|
12
|
+
const d = new Date()
|
|
13
|
+
console.log(`TIMESTAMPED: ${d.getUTCMinutes()}:${d.getUTCSeconds()}:${d.getUTCMilliseconds()}`)
|
|
14
|
+
console.log(s)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// https://dev.to/ivandotv/mobx-server-side-rendering-with-next-js-4m18
|
|
18
|
+
|
|
19
|
+
let instance: StandaloneService | undefined = undefined
|
|
20
|
+
|
|
21
|
+
export const getInstance = ({
|
|
22
|
+
families,
|
|
23
|
+
rootNode,
|
|
24
|
+
options,
|
|
25
|
+
uiSpecifiers
|
|
26
|
+
}: CommerceConfig) : CommerceService => {
|
|
27
|
+
|
|
28
|
+
if (!options) {
|
|
29
|
+
throw new Error('cmmc getInstance(): Standalone Commerce Service requires config options!')
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (typeof window === "undefined") {
|
|
33
|
+
if (uiSpecifiers) {
|
|
34
|
+
initSelectionUI(uiSpecifiers)
|
|
35
|
+
}
|
|
36
|
+
//_log("NEW INSTANCE FOR SERVER")
|
|
37
|
+
return new StandaloneService(
|
|
38
|
+
families,
|
|
39
|
+
rootNode,
|
|
40
|
+
options
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Client side, create the store only once in the client
|
|
45
|
+
if (!instance) {
|
|
46
|
+
if (uiSpecifiers) {
|
|
47
|
+
initSelectionUI(uiSpecifiers)
|
|
48
|
+
}
|
|
49
|
+
//_log("NEW INSTANCE FOR CLIENT")
|
|
50
|
+
const snapShot = readSnapshot()
|
|
51
|
+
instance = new StandaloneService(
|
|
52
|
+
families,
|
|
53
|
+
rootNode,
|
|
54
|
+
options,
|
|
55
|
+
snapShot
|
|
56
|
+
)
|
|
57
|
+
listenAndWriteSnapshots(instance)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return instance
|
|
61
|
+
}
|
|
62
|
+
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import { reaction } from 'mobx'
|
|
2
|
-
import StandaloneService, { type StandaloneServiceSnapshot } from './standalone-service'
|
|
3
|
-
|
|
4
|
-
const LS_KEY = 'lux-cart'
|
|
5
|
-
|
|
6
|
-
const readSnapshot = (): StandaloneServiceSnapshot | undefined => {
|
|
7
|
-
const snapshotAsStr = localStorage.getItem(LS_KEY)
|
|
8
|
-
return snapshotAsStr ? JSON.parse(snapshotAsStr) as StandaloneServiceSnapshot : undefined
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const listenAndWriteSnapshots = (cmmc: StandaloneService): void => {
|
|
12
|
-
|
|
13
|
-
if (typeof window !== 'undefined') {
|
|
14
|
-
reaction(
|
|
15
|
-
() => (cmmc.cartTotal),
|
|
16
|
-
(total) => {
|
|
17
|
-
if (total > 0) {
|
|
18
|
-
const snapshot = cmmc.takeSnapshot()
|
|
19
|
-
// console.log(`CMMC LOCAL STORAGE UPDATE. (CART TOTAL: ${total}`)
|
|
20
|
-
localStorage.setItem(LS_KEY, JSON.stringify(snapshot) )
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
localStorage.removeItem(LS_KEY)
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
)
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export {
|
|
31
|
-
readSnapshot,
|
|
32
|
-
listenAndWriteSnapshots
|
|
33
|
-
}
|
|
34
|
-
|
|
1
|
+
import { reaction } from 'mobx'
|
|
2
|
+
import StandaloneService, { type StandaloneServiceSnapshot } from './standalone-service'
|
|
3
|
+
|
|
4
|
+
const LS_KEY = 'lux-cart'
|
|
5
|
+
|
|
6
|
+
const readSnapshot = (): StandaloneServiceSnapshot | undefined => {
|
|
7
|
+
const snapshotAsStr = localStorage.getItem(LS_KEY)
|
|
8
|
+
return snapshotAsStr ? JSON.parse(snapshotAsStr) as StandaloneServiceSnapshot : undefined
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const listenAndWriteSnapshots = (cmmc: StandaloneService): void => {
|
|
12
|
+
|
|
13
|
+
if (typeof window !== 'undefined') {
|
|
14
|
+
reaction(
|
|
15
|
+
() => (cmmc.cartTotal),
|
|
16
|
+
(total) => {
|
|
17
|
+
if (total > 0) {
|
|
18
|
+
const snapshot = cmmc.takeSnapshot()
|
|
19
|
+
// console.log(`CMMC LOCAL STORAGE UPDATE. (CART TOTAL: ${total}`)
|
|
20
|
+
localStorage.setItem(LS_KEY, JSON.stringify(snapshot) )
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
localStorage.removeItem(LS_KEY)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
readSnapshot,
|
|
32
|
+
listenAndWriteSnapshots
|
|
33
|
+
}
|
|
34
|
+
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { initializeApp, getApps } from 'firebase/app'
|
|
2
|
-
|
|
3
|
-
const firebaseConfig = {
|
|
4
|
-
apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
|
|
5
|
-
authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
|
|
6
|
-
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
|
|
7
|
-
storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET,
|
|
8
|
-
messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
|
|
9
|
-
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
|
|
10
|
-
measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID,
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// Initialize Firebase instance if there isn't one already
|
|
14
|
-
export default getApps().length === 0 ? initializeApp(firebaseConfig) : getApps()[0]
|
|
1
|
+
import { initializeApp, getApps } from 'firebase/app'
|
|
2
|
+
|
|
3
|
+
const firebaseConfig = {
|
|
4
|
+
apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
|
|
5
|
+
authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
|
|
6
|
+
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
|
|
7
|
+
storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET,
|
|
8
|
+
messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
|
|
9
|
+
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
|
|
10
|
+
measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Initialize Firebase instance if there isn't one already
|
|
14
|
+
export default getApps().length === 0 ? initializeApp(firebaseConfig) : getApps()[0]
|