@hanzo/commerce 4.9.0 → 5.0.0

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.
Files changed (37) hide show
  1. package/components/add-to-cart-widget.tsx +0 -1
  2. package/components/{checkout-panel/cart-accordian.tsx → cart-accordian.tsx} +18 -9
  3. package/components/cart-panel/cart-line-item.tsx +22 -28
  4. package/components/cart-panel/index.tsx +57 -33
  5. package/components/index.ts +4 -1
  6. package/components/item-carousel.tsx +80 -0
  7. package/components/{checkout-panel/steps/payment/cards/index.tsx → payment-step-form/card-icon-row.tsx} +6 -6
  8. package/components/{checkout-panel/steps/payment → payment-step-form}/cc-button.tsx +1 -1
  9. package/components/payment-step-form/contact-form.tsx +49 -0
  10. package/components/{checkout-panel/steps/payment → payment-step-form}/index.tsx +27 -54
  11. package/components/{checkout-panel/steps/payment/pay-with-bank-transfer.tsx → payment-step-form/methods/bank-transfer.tsx} +17 -17
  12. package/components/{checkout-panel/steps/payment/pay-with-card.tsx → payment-step-form/methods/card.tsx} +8 -20
  13. package/components/{checkout-panel/steps/payment/pay-with-crypto.tsx → payment-step-form/methods/crypto.tsx} +8 -22
  14. package/components/payment-step-form/methods/index.ts +23 -0
  15. package/components/{checkout-panel/steps/shipping-info.tsx → shipping-step-form.tsx} +6 -8
  16. package/package.json +2 -2
  17. package/types/checkout.ts +43 -1
  18. package/types/index.ts +1 -1
  19. package/components/cart-panel/products-carousel.tsx +0 -60
  20. package/components/checkout-panel/_confirm-order.tsx_unused +0 -143
  21. package/components/checkout-panel/close-button.tsx +0 -24
  22. package/components/checkout-panel/desktop.tsx +0 -46
  23. package/components/checkout-panel/icons/bag-icon.tsx +0 -10
  24. package/components/checkout-panel/index.tsx +0 -108
  25. package/components/checkout-panel/mobile.tsx +0 -41
  26. package/components/checkout-panel/steps/payment/contact-info.tsx +0 -56
  27. package/components/checkout-panel/steps/thank-you.tsx +0 -18
  28. package/components/checkout-panel/steps/types.ts +0 -14
  29. /package/components/{checkout-panel/steps/payment/cards → payment-step-form/card-icons}/amex.tsx +0 -0
  30. /package/components/{checkout-panel/steps/payment/cards → payment-step-form/card-icons}/diners-club.tsx +0 -0
  31. /package/components/{checkout-panel/steps/payment/cards → payment-step-form/card-icons}/discover.tsx +0 -0
  32. /package/components/{checkout-panel/steps/payment/cards → payment-step-form/card-icons}/jcb.tsx +0 -0
  33. /package/components/{checkout-panel/steps/payment/cards → payment-step-form/card-icons}/mastercard.tsx +0 -0
  34. /package/components/{checkout-panel/steps/payment/cards → payment-step-form/card-icons}/visa.tsx +0 -0
  35. /package/components/{checkout-panel/icons → payment-step-form/crypto-icons}/btc.tsx +0 -0
  36. /package/components/{checkout-panel/icons → payment-step-form/crypto-icons}/eth.tsx +0 -0
  37. /package/components/{checkout-panel/icons → payment-step-form/crypto-icons}/usdt.tsx +0 -0
@@ -18,14 +18,12 @@ import {
18
18
  toast
19
19
  } from '@hanzo/ui/primitives'
20
20
 
21
- import { useAuth } from '@hanzo/auth/service'
21
+ import Eth from '../crypto-icons/eth'
22
+ import { useCommerce } from '../../../service/context'
23
+ import type { PaymentMethodComponentProps } from '../../../types'
24
+ import { sendFBEvent, sendGAEvent } from '../../../util/analytics'
22
25
 
