Separate visibility Card messages context
This commit is contained in:
parent
6d0aacd7ce
commit
fdcf2ce872
6 changed files with 124 additions and 31 deletions
|
@ -15,6 +15,7 @@ import PageHeader from "@saleor/components/PageHeader";
|
||||||
import SaveButtonBar from "@saleor/components/SaveButtonBar";
|
import SaveButtonBar from "@saleor/components/SaveButtonBar";
|
||||||
import SeoForm from "@saleor/components/SeoForm";
|
import SeoForm from "@saleor/components/SeoForm";
|
||||||
import VisibilityCard from "@saleor/components/VisibilityCard";
|
import VisibilityCard from "@saleor/components/VisibilityCard";
|
||||||
|
import useDateLocalize from "@saleor/hooks/useDateLocalize";
|
||||||
import { commonMessages, sectionNames } from "@saleor/intl";
|
import { commonMessages, sectionNames } from "@saleor/intl";
|
||||||
import { UserError } from "../../../types";
|
import { UserError } from "../../../types";
|
||||||
import CollectionDetails from "../CollectionDetails/CollectionDetails";
|
import CollectionDetails from "../CollectionDetails/CollectionDetails";
|
||||||
|
@ -66,6 +67,7 @@ const CollectionCreatePage: React.StatelessComponent<
|
||||||
onSubmit
|
onSubmit
|
||||||
}: CollectionCreatePageProps) => {
|
}: CollectionCreatePageProps) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
const localizeDate = useDateLocalize();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form errors={errors} initial={initialForm} onSubmit={onSubmit}>
|
<Form errors={errors} initial={initialForm} onSubmit={onSubmit}>
|
||||||
|
@ -149,7 +151,25 @@ const CollectionCreatePage: React.StatelessComponent<
|
||||||
data={data}
|
data={data}
|
||||||
errors={formErrors}
|
errors={formErrors}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
hiddenMessage={intl.formatMessage(
|
||||||
|
{
|
||||||
|
defaultMessage: "will be visible from {date}",
|
||||||
|
description: "collection"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: localizeDate(data.publicationDate)
|
||||||
|
}
|
||||||
|
)}
|
||||||
onChange={change}
|
onChange={change}
|
||||||
|
visibleMessage={intl.formatMessage(
|
||||||
|
{
|
||||||
|
defaultMessage: "since {date}",
|
||||||
|
description: "collection"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: localizeDate(data.publicationDate)
|
||||||
|
}
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
|
@ -8,11 +8,14 @@ import { ConfirmButtonTransitionState } from "@saleor/components/ConfirmButton";
|
||||||
import { Container } from "@saleor/components/Container";
|
import { Container } from "@saleor/components/Container";
|
||||||
import ControlledCheckbox from "@saleor/components/ControlledCheckbox";
|
import ControlledCheckbox from "@saleor/components/ControlledCheckbox";
|
||||||
import Form from "@saleor/components/Form";
|
import Form from "@saleor/components/Form";
|
||||||
|
import FormSpacer from "@saleor/components/FormSpacer";
|
||||||
import Grid from "@saleor/components/Grid";
|
import Grid from "@saleor/components/Grid";
|
||||||
|
import Hr from "@saleor/components/Hr";
|
||||||
import PageHeader from "@saleor/components/PageHeader";
|
import PageHeader from "@saleor/components/PageHeader";
|
||||||
import SaveButtonBar from "@saleor/components/SaveButtonBar";
|
import SaveButtonBar from "@saleor/components/SaveButtonBar";
|
||||||
import SeoForm from "@saleor/components/SeoForm";
|
import SeoForm from "@saleor/components/SeoForm";
|
||||||
import VisibilityCard from "@saleor/components/VisibilityCard";
|
import VisibilityCard from "@saleor/components/VisibilityCard";
|
||||||
|
import useDateLocalize from "@saleor/hooks/useDateLocalize";
|
||||||
import { sectionNames } from "@saleor/intl";
|
import { sectionNames } from "@saleor/intl";
|
||||||
import { maybe } from "../../../misc";
|
import { maybe } from "../../../misc";
|
||||||
import { ListActions, PageListProps } from "../../../types";
|
import { ListActions, PageListProps } from "../../../types";
|
||||||
|
@ -59,6 +62,7 @@ const CollectionDetailsPage: React.StatelessComponent<
|
||||||
...collectionProductsProps
|
...collectionProductsProps
|
||||||
}: CollectionDetailsPageProps) => {
|
}: CollectionDetailsPageProps) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
const localizeDate = useDateLocalize();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form
|
<Form
|
||||||
|
@ -124,8 +128,29 @@ const CollectionDetailsPage: React.StatelessComponent<
|
||||||
data={data}
|
data={data}
|
||||||
errors={formErrors}
|
errors={formErrors}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
hiddenMessage={intl.formatMessage(
|
||||||
|
{
|
||||||
|
defaultMessage: "will be visible from {date}",
|
||||||
|
description: "collection"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: localizeDate(data.publicationDate)
|
||||||
|
}
|
||||||
|
)}
|
||||||
onChange={change}
|
onChange={change}
|
||||||
|
visibleMessage={intl.formatMessage(
|
||||||
|
{
|
||||||
|
defaultMessage: "since {date}",
|
||||||
|
description: "collection"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: localizeDate(data.publicationDate)
|
||||||
|
}
|
||||||
|
)}
|
||||||
>
|
>
|
||||||
|
<>
|
||||||
|
<FormSpacer />
|
||||||
|
<Hr />
|
||||||
<ControlledCheckbox
|
<ControlledCheckbox
|
||||||
name={"isFeatured" as keyof CollectionDetailsPageFormData}
|
name={"isFeatured" as keyof CollectionDetailsPageFormData}
|
||||||
label={intl.formatMessage({
|
label={intl.formatMessage({
|
||||||
|
@ -136,6 +161,7 @@ const CollectionDetailsPage: React.StatelessComponent<
|
||||||
onChange={change}
|
onChange={change}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
/>
|
/>
|
||||||
|
</>
|
||||||
</VisibilityCard>
|
</VisibilityCard>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -13,7 +13,6 @@ import { useIntl } from "react-intl";
|
||||||
|
|
||||||
import CardTitle from "@saleor/components/CardTitle";
|
import CardTitle from "@saleor/components/CardTitle";
|
||||||
import RadioSwitchField from "@saleor/components/RadioSwitchField";
|
import RadioSwitchField from "@saleor/components/RadioSwitchField";
|
||||||
import useDateLocalize from "@saleor/hooks/useDateLocalize";
|
|
||||||
import { DateContext } from "../Date/DateContext";
|
import { DateContext } from "../Date/DateContext";
|
||||||
|
|
||||||
const styles = (theme: Theme) =>
|
const styles = (theme: Theme) =>
|
||||||
|
@ -48,7 +47,9 @@ interface VisibilityCardProps extends WithStyles<typeof styles> {
|
||||||
};
|
};
|
||||||
errors: { [key: string]: string };
|
errors: { [key: string]: string };
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
|
hiddenMessage: string;
|
||||||
onChange: (event: React.ChangeEvent<any>) => void;
|
onChange: (event: React.ChangeEvent<any>) => void;
|
||||||
|
visibleMessage: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const VisibilityCard = withStyles(styles, {
|
export const VisibilityCard = withStyles(styles, {
|
||||||
|
@ -60,38 +61,25 @@ export const VisibilityCard = withStyles(styles, {
|
||||||
data: { isPublished, publicationDate },
|
data: { isPublished, publicationDate },
|
||||||
errors,
|
errors,
|
||||||
disabled,
|
disabled,
|
||||||
onChange
|
hiddenMessage,
|
||||||
|
onChange,
|
||||||
|
visibleMessage
|
||||||
}: VisibilityCardProps) => {
|
}: VisibilityCardProps) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const [isPublicationDate, setPublicationDate] = React.useState(
|
const [isPublicationDate, setPublicationDate] = React.useState(
|
||||||
publicationDate === null ? true : false
|
publicationDate === null ? true : false
|
||||||
);
|
);
|
||||||
const localizeDate = useDateLocalize();
|
|
||||||
const dateNow = React.useContext(DateContext);
|
const dateNow = React.useContext(DateContext);
|
||||||
const visibleSecondLabel = publicationDate
|
const visibleSecondLabel = publicationDate
|
||||||
? isPublished
|
? isPublished
|
||||||
? intl.formatMessage(
|
? visibleMessage
|
||||||
{
|
|
||||||
defaultMessage: "since {date}"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
date: localizeDate(publicationDate)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
: null
|
: null
|
||||||
: null;
|
: null;
|
||||||
const hiddenSecondLabel = publicationDate
|
const hiddenSecondLabel = publicationDate
|
||||||
? isPublished
|
? isPublished
|
||||||
? null
|
? null
|
||||||
: Date.parse(publicationDate) > dateNow
|
: Date.parse(publicationDate) > dateNow
|
||||||
? intl.formatMessage(
|
? hiddenMessage
|
||||||
{
|
|
||||||
defaultMessage: "will be visible from {date}"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
date: localizeDate(publicationDate)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
: null
|
: null
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ import PageHeader from "@saleor/components/PageHeader";
|
||||||
import SaveButtonBar from "@saleor/components/SaveButtonBar";
|
import SaveButtonBar from "@saleor/components/SaveButtonBar";
|
||||||
import SeoForm from "@saleor/components/SeoForm";
|
import SeoForm from "@saleor/components/SeoForm";
|
||||||
import VisibilityCard from "@saleor/components/VisibilityCard";
|
import VisibilityCard from "@saleor/components/VisibilityCard";
|
||||||
|
import useDateLocalize from "@saleor/hooks/useDateLocalize";
|
||||||
import { sectionNames } from "@saleor/intl";
|
import { sectionNames } from "@saleor/intl";
|
||||||
import { maybe } from "../../../misc";
|
import { maybe } from "../../../misc";
|
||||||
import { UserError } from "../../../types";
|
import { UserError } from "../../../types";
|
||||||
|
@ -54,6 +55,7 @@ const PageDetailsPage: React.StatelessComponent<PageDetailsPageProps> = ({
|
||||||
onSubmit
|
onSubmit
|
||||||
}) => {
|
}) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
const localizeDate = useDateLocalize();
|
||||||
|
|
||||||
const initialForm: FormData = {
|
const initialForm: FormData = {
|
||||||
content: maybe(
|
content: maybe(
|
||||||
|
@ -121,9 +123,27 @@ const PageDetailsPage: React.StatelessComponent<PageDetailsPageProps> = ({
|
||||||
<CardSpacer />
|
<CardSpacer />
|
||||||
<VisibilityCard
|
<VisibilityCard
|
||||||
data={data}
|
data={data}
|
||||||
disabled={disabled}
|
|
||||||
errors={formErrors}
|
errors={formErrors}
|
||||||
|
disabled={disabled}
|
||||||
|
hiddenMessage={intl.formatMessage(
|
||||||
|
{
|
||||||
|
defaultMessage: "will be visible from {date}",
|
||||||
|
description: "page"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: localizeDate(data.publicationDate)
|
||||||
|
}
|
||||||
|
)}
|
||||||
onChange={change}
|
onChange={change}
|
||||||
|
visibleMessage={intl.formatMessage(
|
||||||
|
{
|
||||||
|
defaultMessage: "since {date}",
|
||||||
|
description: "page"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: localizeDate(data.publicationDate)
|
||||||
|
}
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
|
@ -15,6 +15,7 @@ import SeoForm from "@saleor/components/SeoForm";
|
||||||
import VisibilityCard from "@saleor/components/VisibilityCard";
|
import VisibilityCard from "@saleor/components/VisibilityCard";
|
||||||
import { SearchCategories_categories_edges_node } from "@saleor/containers/SearchCategories/types/SearchCategories";
|
import { SearchCategories_categories_edges_node } from "@saleor/containers/SearchCategories/types/SearchCategories";
|
||||||
import { SearchCollections_collections_edges_node } from "@saleor/containers/SearchCollections/types/SearchCollections";
|
import { SearchCollections_collections_edges_node } from "@saleor/containers/SearchCollections/types/SearchCollections";
|
||||||
|
import useDateLocalize from "@saleor/hooks/useDateLocalize";
|
||||||
import useFormset from "@saleor/hooks/useFormset";
|
import useFormset from "@saleor/hooks/useFormset";
|
||||||
import useStateFromProps from "@saleor/hooks/useStateFromProps";
|
import useStateFromProps from "@saleor/hooks/useStateFromProps";
|
||||||
import { sectionNames } from "@saleor/intl";
|
import { sectionNames } from "@saleor/intl";
|
||||||
|
@ -98,7 +99,7 @@ export const ProductCreatePage: React.StatelessComponent<
|
||||||
onSubmit
|
onSubmit
|
||||||
}: ProductCreatePageProps) => {
|
}: ProductCreatePageProps) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
const localizeDate = useDateLocalize();
|
||||||
// Form values
|
// Form values
|
||||||
const {
|
const {
|
||||||
change: changeAttributeData,
|
change: changeAttributeData,
|
||||||
|
@ -280,7 +281,25 @@ export const ProductCreatePage: React.StatelessComponent<
|
||||||
data={data}
|
data={data}
|
||||||
errors={errors}
|
errors={errors}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
hiddenMessage={intl.formatMessage(
|
||||||
|
{
|
||||||
|
defaultMessage: "will be visible from {date}",
|
||||||
|
description: "product"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: localizeDate(data.publicationDate)
|
||||||
|
}
|
||||||
|
)}
|
||||||
onChange={change}
|
onChange={change}
|
||||||
|
visibleMessage={intl.formatMessage(
|
||||||
|
{
|
||||||
|
defaultMessage: "since {date}",
|
||||||
|
description: "product"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: localizeDate(data.publicationDate)
|
||||||
|
}
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
|
@ -14,6 +14,7 @@ import SeoForm from "@saleor/components/SeoForm";
|
||||||
import VisibilityCard from "@saleor/components/VisibilityCard";
|
import VisibilityCard from "@saleor/components/VisibilityCard";
|
||||||
import { SearchCategories_categories_edges_node } from "@saleor/containers/SearchCategories/types/SearchCategories";
|
import { SearchCategories_categories_edges_node } from "@saleor/containers/SearchCategories/types/SearchCategories";
|
||||||
import { SearchCollections_collections_edges_node } from "@saleor/containers/SearchCollections/types/SearchCollections";
|
import { SearchCollections_collections_edges_node } from "@saleor/containers/SearchCollections/types/SearchCollections";
|
||||||
|
import useDateLocalize from "@saleor/hooks/useDateLocalize";
|
||||||
import useFormset from "@saleor/hooks/useFormset";
|
import useFormset from "@saleor/hooks/useFormset";
|
||||||
import useStateFromProps from "@saleor/hooks/useStateFromProps";
|
import useStateFromProps from "@saleor/hooks/useStateFromProps";
|
||||||
import { sectionNames } from "@saleor/intl";
|
import { sectionNames } from "@saleor/intl";
|
||||||
|
@ -109,6 +110,7 @@ export const ProductUpdatePage: React.FC<ProductUpdatePageProps> = ({
|
||||||
toolbar
|
toolbar
|
||||||
}) => {
|
}) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
const localizeDate = useDateLocalize();
|
||||||
const attributeInput = React.useMemo(
|
const attributeInput = React.useMemo(
|
||||||
() => getAttributeInputFromProduct(product),
|
() => getAttributeInputFromProduct(product),
|
||||||
[product]
|
[product]
|
||||||
|
@ -290,7 +292,25 @@ export const ProductUpdatePage: React.FC<ProductUpdatePageProps> = ({
|
||||||
data={data}
|
data={data}
|
||||||
errors={errors}
|
errors={errors}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
hiddenMessage={intl.formatMessage(
|
||||||
|
{
|
||||||
|
defaultMessage: "will be visible from {date}",
|
||||||
|
description: "product"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: localizeDate(data.publicationDate)
|
||||||
|
}
|
||||||
|
)}
|
||||||
onChange={change}
|
onChange={change}
|
||||||
|
visibleMessage={intl.formatMessage(
|
||||||
|
{
|
||||||
|
defaultMessage: "since {date}",
|
||||||
|
description: "product"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: localizeDate(data.publicationDate)
|
||||||
|
}
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
Loading…
Reference in a new issue