2019-06-19 14:40:52 +00:00
|
|
|
import { RawDraftContentState } from "draft-js";
|
2019-08-09 10:26:22 +00:00
|
|
|
import React from "react";
|
2019-08-21 12:31:55 +00:00
|
|
|
import { useIntl } from "react-intl";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
|
|
|
import AppHeader from "@saleor/components/AppHeader";
|
|
|
|
import { CardSpacer } from "@saleor/components/CardSpacer";
|
|
|
|
import { ConfirmButtonTransitionState } from "@saleor/components/ConfirmButton";
|
|
|
|
import { Container } from "@saleor/components/Container";
|
2019-09-09 09:28:06 +00:00
|
|
|
import ControlledCheckbox from "@saleor/components/ControlledCheckbox";
|
2019-06-19 14:40:52 +00:00
|
|
|
import Form from "@saleor/components/Form";
|
2019-09-16 01:36:04 +00:00
|
|
|
import FormSpacer from "@saleor/components/FormSpacer";
|
2019-06-19 14:40:52 +00:00
|
|
|
import Grid from "@saleor/components/Grid";
|
2019-09-16 01:36:04 +00:00
|
|
|
import Hr from "@saleor/components/Hr";
|
2019-06-19 14:40:52 +00:00
|
|
|
import PageHeader from "@saleor/components/PageHeader";
|
|
|
|
import SaveButtonBar from "@saleor/components/SaveButtonBar";
|
|
|
|
import SeoForm from "@saleor/components/SeoForm";
|
|
|
|
import VisibilityCard from "@saleor/components/VisibilityCard";
|
2019-09-16 01:36:04 +00:00
|
|
|
import useDateLocalize from "@saleor/hooks/useDateLocalize";
|
2019-08-21 12:31:55 +00:00
|
|
|
import { sectionNames } from "@saleor/intl";
|
2019-06-19 14:40:52 +00:00
|
|
|
import { maybe } from "../../../misc";
|
|
|
|
import { ListActions, PageListProps } from "../../../types";
|
|
|
|
import { CollectionDetails_collection } from "../../types/CollectionDetails";
|
|
|
|
import CollectionDetails from "../CollectionDetails/CollectionDetails";
|
|
|
|
import { CollectionImage } from "../CollectionImage/CollectionImage";
|
|
|
|
import CollectionProducts from "../CollectionProducts/CollectionProducts";
|
|
|
|
|
|
|
|
export interface CollectionDetailsPageFormData {
|
|
|
|
backgroundImageAlt: string;
|
|
|
|
description: RawDraftContentState;
|
|
|
|
name: string;
|
|
|
|
publicationDate: string;
|
|
|
|
seoDescription: string;
|
|
|
|
seoTitle: string;
|
|
|
|
isFeatured: boolean;
|
|
|
|
isPublished: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface CollectionDetailsPageProps extends PageListProps, ListActions {
|
|
|
|
collection: CollectionDetails_collection;
|
|
|
|
isFeatured: boolean;
|
|
|
|
saveButtonBarState: ConfirmButtonTransitionState;
|
|
|
|
onBack: () => void;
|
|
|
|
onCollectionRemove: () => void;
|
|
|
|
onImageDelete: () => void;
|
|
|
|
onImageUpload: (file: File) => void;
|
|
|
|
onProductUnassign: (id: string, event: React.MouseEvent<any>) => void;
|
|
|
|
onSubmit: (data: CollectionDetailsPageFormData) => void;
|
|
|
|
}
|
|
|
|
|
2019-11-07 11:34:54 +00:00
|
|
|
const CollectionDetailsPage: React.FC<CollectionDetailsPageProps> = ({
|
2019-06-19 14:40:52 +00:00
|
|
|
collection,
|
|
|
|
disabled,
|
|
|
|
isFeatured,
|
|
|
|
saveButtonBarState,
|
|
|
|
onBack,
|
|
|
|
onCollectionRemove,
|
|
|
|
onImageDelete,
|
|
|
|
onImageUpload,
|
|
|
|
onSubmit,
|
|
|
|
...collectionProductsProps
|
|
|
|
}: CollectionDetailsPageProps) => {
|
2019-08-21 12:31:55 +00:00
|
|
|
const intl = useIntl();
|
2019-09-16 01:36:04 +00:00
|
|
|
const localizeDate = useDateLocalize();
|
2019-08-21 12:31:55 +00:00
|
|
|
|
2019-06-19 14:40:52 +00:00
|
|
|
return (
|
|
|
|
<Form
|
|
|
|
initial={{
|
|
|
|
backgroundImageAlt: maybe(() => collection.backgroundImage.alt, ""),
|
|
|
|
description: maybe(() => JSON.parse(collection.descriptionJson)),
|
|
|
|
isFeatured,
|
|
|
|
isPublished: maybe(() => collection.isPublished, false),
|
|
|
|
name: maybe(() => collection.name, ""),
|
|
|
|
publicationDate: maybe(() => collection.publicationDate, ""),
|
|
|
|
seoDescription: maybe(() => collection.seoDescription, ""),
|
|
|
|
seoTitle: maybe(() => collection.seoTitle, "")
|
|
|
|
}}
|
|
|
|
onSubmit={onSubmit}
|
|
|
|
confirmLeave
|
|
|
|
>
|
|
|
|
{({ change, data, errors: formErrors, hasChanged, submit }) => (
|
|
|
|
<Container>
|
2019-08-21 12:31:55 +00:00
|
|
|
<AppHeader onBack={onBack}>
|
|
|
|
{intl.formatMessage(sectionNames.collections)}
|
|
|
|
</AppHeader>
|
2019-06-19 14:40:52 +00:00
|
|
|
<PageHeader title={maybe(() => collection.name)} />
|
|
|
|
<Grid>
|
|
|
|
<div>
|
|
|
|
<CollectionDetails
|
|
|
|
collection={collection}
|
|
|
|
data={data}
|
|
|
|
disabled={disabled}
|
|
|
|
errors={formErrors}
|
|
|
|
onChange={change}
|
|
|
|
/>
|
|
|
|
<CardSpacer />
|
|
|
|
<CollectionImage
|
|
|
|
data={data}
|
|
|
|
image={maybe(() => collection.backgroundImage)}
|
|
|
|
onImageDelete={onImageDelete}
|
|
|
|
onImageUpload={onImageUpload}
|
|
|
|
onChange={change}
|
|
|
|
/>
|
|
|
|
<CardSpacer />
|
|
|
|
<CollectionProducts
|
|
|
|
disabled={disabled}
|
|
|
|
collection={collection}
|
|
|
|
{...collectionProductsProps}
|
|
|
|
/>
|
|
|
|
<CardSpacer />
|
|
|
|
<SeoForm
|
|
|
|
description={data.seoDescription}
|
|
|
|
disabled={disabled}
|
|
|
|
descriptionPlaceholder=""
|
2019-08-21 12:31:55 +00:00
|
|
|
helperText={intl.formatMessage({
|
|
|
|
defaultMessage:
|
2019-08-22 16:25:55 +00:00
|
|
|
"Add search engine title and description to make this collection easier to find"
|
2019-08-21 12:31:55 +00:00
|
|
|
})}
|
2019-06-19 14:40:52 +00:00
|
|
|
title={data.seoTitle}
|
|
|
|
titlePlaceholder={maybe(() => collection.name)}
|
|
|
|
onChange={change}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<div>
|
|
|
|
<VisibilityCard
|
|
|
|
data={data}
|
|
|
|
errors={formErrors}
|
|
|
|
disabled={disabled}
|
2019-09-16 01:36:04 +00:00
|
|
|
hiddenMessage={intl.formatMessage(
|
|
|
|
{
|
|
|
|
defaultMessage: "will be visible from {date}",
|
|
|
|
description: "collection"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
date: localizeDate(data.publicationDate)
|
|
|
|
}
|
|
|
|
)}
|
2019-06-19 14:40:52 +00:00
|
|
|
onChange={change}
|
2019-09-16 01:36:04 +00:00
|
|
|
visibleMessage={intl.formatMessage(
|
|
|
|
{
|
|
|
|
defaultMessage: "since {date}",
|
|
|
|
description: "collection"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
date: localizeDate(data.publicationDate)
|
|
|
|
}
|
|
|
|
)}
|
2019-06-19 14:40:52 +00:00
|
|
|
>
|
2019-09-16 11:43:02 +00:00
|
|
|
<FormSpacer />
|
|
|
|
<Hr />
|
|
|
|
<ControlledCheckbox
|
|
|
|
name={"isFeatured" as keyof CollectionDetailsPageFormData}
|
|
|
|
label={intl.formatMessage({
|
|
|
|
defaultMessage: "Feature on Homepage",
|
|
|
|
description: "switch button"
|
|
|
|
})}
|
|
|
|
checked={data.isFeatured}
|
|
|
|
onChange={change}
|
|
|
|
disabled={disabled}
|
|
|
|
/>
|
2019-06-19 14:40:52 +00:00
|
|
|
</VisibilityCard>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Grid>
|
|
|
|
<SaveButtonBar
|
|
|
|
state={saveButtonBarState}
|
|
|
|
disabled={disabled || !hasChanged}
|
|
|
|
onCancel={onBack}
|
|
|
|
onDelete={onCollectionRemove}
|
|
|
|
onSave={submit}
|
|
|
|
/>
|
|
|
|
</Container>
|
|
|
|
)}
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
CollectionDetailsPage.displayName = "CollectionDetailsPage";
|
|
|
|
export default CollectionDetailsPage;
|