2021-05-14 08:15:15 +00:00
|
|
|
import {
|
|
|
|
Card,
|
|
|
|
TableBody,
|
|
|
|
TableCell,
|
|
|
|
TableHead,
|
|
|
|
TableRow
|
|
|
|
} from "@material-ui/core";
|
2020-05-14 09:30:32 +00:00
|
|
|
import ResponsiveTable from "@saleor/components/ResponsiveTable";
|
|
|
|
import Skeleton from "@saleor/components/Skeleton";
|
2022-03-09 08:56:55 +00:00
|
|
|
import { CountryListQuery } from "@saleor/graphql";
|
2021-07-21 08:59:52 +00:00
|
|
|
import { makeStyles } from "@saleor/macaw-ui";
|
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";
|
|
|
|
|
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 {
|
2022-03-09 08:56:55 +00:00
|
|
|
countries: CountryListQuery["shop"]["countries"];
|
2019-06-19 14:40:52 +00:00
|
|
|
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>
|
2022-05-05 07:54:28 +00:00
|
|
|
<FormattedMessage id="07KB2d" defaultMessage="Country Code" />
|
2019-06-19 14:40:52 +00:00
|
|
|
</TableCell>
|
|
|
|
<TableCell>
|
2022-05-05 07:54:28 +00:00
|
|
|
<FormattedMessage id="0GJfWd" defaultMessage="Country Name" />
|
2019-06-19 14:40:52 +00:00
|
|
|
</TableCell>
|
|
|
|
<TableCell className={classes.textRight}>
|
2022-05-05 07:54:28 +00:00
|
|
|
<FormattedMessage
|
|
|
|
id="/JENWS"
|
|
|
|
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}>
|
2022-05-05 07:54:28 +00:00
|
|
|
<FormattedMessage
|
|
|
|
id="3BTtL2"
|
|
|
|
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;
|