saleor-dashboard/src/taxes/components/CountryList/CountryList.tsx
Dominik Żegleń 935a6f4542
Reduce bundle size (#1103)
* Add analysis tools

* Use deep imports to reduce bundle size

* Remove tslint config

* Remove unused packages

* Remove lodash-es references

* Use root level mui imports

* Remove mui from restricted imports
2021-05-14 10:15:15 +02:00

96 lines
2.7 KiB
TypeScript

import {
Card,
TableBody,
TableCell,
TableHead,
TableRow
} from "@material-ui/core";
import ResponsiveTable from "@saleor/components/ResponsiveTable";
import Skeleton from "@saleor/components/Skeleton";
import { makeStyles } from "@saleor/theme";
import classNames from "classnames";
import React from "react";
import { FormattedMessage } from "react-intl";
import { maybe, renderCollection } from "../../../misc";
import { CountryList_shop_countries } from "../../types/CountryList";
const useStyles = makeStyles(
{
tableRow: {
cursor: "pointer"
},
textRight: {
textAlign: "right"
}
},
{ name: "CountryList" }
);
interface CountryListProps {
countries: CountryList_shop_countries[];
onRowClick: (code: string) => void;
}
const CountryList: React.FC<CountryListProps> = props => {
const { onRowClick, countries } = props;
const classes = useStyles(props);
return (
<Card>
<ResponsiveTable>
<TableHead>
<TableRow>
<TableCell>
<FormattedMessage defaultMessage="Country Code" />
</TableCell>
<TableCell>
<FormattedMessage defaultMessage="Country Name" />
</TableCell>
<TableCell className={classes.textRight}>
<FormattedMessage defaultMessage="Reduced Tax Rates" />
</TableCell>
</TableRow>
</TableHead>
<TableBody>
{renderCollection(
countries,
country => (
<TableRow
className={classNames({
[classes.tableRow]: !!country
})}
hover={!!country}
onClick={!!country ? () => onRowClick(country.code) : undefined}
key={country ? country.code : "skeleton"}
>
<TableCell>
{maybe<React.ReactNode>(() => country.code, <Skeleton />)}
</TableCell>
<TableCell>
{maybe<React.ReactNode>(() => country.country, <Skeleton />)}
</TableCell>
<TableCell className={classes.textRight}>
{maybe<React.ReactNode>(
() => country.vat.reducedRates.length,
<Skeleton />
)}
</TableCell>
</TableRow>
),
() => (
<TableRow>
<TableCell colSpan={3}>
<FormattedMessage defaultMessage="No countries found" />
</TableCell>
</TableRow>
)
)}
</TableBody>
</ResponsiveTable>
</Card>
);
};
CountryList.displayName = "CountryList";
export default CountryList;