fix SaleCreate view (#857)

* fix SaleCreate view

* fix SaleValue input styles, update snapshots

* add success status to create sale notification
This commit is contained in:
AlicjaSzu 2020-11-26 11:43:05 +01:00 committed by GitHub
parent b07c391af4
commit 1845111537
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 1476 additions and 90 deletions

View file

@ -8,8 +8,10 @@ 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 { createSaleChannelsChangeHandler } from "@saleor/discounts/handlers";
import { DiscountErrorFragment } from "@saleor/fragments/types/DiscountErrorFragment";
import { sectionNames } from "@saleor/intl";
import { validatePrice } from "@saleor/products/utils/validation";
import React from "react";
import { useIntl } from "react-intl";
@ -17,6 +19,7 @@ import { SaleType as SaleTypeEnum } from "../../../types/globalTypes";
import DiscountDates from "../DiscountDates";
import SaleInfo from "../SaleInfo";
import SaleType from "../SaleType";
import SaleValue from "../SaleValue";
export interface FormData {
channelListings: ChannelSaleData[];
@ -37,6 +40,7 @@ export interface SaleCreatePageProps {
errors: DiscountErrorFragment[];
saveButtonBarState: ConfirmButtonTransitionState;
onBack: () => void;
onChannelsChange: (data: ChannelSaleData[]) => void;
openChannelsModal: () => void;
onSubmit: (data: FormData) => void;
}
@ -46,6 +50,7 @@ const SaleCreatePage: React.FC<SaleCreatePageProps> = ({
channelListings = [],
disabled,
errors,
onChannelsChange,
onSubmit,
openChannelsModal,
saveButtonBarState,
@ -66,56 +71,73 @@ const SaleCreatePage: React.FC<SaleCreatePageProps> = ({
};
return (
<Form initial={initialForm} onSubmit={onSubmit}>
{({ change, data, hasChanged, submit }) => (
<Container>
<AppHeader onBack={onBack}>
{intl.formatMessage(sectionNames.sales)}
</AppHeader>
<PageHeader
title={intl.formatMessage({
defaultMessage: "Create Sale",
description: "page header"
})}
/>
<Grid>
<div>
<SaleInfo
data={data}
disabled={disabled}
errors={errors}
onChange={change}
/>
<CardSpacer />
<SaleType data={data} disabled={disabled} onChange={change} />
<CardSpacer />
<DiscountDates
data={data}
disabled={disabled}
errors={errors}
onChange={change}
/>
</div>
<div>
<ChannelsAvailability
selectedChannelsCount={data.channelListings.length}
allChannelsCount={allChannelsCount}
channelsList={data.channelListings.map(channel => ({
id: channel.id,
name: channel.name
}))}
disabled={disabled}
openModal={openChannelsModal}
/>
</div>
</Grid>
<SaveButtonBar
disabled={disabled || !hasChanged}
onCancel={onBack}
onSave={submit}
state={saveButtonBarState}
/>
</Container>
)}
{({ change, data, hasChanged, submit, triggerChange }) => {
const handleChannelChange = createSaleChannelsChangeHandler(
data.channelListings,
onChannelsChange,
triggerChange
);
const formDisabled = data.channelListings?.some(channel =>
validatePrice(channel.discountValue)
);
return (
<Container>
<AppHeader onBack={onBack}>
{intl.formatMessage(sectionNames.sales)}
</AppHeader>
<PageHeader
title={intl.formatMessage({
defaultMessage: "Create Sale",
description: "page header"
})}
/>
<Grid>
<div>
<SaleInfo
data={data}
disabled={disabled}
errors={errors}
onChange={change}
/>
<CardSpacer />
<SaleType data={data} disabled={disabled} onChange={change} />
<CardSpacer />
<SaleValue
data={data}
disabled={disabled}
errors={errors}
onChange={handleChannelChange}
/>
<CardSpacer />
<DiscountDates
data={data}
disabled={disabled}
errors={errors}
onChange={change}
/>
</div>
<div>
<ChannelsAvailability
selectedChannelsCount={data.channelListings.length}
allChannelsCount={allChannelsCount}
channelsList={data.channelListings.map(channel => ({
id: channel.id,
name: channel.name
}))}
disabled={disabled}
openModal={openChannelsModal}
/>
</div>
</Grid>
<SaveButtonBar
disabled={disabled || formDisabled || !hasChanged}
onCancel={onBack}
onSave={submit}
state={saveButtonBarState}
/>
</Container>
);
}}
</Form>
);
};

View file

@ -89,7 +89,7 @@ const SaleValue: React.FC<SaleValueProps> = ({
<TableCell>
<Typography>{listing?.name || <Skeleton />}</Typography>
</TableCell>
<TableCell className={classes.colPrice}>
<TableCell>
{listing ? (
<TextField
disabled={disabled}

View file

@ -12,13 +12,10 @@ export const useStyles = makeStyles(
paddingLeft: 0,
width: "auto"
},
colPrice: {
minWidth: 240
},
colType: {
fontSize: 14,
textAlign: "right",
width: 200
width: 235
},
info: {
fontSize: 14

View file

@ -37,6 +37,7 @@ export const SaleDetails: React.FC = () => {
handleChannelsModalOpen,
isChannelSelected,
isChannelsModalOpen,
setCurrentChannels,
toggleAllChannels
} = useChannels(allChannels);
@ -45,6 +46,7 @@ export const SaleDetails: React.FC = () => {
const handleSaleCreate = (data: SaleCreate) => {
if (data.saleCreate.errors.length === 0) {
pushMessage({
status: "success",
text: intl.formatMessage({
defaultMessage: "Successfully created sale"
})
@ -94,6 +96,7 @@ export const SaleDetails: React.FC = () => {
onSubmit={handleSubmit}
saveButtonBarState={saleCreateOpts.status}
openChannelsModal={handleChannelsModalOpen}
onChannelsChange={setCurrentChannels}
/>
</>
);

File diff suppressed because it is too large Load diff

View file

@ -17,6 +17,7 @@ const props: SaleCreatePageProps = {
disabled: false,
errors: [],
onBack: () => undefined,
onChannelsChange: () => undefined,
onSubmit: () => undefined,
openChannelsModal: () => undefined,
saveButtonBarState: "default"