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

97 lines
2.7 KiB
TypeScript
Raw Normal View History

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";
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 { maybe, renderCollection } from "../../../misc";
import { CountryList_shop_countries } from "../../types/CountryList";
2019-12-03 15:28:40 +00:00
const useStyles = makeStyles(
{
tableRow: {
cursor: "pointer"
},
textRight: {
textAlign: "right"
}
2019-06-19 14:40:52 +00:00
},
2019-12-03 15:28:40 +00:00
{ name: "CountryList" }
);
2019-06-19 14:40:52 +00:00
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>
2019-11-04 14:25:23 +00:00
<ResponsiveTable>
2019-06-19 14:40:52 +00:00
<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>
2019-11-04 14:25:23 +00:00
</ResponsiveTable>
2019-06-19 14:40:52 +00:00
</Card>
2019-10-30 14:34:24 +00:00
);
};
2019-06-19 14:40:52 +00:00
CountryList.displayName = "CountryList";
export default CountryList;