saleor-dashboard/src/taxes/components/CountryList/CountryList.tsx

92 lines
2.8 KiB
TypeScript
Raw Normal View History

2019-06-19 14:40:52 +00:00
import Card from "@material-ui/core/Card";
2019-10-30 14:34:24 +00:00
import { makeStyles } from "@material-ui/core/styles";
2019-06-19 14:40:52 +00:00
import Table from "@material-ui/core/Table";
import TableBody from "@material-ui/core/TableBody";
import TableCell from "@material-ui/core/TableCell";
import TableHead from "@material-ui/core/TableHead";
import TableRow from "@material-ui/core/TableRow";
2019-08-09 11:14:35 +00:00
import classNames from "classnames";
2019-08-09 10:26:22 +00:00
import React from "react";
import { FormattedMessage } from "react-intl";
2019-06-19 14:40:52 +00:00
import Skeleton from "@saleor/components/Skeleton";
import { maybe, renderCollection } from "../../../misc";
import { CountryList_shop_countries } from "../../types/CountryList";
2019-10-30 14:34:24 +00:00
const useStyles = makeStyles({
2019-06-19 14:40:52 +00:00
tableRow: {
cursor: "pointer"
},
textRight: {
textAlign: "right"
}
});
2019-10-30 14:34:24 +00:00
interface CountryListProps {
2019-06-19 14:40:52 +00:00
countries: CountryList_shop_countries[];
onRowClick: (code: string) => void;
}
2019-10-30 14:34:24 +00:00
const CountryList: React.FC<CountryListProps> = props => {
const { onRowClick, countries } = props;
const classes = useStyles(props);
return (
2019-06-19 14:40:52 +00:00
<Card>
<Table>
<TableHead>
<TableRow>
<TableCell>
<FormattedMessage defaultMessage="Country Code" />
2019-06-19 14:40:52 +00:00
</TableCell>
<TableCell>
<FormattedMessage defaultMessage="Country Name" />
2019-06-19 14:40:52 +00:00
</TableCell>
<TableCell className={classes.textRight}>
<FormattedMessage defaultMessage="Reduced Tax Rates" />
2019-06-19 14:40:52 +00:00
</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" />
2019-06-19 14:40:52 +00:00
</TableCell>
</TableRow>
)
)}
</TableBody>
</Table>
</Card>
2019-10-30 14:34:24 +00:00
);
};
2019-06-19 14:40:52 +00:00
CountryList.displayName = "CountryList";
export default CountryList;