File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22import { Button } from "@ui/atoms/button"
33import { useRouter } from "next/navigation"
44import { useEffect , useRef } from "react"
5+ import { useClientReady } from "@/hooks/use-client-ready"
56import { useAnalytics } from "@/providers/analytics-provider"
67import type { PplAccessPointData } from "@/utils/address-helpers"
78import { accessPointToShippingData } from "@/utils/address-helpers"
@@ -16,13 +17,30 @@ import {
1617} from "./_context/checkout-context"
1718
1819export default function CheckoutPage ( ) {
20+ const isClientReady = useClientReady ( )
21+
22+ if ( ! isClientReady ) {
23+ return < CheckoutLoadingState />
24+ }
25+
1926 return (
2027 < CheckoutProvider >
2128 < CheckoutContent />
2229 </ CheckoutProvider >
2330 )
2431}
2532
33+ function CheckoutLoadingState ( ) {
34+ return (
35+ < div className = "container mx-auto p-500" >
36+ < h1 className = "font-bold text-2xl text-fg-primary" > Načítání pokladny</ h1 >
37+ < p className = "mt-200 text-fg-secondary" >
38+ Načítám obsah košíku a checkout data.
39+ </ p >
40+ </ div >
41+ )
42+ }
43+
2644function CheckoutContent ( ) {
2745 const router = useRouter ( )
2846 const {
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { Icon } from "@techsio/ui-kit/atoms/icon"
44import { Popover } from "@techsio/ui-kit/molecules/popover"
55import { Suspense } from "react"
66import { ErrorBoundary } from "@/components/error-boundary"
7+ import { useClientReady } from "@/hooks/use-client-ready"
78import { cartFlow } from "@/hooks/storefront-preset"
89import { CartContent } from "./cart-content"
910import { CartEmptyState } from "./cart-empty-state"
@@ -12,6 +13,7 @@ import { useHeaderContext } from "./store/header-context"
1213
1314export const CartPopover = ( ) => {
1415 const { toggleCart, setIsCartOpen } = useHeaderContext ( )
16+ const isClientReady = useClientReady ( )
1517
1618 const handleHover = ( ) => {
1719 toggleCart ( )
@@ -25,9 +27,13 @@ export const CartPopover = () => {
2527 < ErrorBoundary
2628 fallback = { < CartPopoverErrorFallback onClose = { toggleCart } /> }
2729 >
28- < Suspense fallback = { < CartPopoverLoadingFallback /> } >
29- < CartPopoverContent onClose = { toggleCart } />
30- </ Suspense >
30+ { isClientReady ? (
31+ < Suspense fallback = { < CartPopoverLoadingFallback /> } >
32+ < CartPopoverContent onClose = { toggleCart } />
33+ </ Suspense >
34+ ) : (
35+ < CartPopoverLoadingFallback />
36+ ) }
3137 </ ErrorBoundary >
3238 </ div >
3339 )
Original file line number Diff line number Diff line change 1+ "use client"
2+
3+ import { useEffect , useState } from "react"
4+
5+ export function useClientReady ( ) : boolean {
6+ const [ isClientReady , setIsClientReady ] = useState ( false )
7+
8+ useEffect ( ( ) => {
9+ setIsClientReady ( true )
10+ } , [ ] )
11+
12+ return isClientReady
13+ }
You can’t perform that action at this time.
0 commit comments