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";
|
|
|
|
import Grid from "@saleor/components/Grid";
|
2020-11-03 16:49:42 +00:00
|
|
|
import Metadata from "@saleor/components/Metadata";
|
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";
|
2020-07-07 10:14:12 +00:00
|
|
|
import { ProductErrorFragment } from "@saleor/fragments/types/ProductErrorFragment";
|
2019-09-16 01:36:04 +00:00
|
|
|
import useDateLocalize from "@saleor/hooks/useDateLocalize";
|
2020-11-06 10:54:03 +00:00
|
|
|
import { SubmitPromise } from "@saleor/hooks/useForm";
|
2020-09-01 11:46:15 +00:00
|
|
|
import { sectionNames } from "@saleor/intl";
|
2020-05-14 09:30:32 +00:00
|
|
|
import React from "react";
|
|
|
|
import { useIntl } from "react-intl";
|
|
|
|
|
2019-06-19 14:40:52 +00:00
|
|
|
import CollectionDetails from "../CollectionDetails/CollectionDetails";
|
|
|
|
import { CollectionImage } from "../CollectionImage/CollectionImage";
|
2020-11-03 16:49:42 +00:00
|
|
|
import CollectionCreateForm, { CollectionCreateData } from "./form";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
|
|
|
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;
|
2020-11-06 10:54:03 +00:00
|
|
|
onSubmit: (data: CollectionCreateData) => SubmitPromise;
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
|
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-11-03 16:49:42 +00:00
|
|
|
<CollectionCreateForm onSubmit={onSubmit}>
|
|
|
|
{({ change, data, handlers, hasChanged, submit }) => (
|
|
|
|
<Container>
|
|
|
|
<AppHeader onBack={onBack}>
|
|
|
|
{intl.formatMessage(sectionNames.collections)}
|
|
|
|
</AppHeader>
|
|
|
|
<PageHeader
|
|
|
|
title={intl.formatMessage({
|
|
|
|
defaultMessage: "Add Collection",
|
|
|
|
description: "page header"
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
<Grid>
|
|
|
|
<div>
|
|
|
|
<CollectionDetails
|
|
|
|
data={data}
|
|
|
|
disabled={disabled}
|
|
|
|
errors={errors}
|
|
|
|
onChange={change}
|
|
|
|
onDescriptionChange={handlers.changeDescription}
|
|
|
|
/>
|
|
|
|
<CardSpacer />
|
|
|
|
<CollectionImage
|
|
|
|
image={
|
|
|
|
data.backgroundImage.url
|
|
|
|
? {
|
|
|
|
__typename: "Image",
|
|
|
|
alt: data.backgroundImageAlt,
|
|
|
|
url: data.backgroundImage.url
|
2019-08-21 12:31:55 +00:00
|
|
|
}
|
2020-11-03 16:49:42 +00:00
|
|
|
: null
|
|
|
|
}
|
|
|
|
onImageDelete={() =>
|
|
|
|
change({
|
|
|
|
target: {
|
|
|
|
name: "backgroundImage",
|
|
|
|
value: {
|
|
|
|
url: null,
|
|
|
|
value: null
|
2019-08-21 12:31:55 +00:00
|
|
|
}
|
2020-11-03 16:49:42 +00:00
|
|
|
}
|
|
|
|
} as any)
|
|
|
|
}
|
|
|
|
onImageUpload={file =>
|
|
|
|
change({
|
|
|
|
target: {
|
|
|
|
name: "backgroundImage",
|
|
|
|
value: {
|
|
|
|
url: URL.createObjectURL(file),
|
|
|
|
value: file
|
2020-09-03 10:25:16 +00:00
|
|
|
}
|
2020-11-03 16:49:42 +00:00
|
|
|
}
|
|
|
|
} as any)
|
|
|
|
}
|
|
|
|
onChange={change}
|
|
|
|
data={data}
|
|
|
|
/>
|
|
|
|
<CardSpacer />
|
|
|
|
<SeoForm
|
|
|
|
allowEmptySlug={true}
|
|
|
|
description={data.seoDescription}
|
|
|
|
disabled={disabled}
|
|
|
|
descriptionPlaceholder=""
|
|
|
|
helperText={intl.formatMessage({
|
|
|
|
defaultMessage:
|
|
|
|
"Add search engine title and description to make this collection easier to find"
|
|
|
|
})}
|
|
|
|
slug={data.slug}
|
|
|
|
slugPlaceholder={data.name}
|
|
|
|
title={data.seoTitle}
|
|
|
|
titlePlaceholder={data.name}
|
|
|
|
onChange={change}
|
|
|
|
/>
|
|
|
|
<CardSpacer />
|
|
|
|
<Metadata data={data} onChange={handlers.changeMetadata} />
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<VisibilityCard
|
|
|
|
data={data}
|
|
|
|
errors={errors}
|
|
|
|
disabled={disabled}
|
|
|
|
messages={{
|
|
|
|
hiddenLabel: intl.formatMessage({
|
|
|
|
defaultMessage: "Hidden",
|
|
|
|
description: "collection label"
|
|
|
|
}),
|
|
|
|
hiddenSecondLabel: intl.formatMessage(
|
|
|
|
{
|
|
|
|
defaultMessage: "will be visible from {date}",
|
|
|
|
description: "collection"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
date: localizeDate(data.publicationDate, "L")
|
|
|
|
}
|
|
|
|
),
|
|
|
|
visibleLabel: intl.formatMessage({
|
|
|
|
defaultMessage: "Visible",
|
|
|
|
description: "collection label"
|
|
|
|
})
|
|
|
|
}}
|
|
|
|
onChange={change}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</Grid>
|
|
|
|
<SaveButtonBar
|
|
|
|
state={saveButtonBarState}
|
|
|
|
disabled={disabled || !hasChanged}
|
|
|
|
onCancel={onBack}
|
|
|
|
onSave={submit}
|
|
|
|
/>
|
|
|
|
</Container>
|
|
|
|
)}
|
|
|
|
</CollectionCreateForm>
|
2019-08-21 12:31:55 +00:00
|
|
|
);
|
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
CollectionCreatePage.displayName = "CollectionCreatePage";
|
|
|
|
export default CollectionCreatePage;
|