Skip to content

Commit

Permalink
cmmc: @hanzo/cart --> @hanzo/commerce; @1.0.9; improvements support /…
Browse files Browse the repository at this point in the history
…buy pages (#37)

* @hanzo/cart --> @hanzo/commerce
core: created ObsLineItemRef for arch clarity in certain situations
core: added getFacetsValue to service

admin: move many packages into peerDep
some renaming and cleanup of components
simplified mutators concept in facet widgets (now StringMutator and StringArrayMutator)
created util/useSkuAndFacetParams hook for common buy pages

remove commerceJs from tree for now

* cmmc: bump @1.0.9
  • Loading branch information
artemis-prime authored Mar 2, 2024
1 parent 7d209fd commit 9df9a29
Show file tree
Hide file tree
Showing 24 changed files with 479 additions and 3,614 deletions.
14 changes: 6 additions & 8 deletions packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,21 @@
"clean": "rm -rf dist && rm -rf node_modules"
},
"dependencies": {
"firebase-admin": "^12.0.0"
},
"peerDependencies": {
"@hanzo/ui": "^1.0.8",
"@hookform/resolvers": "^3.3.4",
"firebase": "^10.8.0",
"firebase-admin": "^12.0.0",
"lucide-react": "^0.336.0",
"react-hook-form": "^7.50.1",
"mobx": "^6.12.0",
"mobx-react-lite": "^4.0.5",
"react-hook-form": "^7.50.1",
"zod": "3.21.4"
},
"peerDependencies": {
"next": "^14.1.0",
"react": "^18.2.0"
"react": "^18.2.0",
"zod": "3.21.4"
},
"devDependencies": {
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/react": "^14.2.1",
"@types/react": "^18.2.48",
"cross-fetch": "^4.0.0",
"typescript": "^5.3.3"
Expand Down
197 changes: 0 additions & 197 deletions packages/commerce/components/category-view.tsx

This file was deleted.

44 changes: 14 additions & 30 deletions packages/commerce/components/facet-toggles-widget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,12 @@ import React, { useState } from 'react'
import { ToggleGroup, ToggleGroupItem,} from "@hanzo/ui/primitives"
import { cn } from '@hanzo/ui/util'

import type { FacetValueDesc } from '../../types'
import type { FacetValueDesc, StringMutator, StringArrayMutator } from '../../types'
import FacetImage from './facet-image'

interface FacetMutatorSingle {
val: string | null
set(v: string | null): void
}

interface FacetMutatorMultiple {
val: string[] | null
set(v: string[] | null): void
}

const FacetTogglesWidget: React.FC<{
facetValues: FacetValueDesc[]
mutator: FacetMutatorSingle | FacetMutatorMultiple
mutator: StringMutator | StringArrayMutator
multiple?: boolean
className?: string
isMobile?: boolean
Expand All @@ -34,31 +24,29 @@ const FacetTogglesWidget: React.FC<{
const [last, setLast] = useState<string | undefined>(undefined)

const handleChangeMultiple = (selected: string[]) => {
(mutator as FacetMutatorMultiple).set(selected)
if (selected.length === 1) {
setLast(selected[0])
}
else {
setLast(undefined)
}
(mutator as StringArrayMutator).set(selected)
setLast(selected.length === 1 ? selected[0] : undefined)
}

const handleChangeSingle = (selected: string) => {
(mutator as FacetMutatorSingle).set(selected)
if (selected) {
setLast(selected)
}
(mutator as StringMutator).set(selected)
if (selected) { setLast(selected) }
}

const roundedToSpread: any = {}
if (multiple) {
roundedToSpread.rounded = 'xl'
}

const val = multiple ?
(mutator as StringArrayMutator).get()
:
(mutator as StringMutator).get()

return (
<ToggleGroup
type={multiple ? 'multiple' : 'single'}
value={multiple ? mutator.val as string[] : mutator.val as string}
value={val}
variant='default'
size={isMobile ? 'sm' : 'default'}
onValueChange={multiple ? handleChangeMultiple : handleChangeSingle}
Expand All @@ -76,7 +64,7 @@ const FacetTogglesWidget: React.FC<{
<ToggleGroupItem
key={fv.value}
value={fv.value}
disabled={(last && last === fv.value || fv.value === mutator.val)}
disabled={(last && last === fv.value || fv.value === mutator.get())}
aria-label={`Select ${fv.label}`}
{...roundedToSpread}
>
Expand All @@ -91,8 +79,4 @@ const FacetTogglesWidget: React.FC<{
)
}

export {
FacetTogglesWidget as default,
type FacetMutatorSingle,
type FacetMutatorMultiple
}
export default FacetTogglesWidget
9 changes: 3 additions & 6 deletions packages/commerce/components/facets-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ import React, { type PropsWithChildren } from 'react'

import { cn } from '@hanzo/ui/util'

import type { FacetsDesc } from '../types'
import type { FacetsDesc, StringMutator, StringArrayMutator } from '../types'

import FacetTogglesWidget, {
type FacetMutatorSingle,
type FacetMutatorMultiple
} from './facet-toggles-widget'
import FacetTogglesWidget from './facet-toggles-widget'

const FacetsWidget: React.FC<PropsWithChildren & {
facets: FacetsDesc
facetClassNames?: string[]
mutators: FacetMutatorSingle[] | FacetMutatorMultiple[]
mutators: StringMutator[] | StringArrayMutator[]
multiple?: boolean
isMobile?: boolean
id?: string
Expand Down
6 changes: 3 additions & 3 deletions packages/commerce/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export { default as ProductCard } from './product-card'
export { default as AddToCartWidget } from './add-to-cart-widget'
export { default as Cart } from './cart'
export { default as CartLineItem } from './cart-line-item'
export { default as CategoryView } from './category-view'
export { default as FacetsWidget } from './facets-widget'
export { default as FacetTogglesWidget } from './facet-toggles-widget'
export { default as ProductCard } from './product-card'
export { default as ProductSelectionMobilePicker } from './product-selection-mobile-picker'
export { default as ProductSelectionRadioGroup } from './product-selection-radio-group'
export { default as CategoryAndItemWidget } from './category-and-item-widget'
export { default as SelectCategoryAndItemWidget } from './select-category-and-item-widget'
export { default as SelectItemInCategoryView } from './select-item-in-category-view'
export * as Icons from './Icons'
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const formatItem = (item: LineItem, withQuantity: boolean = false): string => (
`${item.titleAsOption}, ${formatPrice(item.price)}${(withQuantity && item.quantity > 0) ? ` (${item.quantity})` : ''}`
)

const CategoryAndItemWidget: React.FC<{
const SelectCategoryAndItemWidget: React.FC<{
categoryLevel: number
parentLevelToken: string
categoryLevelValues: FacetValueDesc[]
Expand Down Expand Up @@ -56,7 +56,7 @@ const CategoryAndItemWidget: React.FC<{
<FacetTogglesWidget
facetValues={categoryLevelValues}
mutator={{
val: currentFacetToken.get(),
get: currentFacetToken.get, // computed's are accessed through their get()
set: onFacetTokenChanged
}}
/>
Expand All @@ -81,4 +81,4 @@ const CategoryAndItemWidget: React.FC<{
)
})

export default CategoryAndItemWidget
export default SelectCategoryAndItemWidget
Loading

0 comments on commit 9df9a29

Please sign in to comment.