2019-06-19 14:40:52 +00:00
|
|
|
import Card from "@material-ui/core/Card";
|
|
|
|
import CardContent from "@material-ui/core/CardContent";
|
|
|
|
import { ContentState, convertToRaw, 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 CardTitle from "@saleor/components/CardTitle";
|
|
|
|
import { ConfirmButtonTransitionState } from "@saleor/components/ConfirmButton";
|
|
|
|
import { Container } from "@saleor/components/Container";
|
|
|
|
import Form from "@saleor/components/Form";
|
|
|
|
import Grid from "@saleor/components/Grid";
|
|
|
|
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 { commonMessages, sectionNames } from "@saleor/intl";
|
2020-03-05 14:59:55 +00:00
|
|
|
import { ProductErrorFragment } from "@saleor/attributes/types/ProductErrorFragment";
|
2019-06-19 14:40:52 +00:00
|
|
|
import CollectionDetails from "../CollectionDetails/CollectionDetails";
|
|
|
|
import { CollectionImage } from "../CollectionImage/CollectionImage";
|
|
|
|
|
|
|
|
export interface CollectionCreatePageFormData {
|
|
|
|
backgroundImage: {
|
|
|
|
url: string;
|
|
|
|
value: string;
|
|
|
|
};
|
|
|
|
backgroundImageAlt: string;
|
|
|
|
description: RawDraftContentState;
|
|
|
|
name: string;
|
|
|
|
publicationDate: string;
|
|
|
|
isPublished: boolean;
|
|
|
|
seoDescription: string;
|
|
|
|
seoTitle: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface CollectionCreatePageProps {
|
|
|
|
disabled: boolean;
|
2020-03-05 14:59:55 +00:00
|
|
|
errors: ProductErrorFragment[];
|
2019-06-19 14:40:52 +00:00
|
|
|
saveButtonBarState: ConfirmButtonTransitionState;
|
|
|
|
onBack: () => void;
|
|
|
|
onSubmit: (data: CollectionCreatePageFormData) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
const initialForm: CollectionCreatePageFormData = {
|
|
|
|
backgroundImage: {
|
|
|
|
url: null,
|
|
|
|
value: null
|
|
|
|
},
|
|
|
|
backgroundImageAlt: "",
|
|
|
|
description: convertToRaw(ContentState.createFromText("")),
|
|
|
|
isPublished: false,
|
|
|
|
name: "",
|
|
|
|
publicationDate: "",
|
|
|
|
seoDescription: "",
|
|
|
|
seoTitle: ""
|
|
|
|
};
|
|
|
|
|
2019-11-07 11:34:54 +00:00
|
|
|
const CollectionCreatePage: React.FC<CollectionCreatePageProps> = ({
|
2019-06-19 14:40:52 +00:00
|
|
|
disabled,
|
|
|
|
errors,
|
|
|
|
saveButtonBarState,
|
|
|
|
onBack,
|
|
|
|
onSubmit
|
2019-08-21 12:31:55 +00:00
|
|
|
}: CollectionCreatePageProps) => {
|
|
|
|
const intl = useIntl();
|
2019-09-16 01:36:04 +00:00
|
|
|
const localizeDate = useDateLocalize();
|
2019-08-21 12:31:55 +00:00
|
|
|
|
|
|
|
return (
|
2020-02-24 14:14:48 +00:00
|
|
|
<Form initial={initialForm} onSubmit={onSubmit}>
|
|
|
|
{({ change, data, hasChanged, submit }) => (
|
2019-08-21 12:31:55 +00:00
|
|
|
<Container>
|
|
|
|
<AppHeader onBack={onBack}>
|
|
|
|
{intl.formatMessage(sectionNames.collections)}
|
|
|
|
</AppHeader>
|
|
|
|
<PageHeader
|
|
|
|
title={intl.formatMessage({
|
2019-10-09 15:33:55 +00:00
|
|
|
defaultMessage: "Add Collection",
|
2019-08-22 16:25:55 +00:00
|
|
|
description: "page header"
|
2019-08-21 12:31:55 +00:00
|
|
|
})}
|
|
|
|
/>
|
|
|
|
<Grid>
|
|
|
|
<div>
|
|
|
|
<CollectionDetails
|
|
|
|
data={data}
|
|
|
|
disabled={disabled}
|
2020-02-24 14:14:48 +00:00
|
|
|
errors={errors}
|
2019-08-21 12:31:55 +00:00
|
|
|
onChange={change}
|
|
|
|
/>
|
|
|
|
<CardSpacer />
|
|
|
|
<CollectionImage
|
|
|
|
image={
|
|
|
|
data.backgroundImage.url
|
|
|
|
? {
|
|
|
|
__typename: "Image",
|
|
|
|
alt: data.backgroundImageAlt,
|
|
|
|
url: data.backgroundImage.url
|
|
|
|
}
|
|
|
|
: null
|
|
|
|
}
|
|
|
|
onImageDelete={() =>
|
|
|
|
change({
|
|
|
|
target: {
|
|
|
|
name: "backgroundImage",
|
|
|
|
value: {
|
|
|
|
url: null,
|
|
|
|
value: null
|
|
|
|
}
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
2019-08-21 12:31:55 +00:00
|
|
|
} as any)
|
|
|
|
}
|
|
|
|
onImageUpload={file =>
|
|
|
|
change({
|
|
|
|
target: {
|
|
|
|
name: "backgroundImage",
|
|
|
|
value: {
|
|
|
|
url: URL.createObjectURL(file),
|
|
|
|
value: file
|
|
|
|
}
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
2019-08-21 12:31:55 +00:00
|
|
|
} as any)
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
2019-08-21 12:31:55 +00:00
|
|
|
onChange={change}
|
|
|
|
data={data}
|
|
|
|
/>
|
|
|
|
<CardSpacer />
|
|
|
|
<SeoForm
|
|
|
|
description={data.seoDescription}
|
|
|
|
disabled={disabled}
|
|
|
|
descriptionPlaceholder=""
|
|
|
|
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
|
|
|
})}
|
|
|
|
title={data.seoTitle}
|
|
|
|
titlePlaceholder={data.name}
|
|
|
|
onChange={change}
|
|
|
|
/>
|
|
|
|
</div>
|
2019-06-19 14:40:52 +00:00
|
|
|
<div>
|
2019-08-21 12:31:55 +00:00
|
|
|
<div>
|
|
|
|
<Card>
|
|
|
|
<CardTitle
|
|
|
|
title={intl.formatMessage(commonMessages.availability)}
|
2019-06-19 14:40:52 +00:00
|
|
|
/>
|
2019-08-21 12:31:55 +00:00
|
|
|
<CardContent>
|
|
|
|
<VisibilityCard
|
|
|
|
data={data}
|
2020-02-24 14:14:48 +00:00
|
|
|
errors={errors}
|
2019-08-21 12:31:55 +00:00
|
|
|
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-08-21 12:31:55 +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-08-21 12:31:55 +00:00
|
|
|
/>
|
|
|
|
</CardContent>
|
|
|
|
</Card>
|
|
|
|
</div>
|
2019-06-19 14:40:52 +00:00
|
|
|
</div>
|
2019-08-21 12:31:55 +00:00
|
|
|
</Grid>
|
|
|
|
<SaveButtonBar
|
|
|
|
state={saveButtonBarState}
|
|
|
|
disabled={disabled || !hasChanged}
|
|
|
|
onCancel={onBack}
|
|
|
|
onSave={submit}
|
|
|
|
/>
|
|
|
|
</Container>
|
|
|
|
)}
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
CollectionCreatePage.displayName = "CollectionCreatePage";
|
|
|
|
export default CollectionCreatePage;
|