Fix assign countries dialogs (#1610)
This commit is contained in:
parent
56b48b87ea
commit
8cb665e091
6 changed files with 74 additions and 73 deletions
|
@ -1,7 +1,8 @@
|
||||||
import useForm, { SubmitPromise, UseFormResult } from "@saleor/hooks/useForm";
|
import useForm, { SubmitPromise, UseFormResult } from "@saleor/hooks/useForm";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
export interface FormProps<T> {
|
export interface FormProps<T>
|
||||||
|
extends Omit<React.HTMLProps<HTMLFormElement>, "onSubmit"> {
|
||||||
children: (props: UseFormResult<T>) => React.ReactNode;
|
children: (props: UseFormResult<T>) => React.ReactNode;
|
||||||
confirmLeave?: boolean;
|
confirmLeave?: boolean;
|
||||||
initial?: T;
|
initial?: T;
|
||||||
|
@ -10,7 +11,7 @@ export interface FormProps<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
function Form<T>(props: FormProps<T>) {
|
function Form<T>(props: FormProps<T>) {
|
||||||
const { children, initial, resetOnSubmit, onSubmit } = props;
|
const { children, initial, resetOnSubmit, onSubmit, ...rest } = props;
|
||||||
const renderProps = useForm(initial, onSubmit);
|
const renderProps = useForm(initial, onSubmit);
|
||||||
|
|
||||||
function handleSubmit(event?: React.FormEvent<any>, cb?: () => void) {
|
function handleSubmit(event?: React.FormEvent<any>, cb?: () => void) {
|
||||||
|
@ -32,7 +33,11 @@ function Form<T>(props: FormProps<T>) {
|
||||||
submit();
|
submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
return <form onSubmit={handleSubmit}>{children(renderProps)}</form>;
|
return (
|
||||||
|
<form {...rest} onSubmit={handleSubmit}>
|
||||||
|
{children(renderProps)}
|
||||||
|
</form>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Form.displayName = "Form";
|
Form.displayName = "Form";
|
||||||
|
|
||||||
|
|
|
@ -21,11 +21,13 @@ import ResponsiveTable from "@saleor/components/ResponsiveTable";
|
||||||
// tslint:disable no-submodule-imports
|
// tslint:disable no-submodule-imports
|
||||||
import { ShopInfo_shop_countries } from "@saleor/components/Shop/types/ShopInfo";
|
import { ShopInfo_shop_countries } from "@saleor/components/Shop/types/ShopInfo";
|
||||||
import { buttonMessages } from "@saleor/intl";
|
import { buttonMessages } from "@saleor/intl";
|
||||||
import { makeStyles } from "@saleor/macaw-ui";
|
import useScrollableDialogStyle from "@saleor/styles/useScrollableDialogStyle";
|
||||||
import { filter } from "fuzzaldrin";
|
import { filter } from "fuzzaldrin";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { FormattedMessage, useIntl } from "react-intl";
|
import { FormattedMessage, useIntl } from "react-intl";
|
||||||
|
|
||||||
|
import { useStyles } from "./styles";
|
||||||
|
|
||||||
interface FormData {
|
interface FormData {
|
||||||
allCountries: boolean;
|
allCountries: boolean;
|
||||||
countries: string[];
|
countries: string[];
|
||||||
|
@ -41,29 +43,6 @@ export interface DiscountCountrySelectDialogProps {
|
||||||
onConfirm: (data: FormData) => void;
|
onConfirm: (data: FormData) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const useStyles = makeStyles(
|
|
||||||
theme => ({
|
|
||||||
checkboxCell: {
|
|
||||||
paddingLeft: 0
|
|
||||||
},
|
|
||||||
containerTitle: {
|
|
||||||
padding: theme.spacing(1.25, 0)
|
|
||||||
},
|
|
||||||
container: {
|
|
||||||
maxHeight: 500,
|
|
||||||
paddingTop: 0,
|
|
||||||
marginBottom: theme.spacing(3)
|
|
||||||
},
|
|
||||||
heading: {
|
|
||||||
marginBottom: theme.spacing(1),
|
|
||||||
marginTop: theme.spacing(2)
|
|
||||||
},
|
|
||||||
wideCell: {
|
|
||||||
width: "100%"
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
{ name: "DiscountCountrySelectDialog" }
|
|
||||||
);
|
|
||||||
const DiscountCountrySelectDialog: React.FC<DiscountCountrySelectDialogProps> = props => {
|
const DiscountCountrySelectDialog: React.FC<DiscountCountrySelectDialogProps> = props => {
|
||||||
const {
|
const {
|
||||||
confirmButtonState,
|
confirmButtonState,
|
||||||
|
@ -74,6 +53,7 @@ const DiscountCountrySelectDialog: React.FC<DiscountCountrySelectDialogProps> =
|
||||||
onConfirm
|
onConfirm
|
||||||
} = props;
|
} = props;
|
||||||
const classes = useStyles(props);
|
const classes = useStyles(props);
|
||||||
|
const scrollableDialogClasses = useScrollableDialogStyle();
|
||||||
|
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
|
@ -84,7 +64,11 @@ const DiscountCountrySelectDialog: React.FC<DiscountCountrySelectDialogProps> =
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<Dialog onClose={onClose} open={open} fullWidth maxWidth="sm">
|
<Dialog onClose={onClose} open={open} fullWidth maxWidth="sm">
|
||||||
<Form initial={initialForm} onSubmit={onConfirm}>
|
<Form
|
||||||
|
initial={initialForm}
|
||||||
|
onSubmit={onConfirm}
|
||||||
|
className={scrollableDialogClasses.form}
|
||||||
|
>
|
||||||
{({ data, change }) => {
|
{({ data, change }) => {
|
||||||
const countrySelectionMap = countries.reduce((acc, country) => {
|
const countrySelectionMap = countries.reduce((acc, country) => {
|
||||||
acc[country.code] = !!data.countries.find(
|
acc[country.code] = !!data.countries.find(
|
||||||
|
@ -120,18 +104,17 @@ const DiscountCountrySelectDialog: React.FC<DiscountCountrySelectDialogProps> =
|
||||||
})}
|
})}
|
||||||
fullWidth
|
fullWidth
|
||||||
/>
|
/>
|
||||||
</DialogContent>
|
<FormSpacer />
|
||||||
<Hr />
|
<Hr />
|
||||||
|
<FormSpacer />
|
||||||
<DialogContent className={classes.containerTitle}>
|
<Typography variant="subtitle1">
|
||||||
<Typography className={classes.heading} variant="subtitle1">
|
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
defaultMessage="Countries A to Z"
|
defaultMessage="Countries A to Z"
|
||||||
description="country selection"
|
description="country selection"
|
||||||
/>
|
/>
|
||||||
</Typography>
|
</Typography>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogContent className={classes.container}>
|
<DialogContent className={scrollableDialogClasses.scrollArea}>
|
||||||
<ResponsiveTable>
|
<ResponsiveTable>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{filter(countries, data.query, {
|
{filter(countries, data.query, {
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
import { makeStyles } from "@saleor/macaw-ui";
|
||||||
|
|
||||||
|
export const useStyles = makeStyles(
|
||||||
|
{
|
||||||
|
checkboxCell: {
|
||||||
|
paddingLeft: 0
|
||||||
|
},
|
||||||
|
wideCell: {
|
||||||
|
width: "100%"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ name: "DiscountCountrySelectDialog" }
|
||||||
|
);
|
|
@ -20,11 +20,13 @@ import Hr from "@saleor/components/Hr";
|
||||||
import ResponsiveTable from "@saleor/components/ResponsiveTable";
|
import ResponsiveTable from "@saleor/components/ResponsiveTable";
|
||||||
import { ShopInfo_shop_countries } from "@saleor/components/Shop/types/ShopInfo";
|
import { ShopInfo_shop_countries } from "@saleor/components/Shop/types/ShopInfo";
|
||||||
import { buttonMessages } from "@saleor/intl";
|
import { buttonMessages } from "@saleor/intl";
|
||||||
import { makeStyles } from "@saleor/macaw-ui";
|
import useScrollableDialogStyle from "@saleor/styles/useScrollableDialogStyle";
|
||||||
import { filter } from "fuzzaldrin";
|
import { filter } from "fuzzaldrin";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { FormattedMessage, useIntl } from "react-intl";
|
import { FormattedMessage, useIntl } from "react-intl";
|
||||||
|
|
||||||
|
import { useStyles } from "./styles";
|
||||||
|
|
||||||
interface FormData {
|
interface FormData {
|
||||||
countries: string[];
|
countries: string[];
|
||||||
query: string;
|
query: string;
|
||||||
|
@ -41,32 +43,6 @@ export interface ShippingZoneCountriesAssignDialogProps {
|
||||||
onConfirm: (data: FormData) => void;
|
onConfirm: (data: FormData) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const useStyles = makeStyles(
|
|
||||||
theme => ({
|
|
||||||
checkboxCell: {
|
|
||||||
paddingLeft: 0
|
|
||||||
},
|
|
||||||
heading: {
|
|
||||||
marginBottom: theme.spacing(2),
|
|
||||||
marginTop: theme.spacing(2)
|
|
||||||
},
|
|
||||||
container: {
|
|
||||||
padding: theme.spacing(1.25, 0)
|
|
||||||
},
|
|
||||||
scrollAreaContainer: {
|
|
||||||
maxHeight: 400,
|
|
||||||
padding: theme.spacing(1.25, 0),
|
|
||||||
marginBottom: theme.spacing(3)
|
|
||||||
},
|
|
||||||
table: {
|
|
||||||
border: "1px solid " + theme.palette.grey[200]
|
|
||||||
},
|
|
||||||
wideCell: {
|
|
||||||
width: "100%"
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
{ name: "ShippingZoneCountriesAssignDialog" }
|
|
||||||
);
|
|
||||||
const ShippingZoneCountriesAssignDialog: React.FC<ShippingZoneCountriesAssignDialogProps> = props => {
|
const ShippingZoneCountriesAssignDialog: React.FC<ShippingZoneCountriesAssignDialogProps> = props => {
|
||||||
const {
|
const {
|
||||||
confirmButtonState,
|
confirmButtonState,
|
||||||
|
@ -79,6 +55,7 @@ const ShippingZoneCountriesAssignDialog: React.FC<ShippingZoneCountriesAssignDia
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const classes = useStyles(props);
|
const classes = useStyles(props);
|
||||||
|
const scrollableDialogClasses = useScrollableDialogStyle();
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
const initialForm: FormData = {
|
const initialForm: FormData = {
|
||||||
|
@ -88,7 +65,11 @@ const ShippingZoneCountriesAssignDialog: React.FC<ShippingZoneCountriesAssignDia
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<Dialog onClose={onClose} open={open} fullWidth maxWidth="sm">
|
<Dialog onClose={onClose} open={open} fullWidth maxWidth="sm">
|
||||||
<Form initial={initialForm} onSubmit={onConfirm}>
|
<Form
|
||||||
|
initial={initialForm}
|
||||||
|
onSubmit={onConfirm}
|
||||||
|
className={scrollableDialogClasses.form}
|
||||||
|
>
|
||||||
{({ data, change }) => {
|
{({ data, change }) => {
|
||||||
const countrySelectionMap = countries.reduce((acc, country) => {
|
const countrySelectionMap = countries.reduce((acc, country) => {
|
||||||
acc[country.code] = !!data.countries.find(
|
acc[country.code] = !!data.countries.find(
|
||||||
|
@ -122,13 +103,13 @@ const ShippingZoneCountriesAssignDialog: React.FC<ShippingZoneCountriesAssignDia
|
||||||
})}
|
})}
|
||||||
fullWidth
|
fullWidth
|
||||||
/>
|
/>
|
||||||
</DialogContent>
|
<FormSpacer />
|
||||||
<Hr />
|
<Hr />
|
||||||
|
<FormSpacer />
|
||||||
<DialogContent className={classes.container}>
|
<Typography variant="subtitle1">
|
||||||
<Typography className={classes.heading} variant="subtitle1">
|
|
||||||
<FormattedMessage defaultMessage="Quick Pick" />
|
<FormattedMessage defaultMessage="Quick Pick" />
|
||||||
</Typography>
|
</Typography>
|
||||||
|
<FormSpacer />
|
||||||
<ResponsiveTable className={classes.table}>
|
<ResponsiveTable className={classes.table}>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
|
@ -157,18 +138,15 @@ const ShippingZoneCountriesAssignDialog: React.FC<ShippingZoneCountriesAssignDia
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</ResponsiveTable>
|
</ResponsiveTable>
|
||||||
</DialogContent>
|
<FormSpacer />
|
||||||
|
<Typography variant="subtitle1">
|
||||||
<DialogContent className={classes.container}>
|
|
||||||
<Typography className={classes.heading} variant="subtitle1">
|
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
defaultMessage="Countries A to Z"
|
defaultMessage="Countries A to Z"
|
||||||
description="country selection"
|
description="country selection"
|
||||||
/>
|
/>
|
||||||
</Typography>
|
</Typography>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
|
<DialogContent className={scrollableDialogClasses.scrollArea}>
|
||||||
<DialogContent className={classes.scrollAreaContainer}>
|
|
||||||
<ResponsiveTable className={classes.table}>
|
<ResponsiveTable className={classes.table}>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{filter(countries, data.query, {
|
{filter(countries, data.query, {
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
import { makeStyles } from "@saleor/macaw-ui";
|
||||||
|
|
||||||
|
export const useStyles = makeStyles(
|
||||||
|
theme => ({
|
||||||
|
checkboxCell: {
|
||||||
|
paddingLeft: 0
|
||||||
|
},
|
||||||
|
table: {
|
||||||
|
border: "1px solid " + theme.palette.grey[200]
|
||||||
|
},
|
||||||
|
wideCell: {
|
||||||
|
width: "100%"
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
{ name: "ShippingZoneCountriesAssignDialog" }
|
||||||
|
);
|
|
@ -6,6 +6,12 @@ const useScrollableDialogStyle = makeStyles(
|
||||||
height: "calc(100% - 64px)",
|
height: "calc(100% - 64px)",
|
||||||
maxHeight: 700
|
maxHeight: 700
|
||||||
},
|
},
|
||||||
|
form: {
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "column",
|
||||||
|
height: "100%",
|
||||||
|
overflowY: "auto"
|
||||||
|
},
|
||||||
loadMoreLoaderContainer: {
|
loadMoreLoaderContainer: {
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
display: "flex",
|
display: "flex",
|
||||||
|
|
Loading…
Reference in a new issue