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-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";
|
2020-08-28 12:45:11 +00:00
|
|
|
import Metadata from "@saleor/components/Metadata/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";
|
2019-08-21 12:31:55 +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 { maybe } from "../../../misc";
|
2020-03-05 14:59:55 +00:00
|
|
|
import { ListActions, PageListProps } from "../../../types";
|
2019-06-19 14:40:52 +00:00
|
|
|
import { CollectionDetails_collection } from "../../types/CollectionDetails";
|
|
|
|
import CollectionDetails from "../CollectionDetails/CollectionDetails";
|
|
|
|
import { CollectionImage } from "../CollectionImage/CollectionImage";
|
|
|
|
import CollectionProducts from "../CollectionProducts/CollectionProducts";
|
2020-11-03 16:49:42 +00:00
|
|
|
import CollectionUpdateForm, { CollectionUpdateData } from "./form";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
|
|
|
export interface CollectionDetailsPageProps extends PageListProps, ListActions {
|
|
|
|
collection: CollectionDetails_collection;
|
2020-03-05 14:59:55 +00:00
|
|
|
errors: ProductErrorFragment[];
|
2019-06-19 14:40:52 +00:00
|
|
|
isFeatured: boolean;
|
|
|
|
saveButtonBarState: ConfirmButtonTransitionState;
|
|
|
|
onBack: () => void;
|
|
|
|
onCollectionRemove: () => void;
|
|
|
|
onImageDelete: () => void;
|
|
|
|
onImageUpload: (file: File) => void;
|
|
|
|
onProductUnassign: (id: string, event: React.MouseEvent<any>) => void;
|
2020-11-03 16:49:42 +00:00
|
|
|
onSubmit: (data: CollectionUpdateData) => Promise<any>;
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
|
2019-11-07 11:34:54 +00:00
|
|
|
const CollectionDetailsPage: React.FC<CollectionDetailsPageProps> = ({
|
2019-06-19 14:40:52 +00:00
|
|
|
collection,
|
|
|
|
disabled,
|
2020-02-24 14:14:48 +00:00
|
|
|
errors,
|
2019-06-19 14:40:52 +00:00
|
|
|
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 (
|
2020-11-03 16:49:42 +00:00
|
|
|
<CollectionUpdateForm
|
|
|
|
collection={collection}
|
|
|
|
isFeatured={isFeatured}
|
|
|
|
onSubmit={onSubmit}
|
2019-06-19 14:40:52 +00:00
|
|
|
>
|
2020-11-03 16:49:42 +00:00
|
|
|
{({ change, data, handlers, hasChanged, submit }) => (
|
|
|
|
<Container>
|
|
|
|
<AppHeader onBack={onBack}>
|
|
|
|
{intl.formatMessage(sectionNames.collections)}
|
|
|
|
</AppHeader>
|
|
|
|
<PageHeader title={maybe(() => collection.name)} />
|
|
|
|
<Grid>
|
|
|
|
<div>
|
|
|
|
<CollectionDetails
|
|
|
|
data={data}
|
|
|
|
disabled={disabled}
|
|
|
|
errors={errors}
|
|
|
|
onChange={change}
|
|
|
|
onDescriptionChange={handlers.changeDescription}
|
|
|
|
/>
|
|
|
|
<CardSpacer />
|
|
|
|
<CollectionImage
|
|
|
|
data={data}
|
|
|
|
image={maybe(() => collection.backgroundImage)}
|
|
|
|
onImageDelete={onImageDelete}
|
|
|
|
onImageUpload={onImageUpload}
|
|
|
|
onChange={change}
|
|
|
|
/>
|
|
|
|
<CardSpacer />
|
|
|
|
<Metadata data={data} onChange={handlers.changeMetadata} />
|
|
|
|
<CardSpacer />
|
|
|
|
<CollectionProducts
|
|
|
|
disabled={disabled}
|
|
|
|
collection={collection}
|
|
|
|
{...collectionProductsProps}
|
|
|
|
/>
|
|
|
|
<CardSpacer />
|
|
|
|
<SeoForm
|
|
|
|
description={data.seoDescription}
|
|
|
|
disabled={disabled}
|
|
|
|
descriptionPlaceholder=""
|
|
|
|
helperText={intl.formatMessage({
|
|
|
|
defaultMessage:
|
|
|
|
"Add search engine title and description to make this collection easier to find"
|
|
|
|
})}
|
|
|
|
errors={errors}
|
|
|
|
slug={data.slug}
|
|
|
|
slugPlaceholder={data.name}
|
|
|
|
title={data.seoTitle}
|
|
|
|
titlePlaceholder={maybe(() => collection.name)}
|
|
|
|
onChange={change}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div>
|
2019-06-19 14:40:52 +00:00
|
|
|
<div>
|
2020-11-03 16:49:42 +00:00
|
|
|
<VisibilityCard
|
2019-06-19 14:40:52 +00:00
|
|
|
data={data}
|
2020-02-24 14:14:48 +00:00
|
|
|
errors={errors}
|
2020-11-03 16:49:42 +00:00
|
|
|
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"
|
|
|
|
})
|
|
|
|
}}
|
2020-08-28 12:45:11 +00:00
|
|
|
onChange={change}
|
2020-11-03 16:49:42 +00:00
|
|
|
>
|
|
|
|
<FormSpacer />
|
|
|
|
<Hr />
|
|
|
|
<ControlledCheckbox
|
|
|
|
name={"isFeatured" as keyof CollectionUpdateData}
|
|
|
|
label={intl.formatMessage({
|
|
|
|
defaultMessage: "Feature on Homepage",
|
|
|
|
description: "switch button"
|
|
|
|
})}
|
|
|
|
checked={data.isFeatured}
|
2020-08-28 12:45:11 +00:00
|
|
|
onChange={change}
|
2020-11-03 16:49:42 +00:00
|
|
|
disabled={disabled}
|
|
|
|
/>
|
|
|
|
</VisibilityCard>
|
2019-06-19 14:40:52 +00:00
|
|
|
</div>
|
2020-11-03 16:49:42 +00:00
|
|
|
</div>
|
|
|
|
</Grid>
|
|
|
|
<SaveButtonBar
|
|
|
|
state={saveButtonBarState}
|
|
|
|
disabled={disabled || !hasChanged}
|
|
|
|
onCancel={onBack}
|
|
|
|
onDelete={onCollectionRemove}
|
|
|
|
onSave={submit}
|
|
|
|
/>
|
|
|
|
</Container>
|
|
|
|
)}
|
|
|
|
</CollectionUpdateForm>
|
2019-06-19 14:40:52 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
CollectionDetailsPage.displayName = "CollectionDetailsPage";
|
|
|
|
export default CollectionDetailsPage;
|