File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
apps/pyconkr/src/components/layout Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ import * as Shop from "@frontend/shop" ;
2+ import { ShoppingCart } from "@mui/icons-material" ;
3+ import { Badge , badgeClasses , IconButton , styled } from "@mui/material" ;
4+ import { ErrorBoundary , Suspense } from "@suspensive/react" ;
5+ import * as React from "react" ;
6+ import { useNavigate } from "react-router-dom" ;
7+
8+ type InnerCartBadgeButtonPropType = {
9+ loading ?: boolean ;
10+ count ?: number ;
11+ } ;
12+
13+ const InnerCartBadge = styled ( Badge ) ( { [ `& .${ badgeClasses . badge } ` ] : { top : "-12px" , right : "-3px" } } ) ;
14+
15+ const InnerCartBadgeButton : React . FC < InnerCartBadgeButtonPropType > = ( { loading, count } ) => {
16+ const navigate = useNavigate ( ) ;
17+
18+ return (
19+ < IconButton loading = { loading } onClick = { ( ) => navigate ( "/store/cart" ) } >
20+ < ShoppingCart />
21+ { count && < InnerCartBadge badgeContent = { count } color = "primary" overlap = "circular" /> }
22+ </ IconButton >
23+ ) ;
24+ } ;
25+
26+ export const CartBadgeButton : React . FC = Suspense . with (
27+ { fallback : < InnerCartBadgeButton loading /> } ,
28+ ErrorBoundary . with ( { fallback : < InnerCartBadgeButton /> } , ( ) => {
29+ const shopAPIClient = Shop . Hooks . useShopClient ( ) ;
30+ const { data : cart } = Shop . Hooks . useCart ( shopAPIClient ) ;
31+ return < InnerCartBadgeButton count = { cart ?. products . length } loading = { false } /> ;
32+ } )
33+ ) ;
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import * as R from "remeda";
88
99import BackendAPISchemas from "../../../../../../packages/common/src/schemas/backendAPI" ;
1010import { useAppContext } from "../../../contexts/app_context" ;
11+ import { CartBadgeButton } from "../CartBadgeButton" ;
1112import LanguageSelector from "../LanguageSelector" ;
1213import { SignInButton } from "../SignInButton" ;
1314
@@ -129,6 +130,7 @@ const Header: React.FC = () => {
129130 < NavSideElementContainer >
130131 < Stack direction = "row" alignItems = "center" gap = { 1 } sx = { { marginLeft : "auto" } } >
131132 < LanguageSelector />
133+ < CartBadgeButton />
132134 < SignInButton />
133135 </ Stack >
134136 </ NavSideElementContainer >
You can’t perform that action at this time.
0 commit comments