'use client'; import { usePathnameWithoutLocale } from '@/core/lib/navigation'; /** * "Which page am I on" checks that hold in every language. * * `usePathnameWithoutLocale()` removes the locale prefix, so `/he/checkout` and * `/checkout` are the same page here. Comparing `usePathname()` against a bare * `/checkout` is the bug this exists to prevent: it works in the default * language and silently stops working in every other one. */ /** `/checkout` and anything under it (`/checkout/...`), locale prefix already removed. */ export function isCheckoutPath(path: string): boolean { return path === '/checkout' || path.startsWith('/checkout/'); } /** `/cart` and `/checkout`, plus anything under them, locale prefix already removed. */ export function isCartOrCheckoutPath(path: string): boolean { return path === '/cart' || path.startsWith('/cart/') || isCheckoutPath(path); } /** True while the shopper is on the checkout page. */ export function useIsCheckoutRoute(): boolean { return isCheckoutPath(usePathnameWithoutLocale()); } /** * True on the cart and checkout pages, where floating widgets (the shopping * assistant) must not sit on top of the order summary, the coupon field or the * pay button. Returns a boolean, not the path, so an effect keyed on it re-runs * only when the answer changes and not on every navigation. */ export function useIsCartOrCheckoutRoute(): boolean { return isCartOrCheckoutPath(usePathnameWithoutLocale()); }