The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.
TypeScript b2b-marketplacecomposable-commerceecommerceenterpriseheadless-commercemarketplacemedusamedusajsmulti-vendortypescript
import { ReactNode, useState, Children } from "react";
import { useLoaderData, useParams } from "react-router-dom";
import { WidgetZone } from "@mercurjs/dashboard-shared";
import { SingleColumnPage } from "../../../components/layout/pages";
import { useTaxRegion } from "../../../hooks/api/tax-regions";
import { TaxRegionDetailSection } from "./components/tax-region-detail-section";
import { TaxRegionProvinceSection } from "./components/tax-region-province-section";
import { SingleColumnPageSkeleton } from "../../../components/common/skeleton";
import { TaxRegionOverrideSection } from "./components/tax-region-override-section";
import { TaxRegionSublevelAlert } from "./components/tax-region-sublevel-alert";
import { TaxRegionProviderSection } from "./tax-region-provider-section";
import { taxRegionLoader } from "./loader";
const Root = ({ children }: { children?: ReactNode }) => {
const { id } = useParams();
const [showSublevelRegions, setShowSublevelRegions] = useState(false);
const initialData = useLoaderData() as Awaited<
ReturnType<typeof taxRegionLoader>
>
const {
tax_region: taxRegion,
isLoading,
isError,
error,
} = useTaxRegion(id!, undefined, { initialData })
if (isLoading || !taxRegion) {
return <SingleColumnPageSkeleton sections={4} showJSON />
}
if (isError) {
throw error
}
return Children.count(children) > 0 ? (
<SingleColumnPage data={taxRegion} showJSON showMetadata>
{children}
</SingleColumnPage>
) : (
<SingleColumnPage data={taxRegion} showJSON showMetadata>
<WidgetZone id="tax-regions.detail.main" data={taxRegion}>
<TaxRegionSublevelAlert
taxRegion={taxRegion}
showSublevelRegions={showSublevelRegions}
setShowSublevelRegions={setShowSublevelRegions}
/>
<TaxRegionDetailSection taxRegion={taxRegion} />
<TaxRegionProvinceSection
taxRegion={taxRegion}
showSublevelRegions={showSublevelRegions}
/>
<TaxRegionOverrideSection taxRegion={taxRegion} />
<TaxRegionProviderSection taxRegion={taxRegion} />
</WidgetZone>
</SingleColumnPage>
);
};
export const TaxRegionDetailPage = Object.assign(Root, {
SublevelAlert: TaxRegionSublevelAlert,
DetailSection: TaxRegionDetailSection,
ProvinceSection: TaxRegionProvinceSection,
OverrideSection: TaxRegionOverrideSection,
ProviderSection: TaxRegionProviderSection,
});