23
- import Eth from '../../icons/eth'
24
- import { useCommerce } from '../../../../service/context'
25
- import type { TransactionStatus } from '../../../../types'
26
- import ContactInfo from './contact-info'
27
- import type { UseFormReturn } from 'react-hook-form'
28
- import { sendFBEvent, sendGAEvent } from '../../../../util/analytics'
26
+ import ContactForm from '../contact-form'
29
27
 
30
28
  declare global {
31
29
  interface Window{
@@ -33,19 +31,7 @@ declare global {
33
31
  }
34
32
  }
35
33
 
36
- const PayWithCrypto: React.FC<{
37
- onDone: () => void
38
- transactionStatus: TransactionStatus
39
- setTransactionStatus: (status: TransactionStatus) => void
40
- storePaymentInfo: (paymentInfo: any) => Promise<void>
41
- contactForm: UseFormReturn<{
42
- name: string
43
- email: string
44
- }, any, {
45
- name: string
46
- email: string
47
- }>
48
- }> = observer(({
34
+ const PayWithCrypto: React.FC<PaymentMethodComponentProps> = observer(({
49
35
  onDone,
50
36
  transactionStatus,
51
37
  setTransactionStatus,
@@ -53,7 +39,7 @@ const PayWithCrypto: React.FC<{
53
39
  contactForm
54
40
  }) => {
55
41
  const cmmc = useCommerce()
56
- const auth = useAuth()
42
+
57
43
  const [loadingPrice, setLoadingPrice] = useState(false)
58
44
  //const [selectedToken, setSelectedToken] = useState('eth')
59
45
  const [amount, setAmount] = useState<number>()
@@ -188,7 +174,7 @@ const PayWithCrypto: React.FC<{
188
174
  return (
189
175
  <div className='flex flex-col gap-6 mt-6'>
190
176
  <div className='flex flex-col gap-2 w-full'>
191
- <ContactInfo form={contactForm}/>
177
+ <ContactForm form={contactForm}/>
192
178
  <div className='flex gap-2 grid grid-cols-3'>
193
179
  <Select onValueChange={(token) => {/*ONLY ETH setSelectedToken(token) */}} defaultValue='eth'>
194
180
  <SelectTrigger>
@@ -0,0 +1,23 @@
1
+ import type { PaymentMethodDesc } from '../../../types'
2
+
3
+ import Card from './card'
4
+ import Crypto from './crypto'
5
+ import BankTransfer from './bank-transfer'
6
+
7
+ export default [
8
+ {
9
+ value: 'card',
10
+ label: 'Card',
11
+ Comp: Card
12
+ },
13
+ {
14
+ value: 'crypto',
15
+ label: 'Wallet',
16
+ Comp: Crypto
17
+ },
18
+ {
19
+ value: 'bank',
20
+ label: 'Bank Wire',
21
+ Comp: BankTransfer
22
+ },
23
+ ] satisfies PaymentMethodDesc[]
@@ -1,6 +1,5 @@
1
1
  'use client'
2
2
 
3
-
4
3
  import * as z from 'zod'
5
4
  import { useForm } from 'react-hook-form'
6
5
  import { zodResolver } from '@hookform/resolvers/zod'
@@ -12,7 +11,6 @@ import {
12
11
  FormControl,
13
12
  FormField,
14
13
  FormItem,
15
- FormLabel,
16
14
  FormMessage,
17
15
  Select,
18
16
  SelectContent,
@@ -21,12 +19,12 @@ import {
21
19
  SelectValue
22
20
  } from '@hanzo/ui/primitives'
23
21
 
24
- import { useCommerce } from '../../..'
22
+ import { useCommerce } from '../service/context'
25
23
 
26
- import countries from '../../../util/countries'
27
- import { sendGAEvent } from '../../../util/analytics'
24
+ import countries from '../util/countries'
25
+ import { sendGAEvent } from '../util/analytics'
28
26
 
29
- import type { StepComponentProps } from './types'
27
+ import type { CheckoutStepComponentProps } from '../types'
30
28
 
31
29
  const shippingFormSchema = z.object({
32
30
  addressLine1: z.string().min(2, 'Address must be at least 2 characters.'),
@@ -37,7 +35,7 @@ const shippingFormSchema = z.object({
37
35
  country: z.string().min(2, 'Country is invalid.'),
38
36
  })
39
37
 
40
- const ShippingInfo: React.FC<StepComponentProps> = ({
38
+ const ShippingStepForm: React.FC<CheckoutStepComponentProps> = ({
41
39
  orderId,
42
40
  onDone
43
41
  }) => {
@@ -171,4 +169,4 @@ const ShippingInfo: React.FC<StepComponentProps> = ({
171
169
  )
172
170
  }
173
171
 
174
- export default ShippingInfo
172
+ export default ShippingStepForm
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzo/commerce",
3
- "version": "4.9.0",
3
+ "version": "5.0.0",
4
4
  "description": "Library with shopping cart components.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/",
@@ -40,7 +40,7 @@
40
40
  },
41
41
  "peerDependencies": {
42
42
  "@hanzo/auth": "^2.3.2",
43
- "@hanzo/ui": "^3.0.18",
43
+ "@hanzo/ui": "^3.0.19",
44
44
  "@hookform/resolvers": "^3.3.4",
45
45
  "firebase": "^10.8.0",
46
46
  "lucide-react": "^0.307.0",
package/types/checkout.ts CHANGED
@@ -1,6 +1,48 @@
1
+ import type { ComponentType } from 'react'
2
+ import type { UseFormReturn } from 'react-hook-form'
1
3
 
2
4
  type TransactionStatus = 'unpaid' | 'paid' | 'confirmed' | 'error'
3
5
 
6
+ interface CheckoutStepComponentProps {
7
+ onDone: () => void
8
+ orderId: string | undefined
9
+ setOrderId: (orderId: string | undefined) => void
10
+ }
11
+
12
+ interface CheckoutStep {
13
+ name: string
14
+ label?: string
15
+ Comp: ComponentType<CheckoutStepComponentProps>
16
+ }
17
+
18
+ type ContactFormType = UseFormReturn<{
19
+ name: string
20
+ email: string
21
+ }, any, {
22
+ name: string
23
+ email: string
24
+ }>
25
+
26
+ interface PaymentMethodComponentProps {
27
+ onDone: () => void
28
+ transactionStatus: TransactionStatus
29
+ setTransactionStatus: (status: TransactionStatus) => void
30
+ storePaymentInfo: (paymentInfo: any) => Promise<void>
31
+ contactForm: ContactFormType
32
+ }
33
+
34
+ interface PaymentMethodDesc {
35
+ value: string
36
+ label: string
37
+ Comp: ComponentType<PaymentMethodComponentProps>
38
+ }
39
+
40
+
4
41
  export {
5
- type TransactionStatus as default
42
+ type TransactionStatus,
43
+ type CheckoutStepComponentProps,
44
+ type CheckoutStep,
45
+ type PaymentMethodComponentProps,
46
+ type PaymentMethodDesc,
47
+ type ContactFormType
6
48
  }
package/types/index.ts CHANGED
@@ -4,7 +4,7 @@ export type { default as CommerceService } from './commerce-service'
4
4
  export type { default as ItemSelector } from './item-selector'
5
5
  export type { default as Product } from './product'
6
6
 
7
- export type { default as TransactionStatus } from './checkout'
7
+ export * from './checkout'
8
8
  export * from './line-item'
9
9
  export * from './facet'
10
10
  export * from './string-mutator'
@@ -1,60 +0,0 @@
1
- import Spline from '@splinetool/react-spline'
2
-
3
- import {
4
- Carousel,
5
- CarouselContent,
6
- CarouselItem,
7
- CarouselPrevious,
8
- CarouselNext
9
- } from '@hanzo/ui/primitives'
10
- import {
11
- VideoBlockComponent,
12
- ImageBlockComponent,
13
- type ImageBlock,
14
- type Block,
15
- type VideoBlock
16
- } from '@hanzo/ui/blocks'
17
-
18
- import type { LineItem } from '../../types'
19
-
20
- // Carousel content hierarchy: 3D > MP4 > Image
21
- const ProductsCarousel: React.FC<{
22
- items: LineItem[]
23
- }> = ({
24
- items,
25
- }) => (
26
- <Carousel options={{ loop: true }} className='w-full max-w-sm mx-auto px-2' >
27
- <CarouselContent>
28
- {items.map(({title, img, video, animation}, index) => (
29
- <CarouselItem key={index}>
30
- <div className='flex aspect-square items-center justify-center p-6'>
31
- {animation ? (
32
- <Spline
33
- scene={animation}
34
- className='!aspect-[12/10] pointer-events-none !w-auto !h-auto'
35
- />
36
- ) : video ? (
37
- <VideoBlockComponent
38
- block={{blockType: 'video', ...video} satisfies VideoBlock as Block}
39
- />
40
- ) : (
41
- <ImageBlockComponent
42
- block={{
43
- blockType: 'image',
44
- src: img ?? '',
45
- alt: title + ' image',
46
- dim: { w: 250, h: 250 }
47
- } satisfies ImageBlock as Block}
48
- className='m-auto'
49
- />
50
- )}
51
- </div>
52
- </CarouselItem>
53
- ))}
54
- </CarouselContent>
55
- <CarouselPrevious />
56
- <CarouselNext />
57
- </Carousel>
58
- )
59
-
60
- export default ProductsCarousel
@@ -1,143 +0,0 @@
1
- 'use client'
2
- import React from 'react'
3
- import type { UseFormReturn } from 'react-hook-form'
4
- import { BookUser, Lock, User } from 'lucide-react'
5
-
6
- import { ApplyTypography, Button } from '@hanzo/ui/primitives'
7
- import { EnhHeadingBlockComponent, type EnhHeadingBlock } from '@hanzo/ui/blocks'
8
-
9
- const ConfirmOrder: React.FC<{
10
- paymentForm: UseFormReturn<{
11
- name: string;
12
- email: string;
13
- cardName: string;
14
- cardNumber: string;
15
- cardExpiryDate: string;
16
- cardCvc: string;
17
- }, any, {
18
- name: string;
19
- email: string;
20
- cardName: string;
21
- cardNumber: string;
22
- cardExpiryDate: string;
23
- cardCvc: string;
24
- }>,
25
- shippingForm: UseFormReturn<{
26
- firstName: string;
27
- lastName: string;
28
- addressLine1: string;
29
- zipCode: string;
30
- city: string;
31
- country: string;
32
- addressLine2?: string | undefined;
33
- state?: string | undefined;
34
- }, any, {
35
- firstName: string;
36
- lastName: string;
37
- addressLine1: string;
38
- zipCode: string;
39
- city: string;
40
- country: string;
41
- addressLine2?: string | undefined;
42
- state?: string | undefined;
43
- }>,
44
- setStep: (step: number) => void,
45
- onPayClick: () => void
46
- }> = ({
47
- paymentForm,
48
- shippingForm,
49
- setStep,
50
- onPayClick
51
- }) => {
52
-
53
- const paymentFormValues = paymentForm.getValues()
54
- const shippingFormValues = shippingForm.getValues()
55
-
56
- return (
57
- <div className='flex flex-col gap-6'>
58
- <div className='flex gap-4 items-center'>
59
- <User />
60
- <EnhHeadingBlockComponent block={{blockType: 'enh-heading',
61
- heading: { text: `Contact Details`, level: 4 },
62
- } as EnhHeadingBlock}/>
63
- </div>
64
- <EnhHeadingBlockComponent block={{blockType: 'enh-heading',
65
- heading: { text: 'Contact name', level: 6 },
66
- byline: { text: paymentFormValues.name, level: 0 },
67
- } as EnhHeadingBlock}/>
68
- <EnhHeadingBlockComponent block={{blockType: 'enh-heading',
69
- heading: { text: 'Contact email', level: 6 },
70
- byline: { text: paymentFormValues.email, level: 0 },
71
- } as EnhHeadingBlock}/>
72
-
73
- <div className='flex gap-4 items-center'>
74
- <ApplyTypography>
75
- <h4 className='flex gap-4 items-center'><Lock /> Payment Info</h4>
76
- <p>Guaranteed safe & secure checkout.</p>
77
- </ApplyTypography>
78
- </div>
79
- <EnhHeadingBlockComponent block={{blockType: 'enh-heading',
80
- heading: { text: 'Name on card', level: 6 },
81
- byline: { text: paymentFormValues.cardName, level: 0 },
82
- } as EnhHeadingBlock}/>
83
- <EnhHeadingBlockComponent block={{blockType: 'enh-heading',
84
- heading: { text: 'Card number', level: 6 },
85
- byline: { text: paymentFormValues.cardNumber, level: 0 },
86
- } as EnhHeadingBlock}/>
87
- <EnhHeadingBlockComponent block={{blockType: 'enh-heading',
88
- heading: { text: 'Card expiry date', level: 6 },
89
- byline: { text: paymentFormValues.cardExpiryDate, level: 0 },
90
- } as EnhHeadingBlock}/>
91
- <EnhHeadingBlockComponent block={{blockType: 'enh-heading',
92
- heading: { text: 'Card CVC', level: 6 },
93
- byline: { text: paymentFormValues.cardCvc, level: 0 },
94
- } as EnhHeadingBlock}/>
95
-
96
- <div className='flex gap-4 items-center'>
97
- <BookUser />
98
- <EnhHeadingBlockComponent block={{blockType: 'enh-heading',
99
- heading: { text: `Shipping address`, level: 4 },
100
- } as EnhHeadingBlock}/>
101
- </div>
102
- <EnhHeadingBlockComponent block={{blockType: 'enh-heading',
103
- heading: { text: 'First name', level: 6 },
104
- byline: { text: shippingFormValues.firstName, level: 0 },
105
- } as EnhHeadingBlock}/>
106
- <EnhHeadingBlockComponent block={{blockType: 'enh-heading',
107
- heading: { text: 'Last name', level: 6 },
108
- byline: { text: shippingFormValues.lastName, level: 0 },
109
- } as EnhHeadingBlock}/>
110
- <EnhHeadingBlockComponent block={{blockType: 'enh-heading',
111
- heading: { text: 'Address line 1', level: 6 },
112
- byline: { text: shippingFormValues.addressLine1, level: 0 },
113
- } as EnhHeadingBlock}/>
114
- <EnhHeadingBlockComponent block={{blockType: 'enh-heading',
115
- heading: { text: 'Address line 2 (optional)', level: 6 },
116
- byline: { text: shippingFormValues.addressLine2, level: 0 },
117
- } as EnhHeadingBlock}/>
118
- <EnhHeadingBlockComponent block={{blockType: 'enh-heading',
119
- heading: { text: 'Zip code', level: 6 },
120
- byline: { text: shippingFormValues.zipCode, level: 0 },
121
- } as EnhHeadingBlock}/>
122
- <EnhHeadingBlockComponent block={{blockType: 'enh-heading',
123
- heading: { text: 'City', level: 6 },
124
- byline: { text: shippingFormValues.city, level: 0 },
125
- } as EnhHeadingBlock}/>
126
- <EnhHeadingBlockComponent block={{blockType: 'enh-heading',
127
- heading: { text: 'State (optional)', level: 6 },
128
- byline: { text: shippingFormValues.state, level: 0 },
129
- } as EnhHeadingBlock}/>
130
- <EnhHeadingBlockComponent block={{blockType: 'enh-heading',
131
- heading: { text: 'Country', level: 6 },
132
- byline: { text: shippingFormValues.country, level: 0 },
133
- } as EnhHeadingBlock}/>
134
-
135
- <div className='flex justify-between mt-8'>
136
- <Button variant='outline' onClick={() => setStep(1)}>Back</Button>
137
- <Button onClick={onPayClick}>Pay</Button>
138
- </div>
139
- </div>
140
- )
141
- }
142
-
143
- export default ConfirmOrder
@@ -1,24 +0,0 @@
1
- 'use client'
2
- import React from 'react'
3
-
4
- import { ChevronLeft } from 'lucide-react'
5
- import { Button } from '@hanzo/ui/primitives'
6
-
7
- const CloseButton: React.FC<{
8
- close: () => void
9
- className?: string
10
- }> = ({
11
- close,
12
- className=''
13
- }) => (
14
- <Button
15
- variant='ghost'
16
- size='icon'
17
- onClick={close}
18
- className={'group ' + className}
19
- >
20
- <ChevronLeft className='w-5 h-5 group-hover:scale-110 transition-scale transition-duration-300'/>
21
- </Button>
22
- )
23
-
24
- export default CloseButton
@@ -1,46 +0,0 @@
1
- 'use client'
2
- import React, { type PropsWithChildren } from 'react'
3
-
4
- import { ScrollArea, StepIndicator } from '@hanzo/ui/primitives'
5
- import { AuthWidget } from '@hanzo/auth/components'
6
-
7
- import CartPanel from '../cart-panel'
8
- import CloseButton from './close-button'
9
-
10
- const DesktopPanel: React.FC<PropsWithChildren & {
11
- index: number
12
- stepNames: string[]
13
- close:() => void
14
- className?: string
15
- }> = ({
16
- index,
17
- stepNames,
18
- close,
19
- className='',
20
- children
21
- }) => (
22
- <div /* id='DT-GRID' */ className={className}>
23
- <div className='w-full bg-background flex flex-row items-start justify-end'>
24
- <ScrollArea className='h-full w-full max-w-[750px] relative flex flex-col items-center justify-start px-6 pt-12 pb-9'>
25
- <CloseButton close={close} className='absolute top-3 left-3 w-auto h-auto rounded-full bg-level-1 hover:bg-level-2 hover:border-muted p-2' />
26
- <CartPanel showCarousel className='flex border-none mt-10 w-full max-w-[550px] flex-col' />
27
- </ScrollArea>
28
- </div>
29
- <ScrollArea className='w-full h-full bg-level-1 flex flex-row items-start justify-start overflow-y-auto'>
30
- <div className='h-full w-full max-w-[750px] relative flex flex-col items-center gap-6 px-8 pb-6 pt-0'>
31
- <AuthWidget noLogin className='hidden md:flex absolute top-4 right-4 '/>
32
- <div className='bg-level-1 sticky h-[90px] pb-2 w-full top-0 flex justify-center items-end'>
33
- <StepIndicator
34
- dotSizeRem={1.5}
35
- steps={stepNames}
36
- currentStep={index}
37
- className='gap-2 text-base w-pr-70 '
38
- />
39
- </div>
40
- {children}
41
- </div>
42
- </ScrollArea>
43
- </div>
44
- )
45
-
46
- export default DesktopPanel
@@ -1,10 +0,0 @@
1
- import React from 'react'
2
- import { type LucideProps } from 'lucide-react'
3
-
4
- const BagIcon: React.FC<LucideProps> = (props: LucideProps) => (
5
- <svg fill="currentColor" viewBox='0 0 20 23' {...props}>
6
- <path fillRule="evenodd" d="M5 5a5 5 0 0 1 10 0v1h-2V5a3 3 0 1 0-6 0v1H5V5Zm0 1v4h2V6h6v4h2V6h3.5a1 1 0 0 1 1 1v15a1 1 0 0 1-1 1h-17a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1H5Z" clipRule="evenodd"/>
7
- </svg>
8
- )
9
-
10
- export default BagIcon
@@ -1,108 +0,0 @@
1
- 'use client'
2
- import React, { useState } from 'react'
3
-
4
- import { capitalize } from '@hanzo/ui/util'
5
-
6
- import { useCommerce } from '../..'
7
-
8
- import type { CheckoutStep } from './steps/types'
9
- import ShippingInfo from './steps/shipping-info'
10
- import ThankYou from './steps/thank-you'
11
- import Payment from './steps/payment'
12
-
13
- const STEPS = [
14
- {
15
- name: 'payment',
16
- Comp: Payment
17
- },
18
- {
19
- name: 'delivery',
20
- Comp: ShippingInfo
21
- },
22
- {
23
- name: 'done',
24
- label: 'Done!',
25
- Comp: ThankYou
26
- }
27
- ] satisfies CheckoutStep[]
28
-
29
- const STEP_NAMES = STEPS.map((s) => (s.label ? s.label : capitalize(s.name)))
30
-
31
- import DesktopCP from './desktop'
32
- import MobileCP from './mobile'
33
-
34
- const CheckoutPanel: React.FC<{
35
- close: () => void
36
- className?: string
37
- }> = ({
38
- close,
39
- className=''
40
- }) => {
41
-
42
- const cmmc = useCommerce()
43
-
44
- // For sites that don't initialize cmmc
45
- if (!cmmc) {
46
- return <></>
47
- }
48
- const [stepIndex, setStepIndex] = useState<number>(0)
49
- const [orderId, setOrderId] = useState<string | undefined>(undefined)
50
-
51
- // Step.name or 'first' or 'next' or 'last'
52
- const setStep = (name: string): void => {
53
-
54
- if (name === 'first') {
55
- setStepIndex(0)
56
- }
57
- else if (name === 'last') {
58
- setStepIndex(STEPS.length - 1)
59
- }
60
- else if (name === 'next') {
61
- if (stepIndex < STEPS.length - 2) {
62
- setStepIndex(stepIndex + 1)
63
- }
64
- else {
65
- throw new Error('CheckoutPanel.setStep(): Attempting to advance past last step!')
66
- }
67
- }
68
- else {
69
- const indexFound = STEPS.findIndex((el) => (el.name === name))
70
- if (indexFound !== -1) {
71
- setStepIndex(indexFound)
72
- }
73
- else {
74
- throw new Error('CheckoutPanel.setStep(): Step named ' + name + ' not found!')
75
- }
76
- }
77
- }
78
-
79
- const _close = () => {
80
- setStep('first')
81
- close()
82
- }
83
-
84
- const StepToRender = STEPS[stepIndex].Comp
85
-
86
- return (
87
- <div /* id='CHECKOUT_PANEL' */ className={className} >
88
- <DesktopCP
89
- className='hidden md:flex h-full flex-row justify-center overflow-y-hidden'
90
- close={_close}
91
- index={stepIndex}
92
- stepNames={STEP_NAMES}
93
- >
94
- <StepToRender onDone={() => {setStep('next')}} orderId={orderId} setOrderId={setOrderId}/>
95
- </DesktopCP>
96
- <MobileCP
97
- className='md:hidden h-full overflow-y-auto'
98
- close={_close}
99
- index={stepIndex}
100
- stepNames={STEP_NAMES}
101
- >
102
- <StepToRender onDone={() => {setStep('next')}} orderId={orderId} setOrderId={setOrderId}/>
103
- </MobileCP>
104
- </div>
105
- )
106
- }
107
-
108
- export default CheckoutPanel
@@ -1,41 +0,0 @@
1
- 'use client'
2
- import React, { type PropsWithChildren } from 'react'
3
-
4
- import { StepIndicator } from '@hanzo/ui/primitives'
5
- import { cn } from '@hanzo/ui/util'
6
- import { AuthWidget } from '@hanzo/auth/components'
7
-
8
- import CloseButton from './close-button'
9
- import CartAccordian from './cart-accordian'
10
-
11
- const MobilePanel: React.FC<PropsWithChildren & {
12
- index: number
13
- stepNames: string[]
14
- close:() => void
15
- className?: string
16
- }> = ({
17
- index,
18
- stepNames,
19
- close,
20
- className='',
21
- children
22
- }) => (
23
-
24
- <div /* id='MOBILE_GRID' */ className={cn('bg-background flex flex-col justify-start px-4', className)}>
25
- <div className='sticky top-0 w-full flex flex-row justify-between items-start bg-background'>
26
- <CloseButton close={close} className='rounded-full bg-background hover:bg-background p-1 -ml-3' />
27
- <StepIndicator
28
- dotSizeRem={1}
29
- steps={stepNames}
30
- currentStep={index}
31
- className='text-xs font-semibold w-pr-70 mt-3'
32
- />
33
- {/* Need wrapper div since 'noLogin' returns null if no logged in user */}
34
- <div className='w-10 h-10 flex items-center justify-center'><AuthWidget noLogin className=''/></div>
35
- </div>
36
- <CartAccordian className='flex items-center justify-center py-2 mt-2 w-full' />
37
- {children}
38
- </div>
39
- )
40
-
41
- export default MobilePanel