2023-06-20 15:53:27 +00:00
|
|
|
import { Box, Button, Text } from "@saleor/macaw-ui/next";
|
|
|
|
import { trpcClient } from "../trpc/trpc-client";
|
|
|
|
import { AppCard } from "./app-card";
|
|
|
|
import { Section } from "./app-section";
|
|
|
|
import { ProviderLabel } from "./provider-label";
|
|
|
|
import { Table } from "./table";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
|
|
|
const MatcherTable = () => {
|
2023-06-28 13:03:24 +00:00
|
|
|
const { data: connections = [], isLoading } = trpcClient.providersConfiguration.getAll.useQuery();
|
2023-06-20 15:53:27 +00:00
|
|
|
|
|
|
|
const isAvatax = connections.some(({ provider }) => provider === "avatax");
|
|
|
|
const isTaxJar = connections.some(({ provider }) => provider === "taxjar");
|
2023-06-28 13:03:24 +00:00
|
|
|
const isConfigured = isAvatax || isTaxJar;
|
2023-06-20 15:53:27 +00:00
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
return (
|
2023-06-28 13:03:24 +00:00
|
|
|
<AppCard __minHeight={"320px"} height="100%" data-testid="matcher-table">
|
|
|
|
{isLoading ? (
|
|
|
|
<Box height="100%" display={"flex"} alignItems={"center"} justifyContent={"center"}>
|
|
|
|
<Text color="textNeutralSubdued">Loading...</Text>
|
|
|
|
</Box>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
{isConfigured ? (
|
|
|
|
<Table.Container>
|
|
|
|
<Table.THead>
|
|
|
|
<Table.TR>
|
|
|
|
<Table.TH>Provider</Table.TH>
|
|
|
|
</Table.TR>
|
|
|
|
</Table.THead>
|
|
|
|
<Table.TBody>
|
|
|
|
{isAvatax && (
|
|
|
|
<Table.TR>
|
|
|
|
<Table.TD>
|
|
|
|
<ProviderLabel name="avatax" />
|
|
|
|
</Table.TD>
|
|
|
|
<Table.TD>
|
|
|
|
<Box display="flex" justifyContent={"flex-end"}>
|
|
|
|
<Button
|
|
|
|
data-testid="avatax-matcher-configure-button"
|
|
|
|
onClick={() => router.push("/providers/avatax/matcher")}
|
|
|
|
variant="tertiary"
|
|
|
|
>
|
|
|
|
Configure
|
|
|
|
</Button>{" "}
|
|
|
|
</Box>{" "}
|
|
|
|
</Table.TD>
|
|
|
|
</Table.TR>
|
|
|
|
)}
|
|
|
|
{isTaxJar && (
|
|
|
|
<Table.TR>
|
|
|
|
<Table.TD>
|
|
|
|
<ProviderLabel name="taxjar" />
|
|
|
|
</Table.TD>
|
|
|
|
<Table.TD>
|
|
|
|
<Box display="flex" justifyContent={"flex-end"}>
|
|
|
|
<Button
|
|
|
|
data-testid="taxjar-matcher-configure-button"
|
|
|
|
onClick={() => router.push("/providers/taxjar/matcher")}
|
|
|
|
variant="tertiary"
|
|
|
|
>
|
|
|
|
Configure
|
|
|
|
</Button>{" "}
|
|
|
|
</Box>
|
|
|
|
</Table.TD>
|
|
|
|
</Table.TR>
|
|
|
|
)}
|
|
|
|
</Table.TBody>
|
|
|
|
</Table.Container>
|
|
|
|
) : (
|
|
|
|
<Box height="100%" display={"flex"} alignItems={"center"} justifyContent={"center"}>
|
|
|
|
<Text color="textNeutralSubdued">You must configure a tax provider first</Text>
|
|
|
|
</Box>
|
2023-06-20 15:53:27 +00:00
|
|
|
)}
|
2023-06-28 13:03:24 +00:00
|
|
|
</>
|
|
|
|
)}
|
2023-06-20 15:53:27 +00:00
|
|
|
</AppCard>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const Intro = () => {
|
|
|
|
return (
|
|
|
|
<Section.Description
|
2023-06-28 13:03:24 +00:00
|
|
|
data-testid="matcher-intro"
|
2023-06-20 15:53:27 +00:00
|
|
|
title="Tax code matcher"
|
|
|
|
description={
|
|
|
|
<>
|
|
|
|
Tax Code Matcher allows you to map Saleor tax classes to provider tax codes to extend
|
|
|
|
products base tax rate.
|
|
|
|
<Text as="span" display="block" marginY={4}>
|
|
|
|
You need to have at least one provider configured to use this feature.
|
|
|
|
</Text>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const MatcherSection = () => {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Intro />
|
|
|
|
<MatcherTable />
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|