Add ability to modify sku
This commit is contained in:
parent
cc1a42c5ef
commit
52f458e739
4 changed files with 88 additions and 4 deletions
|
@ -121,6 +121,14 @@ const ProductVariantCreateContent: React.FC<
|
||||||
attributes={selectedAttributes}
|
attributes={selectedAttributes}
|
||||||
currencySymbol={currencySymbol}
|
currencySymbol={currencySymbol}
|
||||||
data={data}
|
data={data}
|
||||||
|
onVariantDataChange={(variantIndex, field, value) =>
|
||||||
|
dispatchFormDataAction({
|
||||||
|
field,
|
||||||
|
type: "changeVariantData",
|
||||||
|
value,
|
||||||
|
variantIndex
|
||||||
|
})
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -25,6 +25,51 @@ const useStyles = makeStyles((theme: Theme) => ({
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
function canHitNext(
|
||||||
|
step: ProductVariantCreateStep,
|
||||||
|
data: ProductVariantCreateFormData
|
||||||
|
): boolean {
|
||||||
|
switch (step) {
|
||||||
|
case "attributes":
|
||||||
|
return data.attributes.length > 0;
|
||||||
|
case "values":
|
||||||
|
return data.attributes.every(attribute => attribute.values.length > 0);
|
||||||
|
case "prices":
|
||||||
|
if (data.price.all) {
|
||||||
|
if (data.price.value === "") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (
|
||||||
|
data.price.attribute === "" ||
|
||||||
|
data.price.values.some(attributeValue => attributeValue.value === "")
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.stock.all) {
|
||||||
|
if (data.stock.value === "") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (
|
||||||
|
data.stock.attribute === "" ||
|
||||||
|
data.stock.values.some(attributeValue => attributeValue.value === "")
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
case "summary":
|
||||||
|
return data.variants.every(variant => variant.sku !== "");
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export interface ProductVariantCreateDialogProps
|
export interface ProductVariantCreateDialogProps
|
||||||
extends Omit<
|
extends Omit<
|
||||||
ProductVariantCreateContentProps,
|
ProductVariantCreateContentProps,
|
||||||
|
@ -110,13 +155,19 @@ const ProductVariantCreateDialog: React.FC<
|
||||||
<Button
|
<Button
|
||||||
className={classes.button}
|
className={classes.button}
|
||||||
color="primary"
|
color="primary"
|
||||||
|
disabled={!canHitNext(step, data)}
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={handleNextStep}
|
onClick={handleNextStep}
|
||||||
>
|
>
|
||||||
<FormattedMessage defaultMessage="Next" description="button" />
|
<FormattedMessage defaultMessage="Next" description="button" />
|
||||||
</Button>
|
</Button>
|
||||||
) : (
|
) : (
|
||||||
<Button className={classes.button} variant="contained">
|
<Button
|
||||||
|
className={classes.button}
|
||||||
|
color="primary"
|
||||||
|
disabled={!canHitNext(step, data)}
|
||||||
|
variant="contained"
|
||||||
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
defaultMessage="Create"
|
defaultMessage="Create"
|
||||||
description="create multiple variants, button"
|
description="create multiple variants, button"
|
||||||
|
|
|
@ -20,17 +20,24 @@ import Hr from "@saleor/components/Hr";
|
||||||
import { ProductVariantCreateInput } from "@saleor/types/globalTypes";
|
import { ProductVariantCreateInput } from "@saleor/types/globalTypes";
|
||||||
import { ProductDetails_product_productType_variantAttributes } from "../../types/ProductDetails";
|
import { ProductDetails_product_productType_variantAttributes } from "../../types/ProductDetails";
|
||||||
import { ProductVariantCreateFormData } from "./form";
|
import { ProductVariantCreateFormData } from "./form";
|
||||||
|
import { VariantField } from "./reducer";
|
||||||
|
|
||||||
export interface ProductVariantCreateSummaryProps {
|
export interface ProductVariantCreateSummaryProps {
|
||||||
attributes: ProductDetails_product_productType_variantAttributes[];
|
attributes: ProductDetails_product_productType_variantAttributes[];
|
||||||
currencySymbol: string;
|
currencySymbol: string;
|
||||||
data: ProductVariantCreateFormData;
|
data: ProductVariantCreateFormData;
|
||||||
|
onVariantDataChange: (
|
||||||
|
variantIndex: number,
|
||||||
|
field: VariantField,
|
||||||
|
value: string
|
||||||
|
) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const colors = [blue, cyan, green, purple, yellow].map(color => color[800]);
|
const colors = [blue, cyan, green, purple, yellow].map(color => color[800]);
|
||||||
|
|
||||||
const useStyles = makeStyles((theme: Theme) => ({
|
const useStyles = makeStyles((theme: Theme) => ({
|
||||||
attributeValue: {
|
attributeValue: {
|
||||||
|
display: "inline-block",
|
||||||
marginRight: theme.spacing.unit
|
marginRight: theme.spacing.unit
|
||||||
},
|
},
|
||||||
col: {
|
col: {
|
||||||
|
@ -84,7 +91,7 @@ function getVariantName(
|
||||||
const ProductVariantCreateSummary: React.FC<
|
const ProductVariantCreateSummary: React.FC<
|
||||||
ProductVariantCreateSummaryProps
|
ProductVariantCreateSummaryProps
|
||||||
> = props => {
|
> = props => {
|
||||||
const { attributes, currencySymbol, data } = props;
|
const { attributes, currencySymbol, data, onVariantDataChange } = props;
|
||||||
const classes = useStyles(props);
|
const classes = useStyles(props);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -123,7 +130,7 @@ const ProductVariantCreateSummary: React.FC<
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{data.variants.map(variant => (
|
{data.variants.map((variant, variantIndex) => (
|
||||||
<TableRow
|
<TableRow
|
||||||
key={variant.attributes
|
key={variant.attributes
|
||||||
.map(attribute => attribute.values[0])
|
.map(attribute => attribute.values[0])
|
||||||
|
@ -152,6 +159,13 @@ const ProductVariantCreateSummary: React.FC<
|
||||||
}}
|
}}
|
||||||
fullWidth
|
fullWidth
|
||||||
value={variant.quantity}
|
value={variant.quantity}
|
||||||
|
onChange={event =>
|
||||||
|
onVariantDataChange(
|
||||||
|
variantIndex,
|
||||||
|
"stock",
|
||||||
|
event.target.value
|
||||||
|
)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className={classNames(classes.col, classes.colPrice)}>
|
<TableCell className={classNames(classes.col, classes.colPrice)}>
|
||||||
|
@ -166,6 +180,13 @@ const ProductVariantCreateSummary: React.FC<
|
||||||
}}
|
}}
|
||||||
fullWidth
|
fullWidth
|
||||||
value={variant.priceOverride}
|
value={variant.priceOverride}
|
||||||
|
onChange={event =>
|
||||||
|
onVariantDataChange(
|
||||||
|
variantIndex,
|
||||||
|
"price",
|
||||||
|
event.target.value
|
||||||
|
)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className={classNames(classes.col, classes.colSku)}>
|
<TableCell className={classNames(classes.col, classes.colSku)}>
|
||||||
|
@ -173,6 +194,9 @@ const ProductVariantCreateSummary: React.FC<
|
||||||
className={classes.input}
|
className={classes.input}
|
||||||
fullWidth
|
fullWidth
|
||||||
value={variant.sku}
|
value={variant.sku}
|
||||||
|
onChange={event =>
|
||||||
|
onVariantDataChange(variantIndex, "sku", event.target.value)
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
|
|
|
@ -47,7 +47,8 @@ function createVariant(
|
||||||
})),
|
})),
|
||||||
priceOverride,
|
priceOverride,
|
||||||
product: "",
|
product: "",
|
||||||
quantity
|
quantity,
|
||||||
|
sku: ""
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue