saleor-apps-redis_apl/apps/taxes/src/modules/ui/matcher-section.tsx

91 lines
2.5 KiB
TypeScript
Raw Normal View History

feat: tax code matcher (#564) * feat: :sparkles: add tax-classes-fetcher * refactor: :recycle: add "byId" suffix to crud-settings & remove upsert * feat: :sparkles: add updateMany method to CrudSettingsManager * feat: :sparkles: add avatax & taxjar tax-code-map-repository * refactor: :truck: move to tax-code directory * feat: :sparkles: add getTaxCodes methods to provider clients * refactor: :recycle: extract taxClass and taxCode schema * refactor: :truck: tax-code-map -> tax-code-match * feat: :sparkles: add taxjar-tax-code.service * feat: :sparkles: add avatax-tax-code.service * feat: :sparkles: add taxClass to graphql fragment * feat: :sparkles: use tax codes in calculate taxes * fix: :bug: undefined tax code bug & add tests * build: :construction_worker: add changeset * Update avatax-tax-code-mapper.ts * feat: :sparkles: add routers & get rid of adapters & mappers * refactor: :recycle: logger location -> name * refactor: :recycle: clean up & rephrase logs * refactor: :recycle: remove __typename from query * docs: :bulb: make comments about tax codes more informative * refactor: :recycle: use resolveOptionalOrThrow on tax code description * refactor: :recycle: rename tax-codes -> tax-classes, move and rename tax-code-schema * refactor: :truck: ctx -> authData * refactor: :truck: createUrqlClientFromCtx -> createUrqlClientFromAuthdata * refactor: :recycle: dont spread ctx * docs: :bulb: add comment about fallback tax code * refactor: :recycle: remove ..ctx * fix: :bug: use createGraphQLClient * feat: tax code matcher ui (#658) * feat: :sparkles: use tax codes in calculate taxes * feat: :sparkles: add getTaxCodes methods to provider clients * feat: :sparkles: add matcher tables * feat: :sparkles: add log errors middleware * fix: :loud_sound: fix misleading logs * fix: :bug: ctx appToken bug * feat: :sparkles: add Select override with wrapping label * feat: :sparkles: pre-select match * docs: :bulb: add comments about first connection * docs: :bulb: add comment about redirect * refactor: :fire: duplicate file * feat: :sparkles: add AppCard to tables * feat: :sparkles: add _error to breadcrumbs exceptions * fix: :bug: value not set on data * feat: :goal_net: add error for no channels configured * fix: :bug: replace update with upsert * refactor: :truck: channel-configuration-settings to repository * fix: :bug: updating a channel configuration * fix: :test_tube: fix wrong mock * fix: :bug: duplicating configs * Update cool-turtles-reflect.md
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 = () => {
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 />
</>
);
};