@hanzo/commerce 7.0.14 → 7.0.16
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.
|
@@ -26,27 +26,28 @@ const PaymentStepForm: React.FC<CheckoutStepComponentProps> = observer(({
|
|
|
26
26
|
setOrderId
|
|
27
27
|
}) => {
|
|
28
28
|
const cmmc = useCommerce()
|
|
29
|
-
const auth = useAuth()
|
|
29
|
+
const auth = useAuth() // may be null in some cases
|
|
30
|
+
|
|
30
31
|
const [transactionStatus, setTransactionStatus] = useState<TransactionStatus>('unpaid')
|
|
31
32
|
|
|
32
33
|
if (!auth) {
|
|
33
|
-
|
|
34
|
+
console.log("PAYMENT STEP FORM: auth service is null! ")
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
const contactForm = useForm<z.infer<typeof contactFormSchema>>({
|
|
37
38
|
resolver: zodResolver(contactFormSchema),
|
|
38
39
|
defaultValues: {
|
|
39
|
-
name: auth
|
|
40
|
-
email: auth
|
|
40
|
+
name: auth?.user?.displayName ?? '',
|
|
41
|
+
email: auth?.user?.email ?? '',
|
|
41
42
|
},
|
|
42
43
|
})
|
|
43
44
|
|
|
44
45
|
useEffect(() => {
|
|
45
|
-
if (auth
|
|
46
|
-
contactForm.setValue('name', auth
|
|
47
|
-
contactForm.setValue('email', auth
|
|
46
|
+
if (auth?.loggedIn) {
|
|
47
|
+
contactForm.setValue('name', auth!.user?.displayName ?? '')
|
|
48
|
+
contactForm.setValue('email', auth!.user?.email ?? '')
|
|
48
49
|
}
|
|
49
|
-
}, [auth
|
|
50
|
+
}, [auth?.loggedIn])
|
|
50
51
|
|
|
51
52
|
const storePaymentInfo = async (paymentInfo: any) => {
|
|
52
53
|
const {name, email} = contactForm.getValues()
|
package/context/index.tsx
CHANGED
|
@@ -10,10 +10,9 @@ import React, {
|
|
|
10
10
|
import { enableStaticRendering } from 'mobx-react-lite'
|
|
11
11
|
enableStaticRendering(typeof window === "undefined")
|
|
12
12
|
|
|
13
|
-
import type { ServiceOptions } from '..'
|
|
14
13
|
import type CommerceService from '../types/commerce-service'
|
|
15
14
|
import getInstance from '../service/get-instance'
|
|
16
|
-
import type {
|
|
15
|
+
import type { CommerceConfig } from '../types'
|
|
17
16
|
|
|
18
17
|
const CommerceContext = createContext<CommerceService | undefined>(undefined)
|
|
19
18
|
|
|
@@ -22,20 +21,14 @@ const useCommerce = (): CommerceService => {
|
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
const CommerceProvider: React.FC<PropsWithChildren & {
|
|
25
|
-
|
|
26
|
-
rootNode: CategoryNode
|
|
27
|
-
options?: ServiceOptions
|
|
28
|
-
uiSpecs?: Record<string, SelectionUISpecifier>
|
|
24
|
+
config: CommerceConfig
|
|
29
25
|
}> = ({
|
|
30
26
|
children,
|
|
31
|
-
|
|
32
|
-
rootNode,
|
|
33
|
-
options,
|
|
34
|
-
uiSpecs
|
|
27
|
+
config
|
|
35
28
|
}) => {
|
|
36
29
|
|
|
37
30
|
// TODO: Inject Promo fixture here from siteDef
|
|
38
|
-
const service = getInstance(
|
|
31
|
+
const service = getInstance(config)
|
|
39
32
|
const valueRef = useRef<CommerceService>(service)
|
|
40
33
|
|
|
41
34
|
return (
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { enableStaticRendering } from 'mobx-react-lite'
|
|
2
2
|
|
|
3
|
-
import type { CommerceService, Family, CategoryNode, SelectionUISpecifier } from '../../../types'
|
|
3
|
+
import type { CommerceService, Family, CategoryNode, SelectionUISpecifier, CommerceConfig } from '../../../types'
|
|
4
4
|
import StandaloneService, {type StandaloneServiceOptions} from './standalone-service'
|
|
5
5
|
import { initSelectionUI } from '../../../util'
|
|
6
6
|
|
|
@@ -18,20 +18,20 @@ const _log = (s: string) => {
|
|
|
18
18
|
|
|
19
19
|
let instance: StandaloneService | undefined = undefined
|
|
20
20
|
|
|
21
|
-
export const getInstance = (
|
|
22
|
-
families
|
|
23
|
-
rootNode
|
|
24
|
-
options
|
|
25
|
-
|
|
26
|
-
): CommerceService => {
|
|
21
|
+
export const getInstance = ({
|
|
22
|
+
families,
|
|
23
|
+
rootNode,
|
|
24
|
+
options,
|
|
25
|
+
uiSpecifiers
|
|
26
|
+
}: CommerceConfig) : CommerceService => {
|
|
27
27
|
|
|
28
28
|
if (!options) {
|
|
29
29
|
throw new Error('cmmc getInstance(): Standalone Commerce Service requires config options!')
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
if (typeof window === "undefined") {
|
|
33
|
-
if (
|
|
34
|
-
initSelectionUI(
|
|
33
|
+
if (uiSpecifiers) {
|
|
34
|
+
initSelectionUI(uiSpecifiers)
|
|
35
35
|
}
|
|
36
36
|
//_log("NEW INSTANCE FOR SERVER")
|
|
37
37
|
return new StandaloneService(
|
|
@@ -43,8 +43,8 @@ export const getInstance = (
|
|
|
43
43
|
|
|
44
44
|
// Client side, create the store only once in the client
|
|
45
45
|
if (!instance) {
|
|
46
|
-
if (
|
|
47
|
-
initSelectionUI(
|
|
46
|
+
if (uiSpecifiers) {
|
|
47
|
+
initSelectionUI(uiSpecifiers)
|
|
48
48
|
}
|
|
49
49
|
//_log("NEW INSTANCE FOR CLIENT")
|
|
50
50
|
const snapShot = readSnapshot()
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ServiceOptions } from '..'
|
|
2
|
+
import type { CategoryNode } from './category-node'
|
|
3
|
+
import type { Family } from './family'
|
|
4
|
+
import type { SelectionUISpecifier } from './selection-ui-specifier'
|
|
5
|
+
|
|
6
|
+
interface CommerceConfig {
|
|
7
|
+
families: Family[]
|
|
8
|
+
rootNode: CategoryNode
|
|
9
|
+
options?: ServiceOptions
|
|
10
|
+
uiSpecifiers?: Record<string, SelectionUISpecifier>
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { type CommerceConfig as default }
|
package/types/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
export type { default as CommerceService } from './commerce-service'
|
|
3
|
+
export type { default as CommerceConfig } from './commerce-config'
|
|
3
4
|
export type { default as MultiFamilySelectorProps } from './multi-family-selector-props'
|
|
4
5
|
export type { default as Product } from './product'
|
|
5
6
|
export type { default as Promo } from './promo'
|