Skip to content

The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.

1.9 KB
Raw Blame
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 { useState } from "react";
import { SingleColumnPageSkeleton } from "@components/common/skeleton";
import { TaxRegionOverrideSection } from "./_components/tax-region-override-section";
import { TaxRegionSublevelAlert } from "./_components/tax-region-sublevel-alert";
import { taxRegionLoader } from "./loader";

const TaxRegionDetail = () => {
  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} />;
  }

  if (isError) {
    throw error;
  }

  return (
    <SingleColumnPage data={taxRegion}>
      <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} />
      </WidgetZone>
    </SingleColumnPage>
  );
};

export const Component = TaxRegionDetail;
export { taxRegionLoader as loader } from "./loader";
export { TaxRegionDetailBreadcrumb as Breadcrumb } from "./breadcrumb";