Fix visibility card
This commit is contained in:
parent
af88d66d11
commit
c5bc5cf579
11 changed files with 179 additions and 104 deletions
|
@ -63,7 +63,11 @@ export const CollectionCreate: React.FC = () => {
|
||||||
backgroundImage: formData.backgroundImage.value,
|
backgroundImage: formData.backgroundImage.value,
|
||||||
backgroundImageAlt: formData.backgroundImageAlt,
|
backgroundImageAlt: formData.backgroundImageAlt,
|
||||||
descriptionJson: JSON.stringify(formData.description),
|
descriptionJson: JSON.stringify(formData.description),
|
||||||
isPublished: formData.isPublished,
|
isPublished:
|
||||||
|
typeof formData.isPublished !== "boolean" &&
|
||||||
|
formData.isPublished === "true"
|
||||||
|
? true
|
||||||
|
: false,
|
||||||
name: formData.name,
|
name: formData.name,
|
||||||
seo: {
|
seo: {
|
||||||
description: formData.seoDescription,
|
description: formData.seoDescription,
|
||||||
|
|
|
@ -148,7 +148,11 @@ export const CollectionDetails: React.StatelessComponent<
|
||||||
const input: CollectionInput = {
|
const input: CollectionInput = {
|
||||||
backgroundImageAlt: formData.backgroundImageAlt,
|
backgroundImageAlt: formData.backgroundImageAlt,
|
||||||
descriptionJson: JSON.stringify(formData.description),
|
descriptionJson: JSON.stringify(formData.description),
|
||||||
isPublished: formData.isPublished,
|
isPublished:
|
||||||
|
typeof formData.isPublished !== "boolean" &&
|
||||||
|
formData.isPublished === "true"
|
||||||
|
? true
|
||||||
|
: false,
|
||||||
name: formData.name,
|
name: formData.name,
|
||||||
publicationDate: formData.publicationDate,
|
publicationDate: formData.publicationDate,
|
||||||
seo: {
|
seo: {
|
||||||
|
|
|
@ -31,8 +31,8 @@ const styles = (theme: Theme) =>
|
||||||
"&$checked": {
|
"&$checked": {
|
||||||
"&:before": {
|
"&:before": {
|
||||||
background: theme.palette.primary.main,
|
background: theme.palette.primary.main,
|
||||||
content: '"\\2713"',
|
|
||||||
color: theme.palette.common.white,
|
color: theme.palette.common.white,
|
||||||
|
content: '"\\2713"',
|
||||||
fontWeight: "bold",
|
fontWeight: "bold",
|
||||||
textAlign: "center"
|
textAlign: "center"
|
||||||
},
|
},
|
||||||
|
@ -74,17 +74,17 @@ const styles = (theme: Theme) =>
|
||||||
disabled: {},
|
disabled: {},
|
||||||
indeterminate: {},
|
indeterminate: {},
|
||||||
root: {
|
root: {
|
||||||
|
"&:hover": {
|
||||||
|
background: fade(theme.palette.primary.main, 0.1)
|
||||||
|
},
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
borderRadius: "100%",
|
borderRadius: "100%",
|
||||||
cursor: "pointer",
|
cursor: "pointer",
|
||||||
display: "flex",
|
display: "flex",
|
||||||
height: 30,
|
height: 30,
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
width: 30,
|
|
||||||
margin: 9,
|
margin: 9,
|
||||||
"&:hover": {
|
width: 30
|
||||||
background: fade(theme.palette.primary.main, 0.1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const Checkbox = withStyles(styles, { name: "Checkbox" })(
|
const Checkbox = withStyles(styles, { name: "Checkbox" })(
|
||||||
|
|
|
@ -21,6 +21,10 @@ const styles = createStyles({
|
||||||
},
|
},
|
||||||
radioLabel: {
|
radioLabel: {
|
||||||
"& > span": {
|
"& > span": {
|
||||||
|
"& > span": {
|
||||||
|
display: "block",
|
||||||
|
fontSize: "12px"
|
||||||
|
},
|
||||||
padding: "6px"
|
padding: "6px"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,6 +34,7 @@ interface RadioGroupFieldProps extends WithStyles<typeof styles> {
|
||||||
choices: Array<{
|
choices: Array<{
|
||||||
value: string;
|
value: string;
|
||||||
label: string | React.ReactNode;
|
label: string | React.ReactNode;
|
||||||
|
secondLabel?: string | React.ReactNode;
|
||||||
}>;
|
}>;
|
||||||
className?: string;
|
className?: string;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
|
@ -72,15 +77,22 @@ export const RadioGroupField = withStyles(styles, {
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
>
|
>
|
||||||
{choices.length > 0 ? (
|
{choices.length > 0 ? (
|
||||||
choices.map(choice => (
|
choices.map(choice => {
|
||||||
|
return (
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
value={choice.value}
|
value={choice.value}
|
||||||
className={classes.radioLabel}
|
className={classes.radioLabel}
|
||||||
control={<Radio color="primary" />}
|
control={<Radio color="primary" />}
|
||||||
label={choice.label}
|
label={
|
||||||
|
<>
|
||||||
|
{choice.label}
|
||||||
|
<span>{choice.secondLabel}</span>
|
||||||
|
</>
|
||||||
|
}
|
||||||
key={choice.value}
|
key={choice.value}
|
||||||
/>
|
/>
|
||||||
))
|
);
|
||||||
|
})
|
||||||
) : (
|
) : (
|
||||||
<MenuItem disabled={true}>
|
<MenuItem disabled={true}>
|
||||||
<FormattedMessage defaultMessage="No results found" />
|
<FormattedMessage defaultMessage="No results found" />
|
||||||
|
|
|
@ -7,12 +7,13 @@ import {
|
||||||
WithStyles
|
WithStyles
|
||||||
} from "@material-ui/core/styles";
|
} from "@material-ui/core/styles";
|
||||||
import TextField from "@material-ui/core/TextField";
|
import TextField from "@material-ui/core/TextField";
|
||||||
|
import Typography from "@material-ui/core/Typography";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { useIntl } from "react-intl";
|
import { useIntl } from "react-intl";
|
||||||
|
|
||||||
import CardTitle from "@saleor/components/CardTitle";
|
import CardTitle from "@saleor/components/CardTitle";
|
||||||
import ControlledSwitch from "@saleor/components/ControlledSwitch";
|
|
||||||
import { FormSpacer } from "@saleor/components/FormSpacer";
|
import { FormSpacer } from "@saleor/components/FormSpacer";
|
||||||
|
import RadioGroupField from "@saleor/components/RadioGroupField";
|
||||||
import useDateLocalize from "@saleor/hooks/useDateLocalize";
|
import useDateLocalize from "@saleor/hooks/useDateLocalize";
|
||||||
import { DateContext } from "../Date/DateContext";
|
import { DateContext } from "../Date/DateContext";
|
||||||
|
|
||||||
|
@ -22,12 +23,25 @@ const styles = (theme: Theme) =>
|
||||||
"& svg": {
|
"& svg": {
|
||||||
fill: theme.palette.primary.main
|
fill: theme.palette.primary.main
|
||||||
},
|
},
|
||||||
marginTop: theme.spacing.unit * 4
|
marginTop: theme.spacing.unit * 3
|
||||||
},
|
},
|
||||||
expandedSwitchContainer: {
|
expandedSwitchContainer: {
|
||||||
|
"& > div": {
|
||||||
|
padding: 0
|
||||||
|
},
|
||||||
marginBottom: 0
|
marginBottom: 0
|
||||||
},
|
},
|
||||||
|
setPublicationDate: {
|
||||||
|
color: theme.palette.primary.main,
|
||||||
|
cursor: "pointer",
|
||||||
|
fontSize: "14px",
|
||||||
|
paddingTop: "15px",
|
||||||
|
textDecoration: "underline"
|
||||||
|
},
|
||||||
switchContainer: {
|
switchContainer: {
|
||||||
|
"& > div": {
|
||||||
|
padding: 0
|
||||||
|
},
|
||||||
marginBottom: -theme.spacing.unit
|
marginBottom: -theme.spacing.unit
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -55,8 +69,60 @@ export const VisibilityCard = withStyles(styles, {
|
||||||
onChange
|
onChange
|
||||||
}: VisibilityCardProps) => {
|
}: VisibilityCardProps) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
const [isPublicationDate, setPublicationDate] = React.useState(
|
||||||
|
publicationDate === null ? true : false
|
||||||
|
);
|
||||||
const localizeDate = useDateLocalize();
|
const localizeDate = useDateLocalize();
|
||||||
const dateNow = React.useContext(DateContext);
|
const dateNow = React.useContext(DateContext);
|
||||||
|
const isPublishedRadio =
|
||||||
|
typeof isPublished !== "boolean"
|
||||||
|
? isPublished
|
||||||
|
: isPublished
|
||||||
|
? "true"
|
||||||
|
: "false";
|
||||||
|
const visibleSecondLabel = publicationDate
|
||||||
|
? isPublished
|
||||||
|
? intl.formatMessage(
|
||||||
|
{
|
||||||
|
defaultMessage: "since {date}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: localizeDate(publicationDate)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
: null
|
||||||
|
: null;
|
||||||
|
const hiddenSecondLabel = publicationDate
|
||||||
|
? isPublished
|
||||||
|
? null
|
||||||
|
: Date.parse(publicationDate) > dateNow
|
||||||
|
? intl.formatMessage(
|
||||||
|
{
|
||||||
|
defaultMessage: "will be visible from {date}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: localizeDate(publicationDate)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
: null
|
||||||
|
: null;
|
||||||
|
|
||||||
|
const visiblilityPickerChoices = [
|
||||||
|
{
|
||||||
|
label: intl.formatMessage({
|
||||||
|
defaultMessage: "Visible"
|
||||||
|
}),
|
||||||
|
secondLabel: visibleSecondLabel,
|
||||||
|
value: "true"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: intl.formatMessage({
|
||||||
|
defaultMessage: "Hidden"
|
||||||
|
}),
|
||||||
|
secondLabel: hiddenSecondLabel,
|
||||||
|
value: "false"
|
||||||
|
}
|
||||||
|
];
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
<CardTitle
|
<CardTitle
|
||||||
|
@ -73,44 +139,26 @@ export const VisibilityCard = withStyles(styles, {
|
||||||
: classes.switchContainer
|
: classes.switchContainer
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<ControlledSwitch
|
<RadioGroupField
|
||||||
name="isPublished"
|
choices={visiblilityPickerChoices}
|
||||||
label={intl.formatMessage({
|
|
||||||
defaultMessage: "Visible"
|
|
||||||
})}
|
|
||||||
uncheckedLabel={intl.formatMessage({
|
|
||||||
defaultMessage: "Hidden"
|
|
||||||
})}
|
|
||||||
secondLabel={
|
|
||||||
publicationDate
|
|
||||||
? isPublished
|
|
||||||
? intl.formatMessage(
|
|
||||||
{
|
|
||||||
defaultMessage: "since {date}"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
date: localizeDate(publicationDate)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
: Date.parse(publicationDate) > dateNow
|
|
||||||
? intl.formatMessage(
|
|
||||||
{
|
|
||||||
defaultMessage: "will be visible from {date}"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
date: localizeDate(publicationDate)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
: null
|
|
||||||
: null
|
|
||||||
}
|
|
||||||
checked={isPublished}
|
|
||||||
onChange={onChange}
|
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
name={"isPublished" as keyof FormData}
|
||||||
|
value={isPublishedRadio}
|
||||||
|
onChange={onChange}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{!isPublished && (
|
{isPublishedRadio === "false" && (
|
||||||
<>
|
<>
|
||||||
|
{!isPublicationDate && (
|
||||||
|
<Typography
|
||||||
|
className={classes.setPublicationDate}
|
||||||
|
onClick={() => setPublicationDate(!isPublicationDate)}
|
||||||
|
>
|
||||||
|
{" "}
|
||||||
|
Set publication date
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
{isPublicationDate && (
|
||||||
<TextField
|
<TextField
|
||||||
error={!!errors.publicationDate}
|
error={!!errors.publicationDate}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
@ -129,6 +177,7 @@ export const VisibilityCard = withStyles(styles, {
|
||||||
shrink: true
|
shrink: true
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
<FormSpacer />
|
<FormSpacer />
|
||||||
|
|
|
@ -53,14 +53,14 @@ const styles = (theme: Theme) =>
|
||||||
marginBottom: theme.spacing.unit * 3
|
marginBottom: theme.spacing.unit * 3
|
||||||
},
|
},
|
||||||
configurationCategory: {
|
configurationCategory: {
|
||||||
borderTop: `solid 1px #eaeaea`,
|
|
||||||
paddingTop: theme.spacing.unit * 3 + "px",
|
|
||||||
[theme.breakpoints.down("md")]: {
|
[theme.breakpoints.down("md")]: {
|
||||||
gridTemplateColumns: "1fr"
|
gridTemplateColumns: "1fr"
|
||||||
},
|
},
|
||||||
|
borderTop: `solid 1px #eaeaea`,
|
||||||
display: "grid",
|
display: "grid",
|
||||||
gridColumnGap: theme.spacing.unit * 4 + "px",
|
gridColumnGap: theme.spacing.unit * 4 + "px",
|
||||||
gridTemplateColumns: "1fr 3fr"
|
gridTemplateColumns: "1fr 3fr",
|
||||||
|
paddingTop: theme.spacing.unit * 3 + "px"
|
||||||
},
|
},
|
||||||
configurationItem: {
|
configurationItem: {
|
||||||
display: "grid",
|
display: "grid",
|
||||||
|
|
|
@ -3,7 +3,6 @@ import Card from "@material-ui/core/Card";
|
||||||
import CardActions from "@material-ui/core/CardActions";
|
import CardActions from "@material-ui/core/CardActions";
|
||||||
import CardContent from "@material-ui/core/CardContent";
|
import CardContent from "@material-ui/core/CardContent";
|
||||||
import { createStyles, withStyles, WithStyles } from "@material-ui/core/styles";
|
import { createStyles, withStyles, WithStyles } from "@material-ui/core/styles";
|
||||||
import Typography from "@material-ui/core/Typography";
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { FormattedMessage, useIntl } from "react-intl";
|
import { FormattedMessage, useIntl } from "react-intl";
|
||||||
|
|
||||||
|
@ -44,7 +43,6 @@ const styles = createStyles({
|
||||||
const CustomerAddress = withStyles(styles, { name: "CustomerAddress" })(
|
const CustomerAddress = withStyles(styles, { name: "CustomerAddress" })(
|
||||||
({
|
({
|
||||||
address,
|
address,
|
||||||
addressNumber,
|
|
||||||
classes,
|
classes,
|
||||||
disabled,
|
disabled,
|
||||||
isDefaultBillingAddress,
|
isDefaultBillingAddress,
|
||||||
|
|
|
@ -54,16 +54,16 @@ export const PageCreate: React.StatelessComponent<PageCreateProps> = () => {
|
||||||
page={null}
|
page={null}
|
||||||
onBack={() => navigate(pageListUrl())}
|
onBack={() => navigate(pageListUrl())}
|
||||||
onRemove={() => undefined}
|
onRemove={() => undefined}
|
||||||
onSubmit={formData =>
|
onSubmit={formData => {
|
||||||
pageCreate({
|
pageCreate({
|
||||||
variables: {
|
variables: {
|
||||||
input: {
|
input: {
|
||||||
contentJson: JSON.stringify(formData.content),
|
contentJson: JSON.stringify(formData.content),
|
||||||
isPublished: formData.isPublished
|
isPublished:
|
||||||
|
typeof formData.isPublished !== "boolean" &&
|
||||||
|
formData.isPublished === "true"
|
||||||
? true
|
? true
|
||||||
: formData.publicationDate === ""
|
: false,
|
||||||
? false
|
|
||||||
: true,
|
|
||||||
publicationDate: formData.isPublished
|
publicationDate: formData.isPublished
|
||||||
? null
|
? null
|
||||||
: formData.publicationDate === ""
|
: formData.publicationDate === ""
|
||||||
|
@ -77,8 +77,8 @@ export const PageCreate: React.StatelessComponent<PageCreateProps> = () => {
|
||||||
title: formData.title
|
title: formData.title
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
|
@ -19,13 +19,13 @@ export interface PageDetailsProps {
|
||||||
params: PageUrlQueryParams;
|
params: PageUrlQueryParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
const createPageInput = (data: FormData): PageInput => ({
|
const createPageInput = (data: FormData): PageInput => {
|
||||||
|
return {
|
||||||
contentJson: JSON.stringify(data.content),
|
contentJson: JSON.stringify(data.content),
|
||||||
isPublished: data.isPublished
|
isPublished:
|
||||||
|
typeof data.isPublished !== "boolean" && data.isPublished === "true"
|
||||||
? true
|
? true
|
||||||
: data.publicationDate === "" || data.publicationDate === null
|
: false,
|
||||||
? false
|
|
||||||
: true,
|
|
||||||
publicationDate: data.isPublished
|
publicationDate: data.isPublished
|
||||||
? null
|
? null
|
||||||
: data.publicationDate === ""
|
: data.publicationDate === ""
|
||||||
|
@ -37,7 +37,8 @@ const createPageInput = (data: FormData): PageInput => ({
|
||||||
},
|
},
|
||||||
slug: data.slug === "" ? null : data.slug,
|
slug: data.slug === "" ? null : data.slug,
|
||||||
title: data.title
|
title: data.title
|
||||||
});
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export const PageDetails: React.StatelessComponent<PageDetailsProps> = ({
|
export const PageDetails: React.StatelessComponent<PageDetailsProps> = ({
|
||||||
id,
|
id,
|
||||||
|
|
|
@ -83,7 +83,11 @@ export const ProductUpdate: React.StatelessComponent<
|
||||||
descriptionJson: JSON.stringify(
|
descriptionJson: JSON.stringify(
|
||||||
formData.description
|
formData.description
|
||||||
),
|
),
|
||||||
isPublished: formData.isPublished,
|
isPublished:
|
||||||
|
typeof formData.isPublished !== "boolean" &&
|
||||||
|
formData.isPublished === "true"
|
||||||
|
? true
|
||||||
|
: false,
|
||||||
name: formData.name,
|
name: formData.name,
|
||||||
productType: formData.productType,
|
productType: formData.productType,
|
||||||
publicationDate:
|
publicationDate:
|
||||||
|
|
|
@ -25,7 +25,10 @@ export function createUpdateHandler(
|
||||||
collections: data.collections,
|
collections: data.collections,
|
||||||
descriptionJson: JSON.stringify(data.description),
|
descriptionJson: JSON.stringify(data.description),
|
||||||
id: product.id,
|
id: product.id,
|
||||||
isPublished: data.isPublished,
|
isPublished:
|
||||||
|
typeof data.isPublished !== "boolean" && data.isPublished === "true"
|
||||||
|
? true
|
||||||
|
: false,
|
||||||
name: data.name,
|
name: data.name,
|
||||||
publicationDate:
|
publicationDate:
|
||||||
data.publicationDate !== "" ? data.publicationDate : null,
|
data.publicationDate !== "" ? data.publicationDate : null,
|
||||||
|
|
Loading…
Reference in a new issue