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 Grid from "@saleor/components/Grid";
import PageHeader from "@saleor/components/PageHeader"; import PageHeader from "@saleor/components/PageHeader";
import SaveButtonBar from "@saleor/components/SaveButtonBar"; import SaveButtonBar from "@saleor/components/SaveButtonBar";
import { createSaleChannelsChangeHandler } from "@saleor/discounts/handlers";
import { DiscountErrorFragment } from "@saleor/fragments/types/DiscountErrorFragment"; import { DiscountErrorFragment } from "@saleor/fragments/types/DiscountErrorFragment";
import { sectionNames } from "@saleor/intl"; import { sectionNames } from "@saleor/intl";
import { validatePrice } from "@saleor/products/utils/validation";
import React from "react"; import React from "react";
import { useIntl } from "react-intl"; import { useIntl } from "react-intl";
@ -17,6 +19,7 @@ import { SaleType as SaleTypeEnum } from "../../../types/globalTypes";
import DiscountDates from "../DiscountDates"; import DiscountDates from "../DiscountDates";
import SaleInfo from "../SaleInfo"; import SaleInfo from "../SaleInfo";
import SaleType from "../SaleType"; import SaleType from "../SaleType";
import SaleValue from "../SaleValue";
export interface FormData { export interface FormData {
channelListings: ChannelSaleData[]; channelListings: ChannelSaleData[];
@ -37,6 +40,7 @@ export interface SaleCreatePageProps {
errors: DiscountErrorFragment[]; errors: DiscountErrorFragment[];
saveButtonBarState: ConfirmButtonTransitionState; saveButtonBarState: ConfirmButtonTransitionState;
onBack: () => void; onBack: () => void;
onChannelsChange: (data: ChannelSaleData[]) => void;
openChannelsModal: () => void; openChannelsModal: () => void;
onSubmit: (data: FormData) => void; onSubmit: (data: FormData) => void;
} }
@ -46,6 +50,7 @@ const SaleCreatePage: React.FC<SaleCreatePageProps> = ({
channelListings = [], channelListings = [],
disabled, disabled,
errors, errors,
onChannelsChange,
onSubmit, onSubmit,
openChannelsModal, openChannelsModal,
saveButtonBarState, saveButtonBarState,
@ -66,7 +71,16 @@ const SaleCreatePage: React.FC<SaleCreatePageProps> = ({
}; };
return ( return (
<Form initial={initialForm} onSubmit={onSubmit}> <Form initial={initialForm} onSubmit={onSubmit}>
{({ change, data, hasChanged, submit }) => ( {({ change, data, hasChanged, submit, triggerChange }) => {
const handleChannelChange = createSaleChannelsChangeHandler(
data.channelListings,
onChannelsChange,
triggerChange
);
const formDisabled = data.channelListings?.some(channel =>
validatePrice(channel.discountValue)
);
return (
<Container> <Container>
<AppHeader onBack={onBack}> <AppHeader onBack={onBack}>
{intl.formatMessage(sectionNames.sales)} {intl.formatMessage(sectionNames.sales)}
@ -88,6 +102,13 @@ const SaleCreatePage: React.FC<SaleCreatePageProps> = ({
<CardSpacer /> <CardSpacer />
<SaleType data={data} disabled={disabled} onChange={change} /> <SaleType data={data} disabled={disabled} onChange={change} />
<CardSpacer /> <CardSpacer />
<SaleValue
data={data}
disabled={disabled}
errors={errors}
onChange={handleChannelChange}
/>
<CardSpacer />
<DiscountDates <DiscountDates
data={data} data={data}
disabled={disabled} disabled={disabled}
@ -109,13 +130,14 @@ const SaleCreatePage: React.FC<SaleCreatePageProps> = ({
</div> </div>
</Grid> </Grid>
<SaveButtonBar <SaveButtonBar
disabled={disabled || !hasChanged} disabled={disabled || formDisabled || !hasChanged}
onCancel={onBack} onCancel={onBack}
onSave={submit} onSave={submit}
state={saveButtonBarState} state={saveButtonBarState}
/> />
</Container> </Container>
)} );
}}
</Form> </Form>
); );
}; };

View file

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

View file

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

View file

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