saleor-apps-redis_apl/apps/taxes/src/modules/ui/matcher-section.tsx
Adrian Pilarczyk 09e07995b5
feat: tax code matcher (#564)
* feat:  add tax-classes-fetcher

* refactor: ♻️ add "byId" suffix to crud-settings & remove upsert

* feat:  add updateMany method to CrudSettingsManager

* feat:  add avatax & taxjar tax-code-map-repository

* refactor: 🚚 move to tax-code directory

* feat:  add getTaxCodes methods to provider clients

* refactor: ♻️ extract taxClass and taxCode schema

* refactor: 🚚 tax-code-map -> tax-code-match

* feat:  add taxjar-tax-code.service

* feat:  add avatax-tax-code.service

* feat:  add taxClass to graphql fragment

* feat:  use tax codes in calculate taxes

* fix: 🐛 undefined tax code bug & add tests

* build: 👷 add changeset

* Update avatax-tax-code-mapper.ts

* feat:  add routers & get rid of adapters & mappers

* refactor: ♻️ logger location -> name

* refactor: ♻️ clean up & rephrase logs

* refactor: ♻️ remove __typename from query

* docs: 💡 make comments about tax codes more informative

* refactor: ♻️ use resolveOptionalOrThrow on tax code description

* refactor: ♻️ rename tax-codes -> tax-classes, move and rename tax-code-schema

* refactor: 🚚 ctx -> authData

* refactor: 🚚 createUrqlClientFromCtx -> createUrqlClientFromAuthdata

* refactor: ♻️ dont spread ctx

* docs: 💡 add comment about fallback tax code

* refactor: ♻️ remove ..ctx

* fix: 🐛 use createGraphQLClient

* feat: tax code matcher ui (#658)

* feat:  use tax codes in calculate taxes

* feat:  add getTaxCodes methods to provider clients

* feat:  add matcher tables

* feat:  add log errors middleware

* fix: 🔊 fix misleading logs

* fix: 🐛 ctx appToken bug

* feat:  add Select override with wrapping label

* feat:  pre-select match

* docs: 💡 add comments about first connection

* docs: 💡 add comment about redirect

* refactor: 🔥 duplicate file

* feat:  add AppCard to tables

* feat:  add _error to breadcrumbs exceptions

* fix: 🐛 value not set on data

* feat: 🥅 add error for no channels configured

* fix: 🐛 replace update with upsert

* refactor: 🚚 channel-configuration-settings to repository

* fix: 🐛 updating a channel configuration

* fix: 🧪 fix wrong mock

* fix: 🐛 duplicating configs

* Update cool-turtles-reflect.md
2023-06-20 17:53:27 +02:00

90 lines
2.5 KiB
TypeScript

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 = () => {
const { data: connections = [] } = trpcClient.providersConfiguration.getAll.useQuery();
const isAvatax = connections.some(({ provider }) => provider === "avatax");
const isTaxJar = connections.some(({ provider }) => provider === "taxjar");
const router = useRouter();
return (
<AppCard __minHeight={"320px"} height="100%">
<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
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
onClick={() => router.push("/providers/taxjar/matcher")}
variant="tertiary"
>
Configure
</Button>{" "}
</Box>
</Table.TD>
</Table.TR>
)}
</Table.TBody>
</Table.Container>
</AppCard>
);
};
const Intro = () => {
return (
<Section.Description
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 />
</>
);
};