Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Make country list global component

dominik-zeglenfb88e46a6797
diff --git a/saleor/static/dashboard-next/discounts/components/VoucherCountries/VoucherCountries.tsx b/saleor/static/dashboard-next/components/CountryList/CountryList.tsx
similarity index 70%
rename from saleor/static/dashboard-next/discounts/components/VoucherCountries/VoucherCountries.tsx
rename to saleor/static/dashboard-next/components/CountryList/CountryList.tsx
index a970b5f3dc..6435d37276 100644
--- a/saleor/static/dashboard-next/discounts/components/VoucherCountries/VoucherCountries.tsx
+++ b/saleor/static/dashboard-next/components/CountryList/CountryList.tsx
@@ -11,22 +11,23 @@ import Table from "@material-ui/core/Table";
import TableBody from "@material-ui/core/TableBody";
import TableCell from "@material-ui/core/TableCell";
import TableRow from "@material-ui/core/TableRow";
-import Typography from "@material-ui/core/Typography";
import ArrowDropDownIcon from "@material-ui/icons/ArrowDropDown";
import CloseIcon from "@material-ui/icons/Close";
import classNames from "classnames";
import * as React from "react";
-import CardTitle from "../../../components/CardTitle";
-import Skeleton from "../../../components/Skeleton";
-import Toggle from "../../../components/Toggle";
-import i18n from "../../../i18n";
-import { maybe, renderCollection } from "../../../misc";
-import { VoucherDetails_voucher } from "../../types/VoucherDetails";
+import CardTitle from "../../components/CardTitle";
+import Skeleton from "../../components/Skeleton";
+import Toggle from "../../components/Toggle";
+import i18n from "../../i18n";
+import { maybe, renderCollection } from "../../misc";
+import { CountryFragment } from "../../taxes/types/CountryFragment";
-export interface VoucherCountriesProps {
+export interface CountryListProps {
+ countries: CountryFragment[];
disabled: boolean;
- voucher: VoucherDetails_voucher;
+ emptyText: React.ReactNode;
+ title: React.ReactNode;
onCountryAssign: () => void;
onCountryUnassign: (country: string) => void;
}
@@ -36,9 +37,6 @@ const styles = (theme: Theme) =>
arrow: {
marginRight: theme.spacing.unit * 1.5
},
- caption: {
- marginTop: theme.spacing.unit
- },
pointer: {
cursor: "pointer"
},
@@ -53,30 +51,23 @@ const styles = (theme: Theme) =>
}
});
-const VoucherCountries = withStyles(styles, {
- name: "VoucherCountries"
+const CountryList = withStyles(styles, {
+ name: "CountryList"
})(
({
classes,
+ countries,
disabled,
- voucher,
+ emptyText,
+ title,
onCountryAssign,
onCountryUnassign
- }: VoucherCountriesProps & WithStyles<typeof styles>) => (
+ }: CountryListProps & WithStyles<typeof styles>) => (
<Toggle initial={true}>
{(isCollapsed, { toggle: toggleCollapse }) => (
<Card>
<CardTitle
- title={
- <>
- {i18n.t("Countries assigned to {{ voucherName }}", {
- voucherName: maybe(() => voucher.name)
- })}
- <Typography className={classes.caption} variant="caption">
- {i18n.t("Vouchers limited to these countries")}
- </Typography>
- </>
- }
+ title={title}
toolbar={
<Button
variant="flat"
@@ -93,10 +84,7 @@ const VoucherCountries = withStyles(styles, {
<TableCell className={classes.wideColumn}>
{i18n.t("{{ number }} Countries", {
context: "number of countries",
- number: maybe(
- () => voucher.countries.length.toString(),
- "..."
- )
+ number: maybe(() => countries.length.toString(), "...")
})}
</TableCell>
<TableCell className={classes.textRight}>
@@ -110,7 +98,7 @@ const VoucherCountries = withStyles(styles, {
</TableRow>
{!isCollapsed &&
renderCollection(
- maybe(() => voucher.countries),
+ countries,
country => (
<TableRow key={country ? country.code : "skeleton"}>
<TableCell>
@@ -131,9 +119,7 @@ const VoucherCountries = withStyles(styles, {
),
() => (
<TableRow>
- <TableCell colSpan={2}>
- {i18n.t("Voucher applies to all countries")}
- </TableCell>
+ <TableCell colSpan={2}>{emptyText}</TableCell>
</TableRow>
)
)}
@@ -144,4 +130,4 @@ const VoucherCountries = withStyles(styles, {
</Toggle>
)
);
-export default VoucherCountries;
+export default CountryList;
diff --git a/saleor/static/dashboard-next/components/CountryList/index.ts b/saleor/static/dashboard-next/components/CountryList/index.ts
new file mode 100644
index 0000000000..3ad707c62a
--- /dev/null
+++ b/saleor/static/dashboard-next/components/CountryList/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./CountryList";
+export * from "./CountryList";
diff --git a/saleor/static/dashboard-next/discounts/components/VoucherCountries/index.ts b/saleor/static/dashboard-next/discounts/components/VoucherCountries/index.ts
deleted file mode 100644
index 503b300d5d..0000000000
--- a/saleor/static/dashboard-next/discounts/components/VoucherCountries/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-export { default } from "./VoucherCountries";
-export * from "./VoucherCountries";
diff --git a/saleor/static/dashboard-next/discounts/components/VoucherDetailsPage/VoucherDetailsPage.tsx b/saleor/static/dashboard-next/discounts/components/VoucherDetailsPage/VoucherDetailsPage.tsx
index 7503fc772a..aa3e91a883 100644
--- a/saleor/static/dashboard-next/discounts/components/VoucherDetailsPage/VoucherDetailsPage.tsx
+++ b/saleor/static/dashboard-next/discounts/components/VoucherDetailsPage/VoucherDetailsPage.tsx
@@ -1,8 +1,10 @@
+import Typography from "@material-ui/core/Typography";
import * as React from "react";
import CardSpacer from "../../../components/CardSpacer";
import { ConfirmButtonTransitionState } from "../../../components/ConfirmButton";
import Container from "../../../components/Container";
+import CountryList from "../../../components/CountryList";
import Form from "../../../components/Form";
import Grid from "../../../components/Grid";
import PageHeader from "../../../components/PageHeader";
@@ -20,7 +22,6 @@ import { VoucherDetails_voucher } from "../../types/VoucherDetails";
import DiscountCategories from "../DiscountCategories";
import DiscountCollections from "../DiscountCollections";
import DiscountProducts from "../DiscountProducts";
-import VoucherCountries from "../VoucherCountries";
import VoucherInfo from "../VoucherInfo";
import VoucherOptions from "../VoucherOptions";
import VoucherSummary from "../VoucherSummary";
@@ -220,11 +221,22 @@ const VoucherDetailsPage: React.StatelessComponent<VoucherDetailsPageProps> = ({
)}
</>
) : data.type === VoucherType.SHIPPING ? (
- <VoucherCountries
+ <CountryList
+ countries={maybe(() => voucher.countries)}
disabled={disabled}
+ emptyText={i18n.t("Voucher applies to all countries")}
+ title={
+ <>
+ {i18n.t("Countries assigned to {{ voucherName }}", {
+ voucherName: maybe(() => voucher.name)
+ })}
+ <Typography variant="caption">
+ {i18n.t("Vouchers limited to these countries")}
+ </Typography>
+ </>
+ }
onCountryAssign={onCountryAssign}
onCountryUnassign={onCountryUnassign}
- voucher={voucher}
/>
) : null}
</div>
diff --git a/saleor/static/dashboard-next/taxes/queries.ts b/saleor/static/dashboard-next/taxes/queries.ts
index c0e81489e2..a1292654c8 100644
--- a/saleor/static/dashboard-next/taxes/queries.ts
+++ b/saleor/static/dashboard-next/taxes/queries.ts
@@ -6,6 +6,11 @@ export const countryFragment = gql`
fragment CountryFragment on CountryDisplay {
country
code
+ }
+`;
+export const countryWithTaxesFragment = gql`
+ fragment CountryWithTaxesFragment on CountryDisplay {
+ ...CountryFragment
vat {
standardRate
reducedRates {
@@ -24,7 +29,7 @@ export const shopTaxesFragment = gql`
`;
const countryList = gql`
- ${countryFragment}
+ ${countryWithTaxesFragment}
${shopTaxesFragment}
query CountryList {
shop {
diff --git a/saleor/static/dashboard-next/taxes/types/CountryFragment.ts b/saleor/static/dashboard-next/taxes/types/CountryFragment.ts
index 78ae7cf8d5..25ceb01995 100644
--- a/saleor/static/dashboard-next/taxes/types/CountryFragment.ts
+++ b/saleor/static/dashboard-next/taxes/types/CountryFragment.ts
@@ -1,27 +1,12 @@
/* tslint:disable */
// This file was automatically generated and should not be edited.
-import { TaxRateType } from "./../../types/globalTypes";
-
// ====================================================
// GraphQL fragment: CountryFragment
// ====================================================
-export interface CountryFragment_vat_reducedRates {
- __typename: "ReducedRate";
- rateType: TaxRateType;
- rate: number;
-}
-
-export interface CountryFragment_vat {
- __typename: "VAT";
- standardRate: number | null;
- reducedRates: (CountryFragment_vat_reducedRates | null)[];
-}
-
export interface CountryFragment {
__typename: "CountryDisplay";
country: string;
code: string;
- vat: CountryFragment_vat | null;
}
diff --git a/saleor/static/dashboard-next/taxes/types/CountryList.ts b/saleor/static/dashboard-next/taxes/types/CountryList.ts
index 90393b767b..5da20bf20a 100644
--- a/saleor/static/dashboard-next/taxes/types/CountryList.ts
+++ b/saleor/static/dashboard-next/taxes/types/CountryList.ts
@@ -1,29 +1,14 @@
/* tslint:disable */
// This file was automatically generated and should not be edited.
-import { TaxRateType } from "./../../types/globalTypes";
-
// ====================================================
// GraphQL query operation: CountryList
// ====================================================
-export interface CountryList_shop_countries_vat_reducedRates {
- __typename: "ReducedRate";
- rateType: TaxRateType;
- rate: number;
-}
-
-export interface CountryList_shop_countries_vat {
- __typename: "VAT";
- standardRate: number | null;
- reducedRates: (CountryList_shop_countries_vat_reducedRates | null)[];
-}
-
export interface CountryList_shop_countries {
__typename: "CountryDisplay";
country: string;
code: string;
- vat: CountryList_shop_countries_vat | null;
}
export interface CountryList_shop {
diff --git a/saleor/static/dashboard-next/taxes/types/CountryWithTaxesFragment.ts b/saleor/static/dashboard-next/taxes/types/CountryWithTaxesFragment.ts
new file mode 100644
index 0000000000..1556608694
--- /dev/null
+++ b/saleor/static/dashboard-next/taxes/types/CountryWithTaxesFragment.ts
@@ -0,0 +1,27 @@
+/* tslint:disable */
+// This file was automatically generated and should not be edited.
+
+import { TaxRateType } from "./../../types/globalTypes";
+
+// ====================================================
+// GraphQL fragment: CountryWithTaxesFragment
+// ====================================================
+
+export interface CountryWithTaxesFragment_vat_reducedRates {
+ __typename: "ReducedRate";
+ rateType: TaxRateType;
+ rate: number;
+}
+
+export interface CountryWithTaxesFragment_vat {
+ __typename: "VAT";
+ standardRate: number | null;
+ reducedRates: (CountryWithTaxesFragment_vat_reducedRates | null)[];
+}
+
+export interface CountryWithTaxesFragment {
+ __typename: "CountryDisplay";
+ country: string;
+ code: string;
+ vat: CountryWithTaxesFragment_vat | null;
+}
diff --git a/saleor/static/dashboard-next/taxes/types/FetchTaxes.ts b/saleor/static/dashboard-next/taxes/types/FetchTaxes.ts
index 95d1f443e7..07c941d67f 100644
--- a/saleor/static/dashboard-next/taxes/types/FetchTaxes.ts
+++ b/saleor/static/dashboard-next/taxes/types/FetchTaxes.ts
@@ -1,8 +1,6 @@
/* tslint:disable */
// This file was automatically generated and should not be edited.
-import { TaxRateType } from "./../../types/globalTypes";
-
// ====================================================
// GraphQL mutation operation: FetchTaxes
// ====================================================
@@ -13,23 +11,10 @@ export interface FetchTaxes_shopFetchTaxRates_errors {
message: string | null;
}
-export interface FetchTaxes_shopFetchTaxRates_shop_countries_vat_reducedRates {
- __typename: "ReducedRate";
- rateType: TaxRateType;
- rate: number;
-}
-
-export interface FetchTaxes_shopFetchTaxRates_shop_countries_vat {
- __typename: "VAT";
- standardRate: number | null;
- reducedRates: (FetchTaxes_shopFetchTaxRates_shop_countries_vat_reducedRates | null)[];
-}
-
export interface FetchTaxes_shopFetchTaxRates_shop_countries {
__typename: "CountryDisplay";
country: string;
code: string;
- vat: FetchTaxes_shopFetchTaxRates_shop_countries_vat | null;
}
export interface FetchTaxes_shopFetchTaxRates_shop {
diff --git a/saleor/static/dashboard-next/types/globalTypes.ts b/saleor/static/dashboard-next/types/globalTypes.ts
index 115ed49d0e..d39496a646 100644
--- a/saleor/static/dashboard-next/types/globalTypes.ts
+++ b/saleor/static/dashboard-next/types/globalTypes.ts
@@ -96,6 +96,11 @@ export enum SaleType {
PERCENTAGE = "PERCENTAGE",
}
+export enum ShippingMethodTypeEnum {
+ PRICE = "PRICE",
+ WEIGHT = "WEIGHT",
+}
+
export enum StockAvailability {
IN_STOCK = "IN_STOCK",
OUT_OF_STOCK = "OUT_OF_STOCK",