2019-06-19 14:40:52 +00:00
|
|
|
import Card from "@material-ui/core/Card";
|
|
|
|
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";
|
2020-05-14 09:30:32 +00:00
|
|
|
import ResponsiveTable from "@saleor/components/ResponsiveTable";
|
|
|
|
import Skeleton from "@saleor/components/Skeleton";
|
2021-03-30 07:40:18 +00:00
|
|
|
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";
|
2019-08-26 21:46:15 +00:00
|
|
|
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>
|
2019-08-26 21:46:15 +00:00
|
|
|
<FormattedMessage defaultMessage="Country Code" />
|
2019-06-19 14:40:52 +00:00
|
|
|
</TableCell>
|
|
|
|
<TableCell>
|
2019-08-26 21:46:15 +00:00
|
|
|
<FormattedMessage defaultMessage="Country Name" />
|
2019-06-19 14:40:52 +00:00
|
|
|
</TableCell>
|
|
|
|
<TableCell className={classes.textRight}>
|
2019-08-26 21:46:15 +00:00
|
|
|
<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}>
|
2019-08-26 21:46:15 +00:00
|
|
|
<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;
|