
* feat: ✨ add dummy order-created * refactor: 🔥 unused private-providers-configuration-service * feat: ✨ add dummy order-fulfilled * refactor: 🚚 move provider-config * refactor: 🚚 crudSettingsConfigurator -> crudSettingsManager * refactor: ♻️ [tax-provider].ts -> [tax-provider]-webhook.service.ts * feat: ✨ add dummy createOrder * refactor: ♻️ distinguish between salesOrder and salesInvoice in avatax * refactor: 🚚 [provider]-calculate.ts to [provider]-transform.ts * refactor: 🚚 ResponseTaxPayload to tax-provider-webhook.ts * refactor: 🚚 ResponseTaxPayload -> CalculateTaxesResponse * refactor: ♻️ webhooks with active-tax-provider.service.ts * feat: ✨ add skeleton orderCreate functionality * refactor: ♻️ [provider]-transform.ts -> [provider]-[webhook]-transform.ts * feat: ✨ add order-fulfilled with avatax call * refactor: ♻️ move getActiveTaxProvider to active-tax-provider * refactor: 🏷️ export types for [provider]-client function args * refactor: 🚚 UpdateAppMetadata -> UpdateMetadata * feat: ✨ fulfill order with id from metadata * build: ⬆️ upgrade avatax * feat: ✨ commit transaction on fulfill in avatax * fix: 🐛 return of webhooks to ensure valid retry behavior * refactor: 🚚 [provider]-[webhook]-transform -> [provider]-[webhook]-map * refactor: 🏷️ export types of avatax-calculate-taxes mapPayload * refactor: ♻️ extract address-map to separate function * refactor: ♻️ remove schema.ts * refactor: ♻️ move addressSchema to channels-config.ts * feat: ✨ add tests & placeholder tests for avatax & taxjar maps * refactor: ♻️ throw error if no metadata * refactor: ♻️ change EXTERNAL_ID_KEY to PROVIDER_ORDER_ID_KEY add comments * refactor: ♻️ comments -> it.todo in tests * refactor: 💡 add comment about shipping_item_code * refactor: ✅ add todo items for tests * refactor: ♻️ remove export and add sumLines to taxJarOrderCreated * refactor: ♻️ address-map with avatarAddressFactory * docs: 💡 add comment about MOCKED_SALEOR_PAYLOAD * refactor: ♻️ remove export of mapLines and add to avataxCalculateTaxes * style: 🎨 add newline-after-var warn to eslint-config-saleor * style: 🎨 autofix newline-after-var in taxes * test: ✅ restructure tests according to new naming in address-map * refactor: ♻️ add shippingItemCode to avataxCalculateTaxes wrapper object * refactor: 🚚 payloadProps -> payloadArgs * refactor: ♻️ add Maps suffix to map wrapper objects * refactor: ♻️ remove data: null from ActiveTaxProviderResult * refactor: ♻️ maintain the object hierarchy in tests * refactor: ♻️ refactor webhook responses with WebhookResponseFactory * build: ⬆️ vitest * test: ✅ add tests for get-app-config-test * test: ✅ add tests for getActiveTaxProvider * refactor: ♻️ use address fragment for taxBase and order * refactor: ♻️ rename WebhookResponseFactory -> WebhookResponse * style: 👷 add multiline-comment-style * fix: 🐛 dummy test in get-app-config.test.ts * refactor: ♻️ rename AddressFragment -> Address * refactor: ♻️ use debug instead of error in webhook-response noRetry * refactor: ♻️ refactor as variables in mutation * build: 👷 add changeset * refactor: ♻️ split changesets in two * build: ⬆️ vite * build: ⬆️ vite && vitest in all apps
105 lines
3.7 KiB
TypeScript
105 lines
3.7 KiB
TypeScript
import { FormControlLabel, Grid, Radio, RadioGroup, Typography } from "@material-ui/core";
|
|
import { makeStyles } from "@saleor/macaw-ui";
|
|
import React from "react";
|
|
import { AvataxConfiguration } from "../../avatax/ui/avatax-configuration";
|
|
import { providerConfig, TaxProviderName } from "../../taxes/provider-config";
|
|
import { TaxJarConfiguration } from "../../taxjar/ui/taxjar-configuration";
|
|
import { useInstanceId } from "../../taxes/tax-context";
|
|
import { trpcClient } from "../../trpc/trpc-client";
|
|
import { AppPaper } from "../../ui/app-paper";
|
|
import { ProviderIcon } from "./provider-icon";
|
|
|
|
const providersConfigurationComponent: Record<TaxProviderName, React.ComponentType> = {
|
|
taxjar: TaxJarConfiguration,
|
|
avatax: AvataxConfiguration,
|
|
};
|
|
|
|
const useStyles = makeStyles((theme) => ({
|
|
radioLabel: {
|
|
width: "100%",
|
|
padding: theme.spacing(1),
|
|
border: `1px solid ${theme.palette.divider}`,
|
|
"&:hover": {
|
|
backgroundColor:
|
|
theme.palette.type === "dark" ? theme.palette.primary.dark : theme.palette.grey[50],
|
|
},
|
|
},
|
|
gridItem: {
|
|
display: "flex",
|
|
justifyContent: "center",
|
|
},
|
|
radioLabelActive: {
|
|
backgroundColor:
|
|
theme.palette.type === "dark" ? theme.palette.primary.dark : theme.palette.grey[50],
|
|
},
|
|
iconWithLabel: {
|
|
display: "flex",
|
|
alignItems: "center",
|
|
flexDirection: "column",
|
|
gap: theme.spacing(1),
|
|
},
|
|
}));
|
|
|
|
export const Configuration = () => {
|
|
const [provider, setProvider] = React.useState<TaxProviderName>("taxjar");
|
|
const { instanceId } = useInstanceId();
|
|
const { data: providersConfigurationData } = trpcClient.providersConfiguration.getAll.useQuery();
|
|
const styles = useStyles();
|
|
|
|
React.useEffect(() => {
|
|
const instance = providersConfigurationData?.find((instance) => instance.id === instanceId);
|
|
|
|
setProvider(instance?.provider ?? "taxjar");
|
|
}, [instanceId, providersConfigurationData]);
|
|
|
|
const SelectedConfigurationForm = React.useMemo(
|
|
() => (provider ? providersConfigurationComponent[provider] : () => null),
|
|
[provider]
|
|
);
|
|
|
|
return (
|
|
<AppPaper>
|
|
{!instanceId && (
|
|
<Grid container spacing={2}>
|
|
<Grid item xs={12}>
|
|
<div className={styles.gridItem}>
|
|
<Typography component="h3" variant="h3">
|
|
Please select one of the providers:
|
|
</Typography>
|
|
</div>
|
|
</Grid>
|
|
<Grid item xs={12}>
|
|
<RadioGroup
|
|
value={provider ?? ""}
|
|
onChange={(e) => setProvider(e.target.value as TaxProviderName)}
|
|
>
|
|
<Grid container justifyContent="center">
|
|
{Object.entries(providerConfig).map(([name, config]) => (
|
|
<Grid className={styles.gridItem} item xs={6} key={name}>
|
|
<FormControlLabel
|
|
className={
|
|
provider === name
|
|
? `${styles.radioLabelActive} ${styles.radioLabel}`
|
|
: styles.radioLabel
|
|
}
|
|
control={<Radio style={{ display: "none" }} name="provider" value={name} />}
|
|
label={
|
|
<div className={styles.iconWithLabel}>
|
|
<ProviderIcon size={"xlarge"} provider={name as TaxProviderName} />
|
|
<Typography variant="body1">{config.label}</Typography>
|
|
</div>
|
|
}
|
|
labelPlacement="top"
|
|
aria-label={config.label}
|
|
/>
|
|
</Grid>
|
|
))}
|
|
</Grid>
|
|
</RadioGroup>
|
|
</Grid>
|
|
</Grid>
|
|
)}
|
|
<SelectedConfigurationForm />
|
|
</AppPaper>
|
|
);
|
|
};
|