Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Restyle product type details and create pages

dominik-zeglen51d68b9a24b4
diff --git a/saleor/static/dashboard-next/orders/queries.ts b/saleor/static/dashboard-next/orders/queries.ts
index 6d41692a83..84c8b403ca 100644
--- a/saleor/static/dashboard-next/orders/queries.ts
+++ b/saleor/static/dashboard-next/orders/queries.ts
@@ -204,6 +204,7 @@ export const orderDetailsQuery = gql`
code
country
}
+ defaultWeightUnit
}
}
`;
diff --git a/saleor/static/dashboard-next/orders/types/OrderDetails.ts b/saleor/static/dashboard-next/orders/types/OrderDetails.ts
index 8d78a2372f..9f72b5c443 100644
--- a/saleor/static/dashboard-next/orders/types/OrderDetails.ts
+++ b/saleor/static/dashboard-next/orders/types/OrderDetails.ts
@@ -1,7 +1,7 @@
/* tslint:disable */
// This file was automatically generated and should not be edited.
-import { OrderEventsEmails, OrderEvents, FulfillmentStatus, PaymentStatusEnum, OrderStatus } from "./../../types/globalTypes";
+import { OrderEventsEmails, OrderEvents, FulfillmentStatus, PaymentStatusEnum, OrderStatus, WeightUnitsEnum } from "./../../types/globalTypes";
// ====================================================
// GraphQL query operation: OrderDetails
@@ -262,6 +262,7 @@ export interface OrderDetails_shop_countries {
export interface OrderDetails_shop {
__typename: "Shop";
countries: (OrderDetails_shop_countries | null)[];
+ defaultWeightUnit: WeightUnitsEnum | null;
}
export interface OrderDetails {
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributes/ProductTypeAttributes.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributes/ProductTypeAttributes.tsx
new file mode 100644
index 0000000000..2ea27a294f
--- /dev/null
+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributes/ProductTypeAttributes.tsx
@@ -0,0 +1,82 @@
+import Card from "@material-ui/core/Card";
+import { withStyles } from "@material-ui/core/styles";
+import Table from "@material-ui/core/Table";
+import TableBody from "@material-ui/core/TableBody";
+import TableCell from "@material-ui/core/TableCell";
+import TableHead from "@material-ui/core/TableHead";
+import TableRow from "@material-ui/core/TableRow";
+import * as React from "react";
+
+import CardTitle from "../../../components/CardTitle";
+import Skeleton from "../../../components/Skeleton";
+import i18n from "../../../i18n";
+import { maybe, renderCollection } from "../../../misc";
+import {
+ ProductTypeDetails_productType_productAttributes_edges_node,
+ ProductTypeDetails_productType_variantAttributes_edges_node
+} from "../../types/ProductTypeDetails";
+
+interface ProductTypeAttributesProps {
+ attributes:
+ | ProductTypeDetails_productType_productAttributes_edges_node[]
+ | ProductTypeDetails_productType_variantAttributes_edges_node[];
+ title: string;
+}
+
+const decorate = withStyles({
+ link: {
+ cursor: "pointer" as "pointer"
+ },
+ textLeft: {
+ textAlign: "left" as "left"
+ }
+});
+const ProductTypeAttributes = decorate<ProductTypeAttributesProps>(
+ ({ attributes, classes, title }) => (
+ <Card>
+ <CardTitle title={title} />
+ <Table>
+ <TableHead>
+ <TableRow>
+ <TableCell>{i18n.t("Attribute name")}</TableCell>
+ <TableCell className={classes.textLeft}>
+ {i18n.t("Values")}
+ </TableCell>
+ </TableRow>
+ </TableHead>
+ <TableBody>
+ {renderCollection(
+ attributes,
+ attribute => (
+ <TableRow
+ className={!!attribute ? classes.link : undefined}
+ hover={!!attribute}
+ key={maybe(() => attribute.id)}
+ >
+ <TableCell>
+ {maybe(() => attribute.name) ? attribute.name : <Skeleton />}
+ </TableCell>
+ <TableCell className={classes.textLeft}>
+ {maybe(() => attribute.values) !== undefined ? (
+ attribute.values.map(value => value.name).join(", ")
+ ) : (
+ <Skeleton />
+ )}
+ </TableCell>
+ </TableRow>
+ ),
+ () => (
+ <TableRow>
+ <TableCell colSpan={2}>
+ {i18n.t("No attributes found")}
+ </TableCell>
+ </TableRow>
+ )
+ )}
+ </TableBody>
+ </Table>
+ </Card>
+ )
+);
+ProductTypeAttributes.displayName = "ProductTypeAttributes";
+export default ProductTypeAttributes;
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributes/index.ts b/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributes/index.ts
new file mode 100644
index 0000000000..c59c845326
--- /dev/null
+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeAttributes/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./ProductTypeAttributes";
+export * from "./ProductTypeAttributes";
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeCreatePage/ProductTypeCreatePage.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeCreatePage/ProductTypeCreatePage.tsx
new file mode 100644
index 0000000000..8f7757065c
--- /dev/null
+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeCreatePage/ProductTypeCreatePage.tsx
@@ -0,0 +1,105 @@
+import { withStyles } from "@material-ui/core/styles";
+import * as React from "react";
+
+import Container from "../../../components/Container";
+import Form from "../../../components/Form";
+import PageHeader from "../../../components/PageHeader";
+import SaveButtonBar, {
+ SaveButtonBarState
+} from "../../../components/SaveButtonBar";
+import { TaxRateType, WeightUnitsEnum } from "../../../types/globalTypes";
+import ProductTypeDetails from "../ProductTypeDetails/ProductTypeDetails";
+import ProductTypeShipping from "../ProductTypeShipping/ProductTypeShipping";
+import ProductTypeTaxes from "../ProductTypeTaxes/ProductTypeTaxes";
+
+export interface ProductTypeForm {
+ chargeTaxes: boolean;
+ name: string;
+ isShippingRequired: boolean;
+ taxRate: TaxRateType;
+ weight: number;
+}
+interface ProductTypeCreatePageProps {
+ errors: Array<{
+ field: string;
+ message: string;
+ }>;
+ defaultWeightUnit: WeightUnitsEnum;
+ disabled: boolean;
+ pageTitle: string;
+ saveButtonBarState: SaveButtonBarState;
+ onBack: () => void;
+ onSubmit: (data: ProductTypeForm) => void;
+}
+
+const decorate = withStyles(theme => ({
+ cardContainer: {
+ marginTop: theme.spacing.unit * 2
+ },
+ root: {
+ display: "grid" as "grid",
+ gridColumnGap: theme.spacing.unit * 2 + "px",
+ gridTemplateColumns: "2fr 1fr"
+ }
+}));
+const ProductTypeCreatePage = decorate<ProductTypeCreatePageProps>(
+ ({
+ classes,
+ defaultWeightUnit,
+ disabled,
+ errors,
+ pageTitle,
+ saveButtonBarState,
+ onBack,
+ onSubmit
+ }) => {
+ const formInitialData: ProductTypeForm = {
+ chargeTaxes: true,
+ isShippingRequired: false,
+ name: "",
+ taxRate: TaxRateType.STANDARD,
+ weight: 0
+ };
+ return (
+ <Form errors={errors} initial={formInitialData} onSubmit={onSubmit}>
+ {({ change, data, hasChanged, submit }) => (
+ <Container width="md">
+ <PageHeader title={pageTitle} onBack={onBack} />
+ <div className={classes.root}>
+ <div>
+ <ProductTypeDetails
+ data={data}
+ disabled={disabled}
+ onChange={change}
+ />
+ </div>
+ <div>
+ <ProductTypeShipping
+ disabled={disabled}
+ data={data}
+ defaultWeightUnit={defaultWeightUnit}
+ onChange={change}
+ />
+ <div className={classes.cardContainer}>
+ <ProductTypeTaxes
+ disabled={disabled}
+ data={data}
+ onChange={change}
+ />
+ </div>
+ </div>
+ </div>
+ <SaveButtonBar
+ onCancel={onBack}
+ onSave={submit}
+ disabled={disabled || !hasChanged}
+ state={saveButtonBarState}
+ />
+ </Container>
+ )}
+ </Form>
+ );
+ }
+);
+ProductTypeCreatePage.displayName = "ProductTypeCreatePage";
+export default ProductTypeCreatePage;
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeCreatePage/index.ts b/saleor/static/dashboard-next/productTypes/components/ProductTypeCreatePage/index.ts
new file mode 100644
index 0000000000..2a18e4c3e9
--- /dev/null
+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeCreatePage/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./ProductTypeCreatePage";
+export * from "./ProductTypeCreatePage";
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeDetails/ProductTypeDetails.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeDetails/ProductTypeDetails.tsx
index 0f1e0f21e5..1f20fdf898 100644
--- a/saleor/static/dashboard-next/productTypes/components/ProductTypeDetails/ProductTypeDetails.tsx
+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeDetails/ProductTypeDetails.tsx
@@ -4,28 +4,14 @@ import { withStyles } from "@material-ui/core/styles";
import TextField from "@material-ui/core/TextField";
import * as React from "react";
-import FormSpacer from "../../../components/FormSpacer";
-import MultiAutocompleteSelectField from "../../../components/MultiAutocompleteSelectField";
+import CardTitle from "../../../components/CardTitle";
import i18n from "../../../i18n";
-interface ChoiceType {
- label: string;
- value: string;
-}
interface ProductTypeDetailsProps {
data?: {
name: string;
- hasVariants: boolean;
- productAttributes: ChoiceType[];
- variantAttributes: ChoiceType[];
};
disabled: boolean;
- searchLoading: boolean;
- searchResults: Array<{
- id: string;
- name: string;
- }>;
- onAttributeSearch: (name: string) => void;
onChange: (event: React.ChangeEvent<any>) => void;
}
@@ -35,49 +21,18 @@ const decorate = withStyles({
}
});
const ProductTypeDetails = decorate<ProductTypeDetailsProps>(
- ({
- classes,
- data,
- disabled,
- searchLoading,
- searchResults,
- onAttributeSearch,
- onChange
- }) => (
+ ({ classes, data, disabled, onChange }) => (
<Card className={classes.root}>
+ <CardTitle title={i18n.t("Information")} />
<CardContent>
<TextField
disabled={disabled}
fullWidth
- label={i18n.t("Name")}
+ label={i18n.t("Product Type Name")}
name="name"
onChange={onChange}
value={data.name}
/>
- <FormSpacer />
- <MultiAutocompleteSelectField
- choices={searchResults.map(s => ({ label: s.name, value: s.id }))}
- fetchChoices={onAttributeSearch}
- helperText={i18n.t("Optional")}
- label={i18n.t("Product attributes")}
- loading={searchLoading}
- name="productAttributes"
- onChange={onChange}
- value={data.productAttributes}
- />
- <FormSpacer />
- {data.hasVariants && (
- <MultiAutocompleteSelectField
- choices={searchResults.map(s => ({ label: s.name, value: s.id }))}
- fetchChoices={onAttributeSearch}
- helperText={i18n.t("Optional")}
- label={i18n.t("Variant attributes")}
- loading={searchLoading}
- name="variantAttributes"
- onChange={onChange}
- value={data.variantAttributes}
- />
- )}
</CardContent>
</Card>
)
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx
index 7b37b9ea22..b22fc1cba2 100644
--- a/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx
+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx
@@ -4,6 +4,7 @@ import * as React from "react";
import ActionDialog from "../../../components/ActionDialog";
import Container from "../../../components/Container";
+import { ControlledCheckbox } from "../../../components/ControlledCheckbox";
import Form from "../../../components/Form";
import PageHeader from "../../../components/PageHeader";
import SaveButtonBar, {
@@ -11,42 +12,35 @@ import SaveButtonBar, {
} from "../../../components/SaveButtonBar";
import Toggle from "../../../components/Toggle";
import i18n from "../../../i18n";
-import { TaxRateType } from "../../../types/globalTypes";
+import { maybe } from "../../../misc";
+import { TaxRateType, WeightUnitsEnum } from "../../../types/globalTypes";
+import { ProductTypeDetails_productType } from "../../types/ProductTypeDetails";
+import ProductTypeAttributes from "../ProductTypeAttributes/ProductTypeAttributes";
import ProductTypeDetails from "../ProductTypeDetails/ProductTypeDetails";
-import ProductTypeProperties from "../ProductTypeProperties/ProductTypeProperties";
+import ProductTypeShipping from "../ProductTypeShipping/ProductTypeShipping";
+import ProductTypeTaxes from "../ProductTypeTaxes/ProductTypeTaxes";
interface ChoiceType {
label: string;
value: string;
}
export interface ProductTypeForm {
+ chargeTaxes: boolean;
name: string;
hasVariants: boolean;
isShippingRequired: boolean;
taxRate: TaxRateType;
productAttributes: ChoiceType[];
variantAttributes: ChoiceType[];
+ weight: number;
}
interface ProductTypeDetailsPageProps {
errors: Array<{
field: string;
message: string;
}>;
- productType?: {
- id?: string;
- name?: string;
- hasVariants?: boolean;
- isShippingRequired?: boolean;
- taxRate?: TaxRateType;
- };
- productAttributes?: Array<{
- id: string;
- name: string;
- }>;
- variantAttributes?: Array<{
- id: string;
- name: string;
- }>;
+ productType: ProductTypeDetails_productType;
+ defaultWeightUnit: WeightUnitsEnum;
disabled: boolean;
pageTitle: string;
saveButtonBarState: SaveButtonBarState;
@@ -62,6 +56,9 @@ interface ProductTypeDetailsPageProps {
}
const decorate = withStyles(theme => ({
+ cardContainer: {
+ marginTop: theme.spacing.unit * 2
+ },
root: {
display: "grid" as "grid",
gridColumnGap: theme.spacing.unit * 2 + "px",
@@ -71,40 +68,46 @@ const decorate = withStyles(theme => ({
const ProductTypeDetailsPage = decorate<ProductTypeDetailsPageProps>(
({
classes,
+ defaultWeightUnit,
disabled,
errors,
pageTitle,
- productAttributes,
productType,
saveButtonBarState,
- searchLoading,
- searchResults,
- variantAttributes,
- onAttributeSearch,
onBack,
onDelete,
onSubmit
}) => {
const formInitialData: ProductTypeForm = {
+ chargeTaxes: maybe(() => productType.taxRate !== null, false),
hasVariants:
- productType && productType.hasVariants !== undefined
+ maybe(() => productType.hasVariants) !== undefined
? productType.hasVariants
: false,
isShippingRequired:
- productType && productType.isShippingRequired !== undefined
+ maybe(() => productType.isShippingRequired) !== undefined
? productType.isShippingRequired
: false,
- name:
- productType && productType.name !== undefined ? productType.name : "",
+ name: maybe(() => productType.name) !== undefined ? productType.name : "",
productAttributes:
- productAttributes !== undefined
- ? productAttributes.map(a => ({ label: a.name, value: a.id }))
+ maybe(() => productType.productAttributes.edges) !== undefined
+ ? productType.productAttributes.edges.map(edge => ({
+ label: edge.node.name,
+ value: edge.node.id
+ }))
: [],
- taxRate: productType && productType.taxRate ? productType.taxRate : null,
+ taxRate:
+ maybe(() => productType.taxRate) !== undefined
+ ? productType.taxRate
+ : null,
variantAttributes:
- variantAttributes !== undefined
- ? variantAttributes.map(a => ({ label: a.name, value: a.id }))
- : []
+ maybe(() => productType.variantAttributes.edges) !== undefined
+ ? productType.variantAttributes.edges.map(edge => ({
+ label: edge.node.name,
+ value: edge.node.id
+ }))
+ : [],
+ weight: maybe(() => productType.weight.value)
};
return (
<Toggle>
@@ -124,30 +127,54 @@ const ProductTypeDetailsPage = decorate<ProductTypeDetailsPageProps>(
<ProductTypeDetails
data={data}
disabled={disabled}
- searchLoading={searchLoading}
- searchResults={searchResults
- .filter(
- suggestion =>
- data.productAttributes
- .map(v => v.value)
- .indexOf(suggestion.id) === -1
- )
- .filter(
- suggestion =>
- data.variantAttributes
- .map(v => v.value)
- .indexOf(suggestion.id) === -1
- )}
- onAttributeSearch={onAttributeSearch}
onChange={change}
/>
+ <div className={classes.cardContainer}>
+ <ProductTypeAttributes
+ attributes={maybe(() =>
+ productType.productAttributes.edges.map(
+ edge => edge.node
+ )
+ )}
+ title={i18n.t("Product Attributes")}
+ />
+ </div>
+ <div className={classes.cardContainer}>
+ <ControlledCheckbox
+ checked={data.hasVariants}
+ disabled={disabled}
+ label={i18n.t("This product type has variants")}
+ name="hasVariants"
+ onChange={change}
+ />
+ </div>
+ {data.hasVariants && (
+ <div className={classes.cardContainer}>
+ <ProductTypeAttributes
+ attributes={maybe(() =>
+ productType.variantAttributes.edges.map(
+ edge => edge.node
+ )
+ )}
+ title={i18n.t("Variant Attributes")}
+ />
+ </div>
+ )}
</div>
<div>
- <ProductTypeProperties
- data={data}
+ <ProductTypeShipping
disabled={disabled}
+ data={data}
+ defaultWeightUnit={defaultWeightUnit}
onChange={change}
/>
+ <div className={classes.cardContainer}>
+ <ProductTypeTaxes
+ disabled={disabled}
+ data={data}
+ onChange={change}
+ />
+ </div>
</div>
</div>
<SaveButtonBar
@@ -161,24 +188,22 @@ const ProductTypeDetailsPage = decorate<ProductTypeDetailsPageProps>(
)}
</Form>
- {productType && (
- <ActionDialog
- open={openedDeleteDialog}
- onClose={toggleDeleteDialog}
- onConfirm={onDelete}
- title={i18n.t("Remove product type")}
- variant="delete"
- >
- <DialogContentText
- dangerouslySetInnerHTML={{
- __html: i18n.t(
- "Are you sure you want to remove <strong>{{ name }}</strong>?",
- { name: productType.name }
- )
- }}
- />
- </ActionDialog>
- )}
+ <ActionDialog
+ open={openedDeleteDialog}
+ onClose={toggleDeleteDialog}
+ onConfirm={onDelete}
+ title={i18n.t("Remove product type")}
+ variant="delete"
+ >
+ <DialogContentText
+ dangerouslySetInnerHTML={{
+ __html: i18n.t(
+ "Are you sure you want to remove <strong>{{ name }}</strong>?",
+ { name: maybe(() => productType.name) }
+ )
+ }}
+ />
+ </ActionDialog>
</>
)}
</Toggle>
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeList/ProductTypeList.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeList/ProductTypeList.tsx
index 0f1229adda..c325fb97de 100644
--- a/saleor/static/dashboard-next/productTypes/components/ProductTypeList/ProductTypeList.tsx
+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeList/ProductTypeList.tsx
@@ -6,6 +6,7 @@ import TableCell from "@material-ui/core/TableCell";
import TableFooter from "@material-ui/core/TableFooter";
import TableHead from "@material-ui/core/TableHead";
import TableRow from "@material-ui/core/TableRow";
+import Typography from "@material-ui/core/Typography";
import * as React from "react";
import { ListProps } from "../../..";
@@ -80,7 +81,20 @@ const ProductTypeList = decorate<ProductTypeListProps>(
<TableCell
onClick={productType ? onRowClick(productType.id) : undefined}
>
- {productType ? productType.name : <Skeleton />}
+ {productType ? (
+ <>
+ {productType.name}
+ <Typography variant="caption">
+ {maybe(() => productType.hasVariants)
+ ? i18n.t("Configurable", { context: "product type" })
+ : i18n.t("Simple product", {
+ context: "product type"
+ })}
+ </Typography>
+ </>
+ ) : (
+ <Skeleton />
+ )}
</TableCell>
<TableCell className={classes.leftText}>
{maybe(() => productType.isShippingRequired) !== undefined ? (
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeProperties/ProductTypeProperties.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeProperties/ProductTypeProperties.tsx
deleted file mode 100644
index fc17c92021..0000000000
--- a/saleor/static/dashboard-next/productTypes/components/ProductTypeProperties/ProductTypeProperties.tsx
+++ /dev/null
@@ -1,60 +0,0 @@
-import Card from "@material-ui/core/Card";
-import CardContent from "@material-ui/core/CardContent";
-import * as React from "react";
-
-import CardTitle from "../../../components/CardTitle";
-import ControlledCheckbox from "../../../components/ControlledCheckbox";
-import FormSpacer from "../../../components/FormSpacer";
-import SingleSelectField from "../../../components/SingleSelectField";
-import i18n from "../../../i18n";
-import { translatedTaxRates as taxRates } from "../../../misc";
-
-interface ProductTypePropertiesProps {
- data?: {
- isShippingRequired: boolean;
- hasVariants: boolean;
- taxRate: string;
- };
- disabled: boolean;
- onChange: (event: React.ChangeEvent<any>) => void;
-}
-
-const taxRateChoices = Object.keys(taxRates()).map(key => ({
- label: taxRates()[key],
- value: key
-}));
-
-const ProductTypeProperties: React.StatelessComponent<
- ProductTypePropertiesProps
-> = ({ data, disabled, onChange }) => (
- <Card>
- <CardTitle title={i18n.t("Properties")} />
- <CardContent>
- <ControlledCheckbox
- checked={data.hasVariants}
- disabled={disabled}
- label={i18n.t("Has variants")}
- name="hasVariants"
- onChange={onChange}
- />
- <ControlledCheckbox
- checked={data.isShippingRequired}
- disabled={disabled}
- label={i18n.t("Requires shipping")}
- name="isShippingRequired"
- onChange={onChange}
- />
- <FormSpacer />
- <SingleSelectField
- choices={taxRateChoices}
- hint={i18n.t("Optional")}
- label={i18n.t("Tax rate")}
- name="taxRate"
- onChange={onChange}
- value={data.taxRate}
- />
- </CardContent>
- </Card>
-);
-ProductTypeProperties.displayName = "ProductTypeProperties";
-export default ProductTypeProperties;
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeProperties/index.ts b/saleor/static/dashboard-next/productTypes/components/ProductTypeProperties/index.ts
deleted file mode 100644
index 82910fc43b..0000000000
--- a/saleor/static/dashboard-next/productTypes/components/ProductTypeProperties/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-export { default } from "./ProductTypeProperties";
-export * from "./ProductTypeProperties";
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeShipping/ProductTypeShipping.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeShipping/ProductTypeShipping.tsx
new file mode 100644
index 0000000000..c2bf05bd4c
--- /dev/null
+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeShipping/ProductTypeShipping.tsx
@@ -0,0 +1,53 @@
+import Card from "@material-ui/core/Card";
+import CardContent from "@material-ui/core/CardContent";
+import TextField from "@material-ui/core/TextField";
+import * as React from "react";
+
+import CardTitle from "../../../components/CardTitle";
+import { ControlledCheckbox } from "../../../components/ControlledCheckbox";
+import i18n from "../../../i18n";
+import { WeightUnitsEnum } from "../../../types/globalTypes";
+
+interface ProductTypeShippingProps {
+ data: {
+ isShippingRequired: boolean;
+ weight: number | null;
+ };
+ defaultWeightUnit: WeightUnitsEnum;
+ disabled: boolean;
+ onChange: (event: React.ChangeEvent<any>) => void;
+}
+
+const ProductTypeShipping: React.StatelessComponent<
+ ProductTypeShippingProps
+> = ({ data, defaultWeightUnit, disabled, onChange }) => (
+ <Card>
+ <CardTitle title={i18n.t("Shipping")} />
+ <CardContent>
+ <ControlledCheckbox
+ checked={data.isShippingRequired}
+ disabled={disabled}
+ label={i18n.t("Is this product shippable?")}
+ name="isShippingRequired"
+ onChange={onChange}
+ />
+ {data.isShippingRequired && (
+ <TextField
+ disabled={disabled}
+ InputProps={{ endAdornment: defaultWeightUnit }}
+ label={i18n.t("Weight")}
+ name="weight"
+ helperText={i18n.t(
+ "Used to calculate rates for shipping for products of this product type, when specific weight is not given"
+ )}
+ type="number"
+ value={data.weight}
+ onChange={onChange}
+ />
+ )}
+ </CardContent>
+ </Card>
+);
+
+ProductTypeShipping.displayName = "ProductTypeShipping";
+export default ProductTypeShipping;
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeShipping/index.ts b/saleor/static/dashboard-next/productTypes/components/ProductTypeShipping/index.ts
new file mode 100644
index 0000000000..c0c6382653
--- /dev/null
+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeShipping/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./ProductTypeShipping";
+export * from "./ProductTypeShipping";
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeTaxes/ProductTypeTaxes.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeTaxes/ProductTypeTaxes.tsx
new file mode 100644
index 0000000000..7af29d63e1
--- /dev/null
+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeTaxes/ProductTypeTaxes.tsx
@@ -0,0 +1,58 @@
+import Card from "@material-ui/core/Card";
+import CardContent from "@material-ui/core/CardContent";
+import * as React from "react";
+
+import CardTitle from "../../../components/CardTitle";
+import { ControlledCheckbox } from "../../../components/ControlledCheckbox";
+import { FormSpacer } from "../../../components/FormSpacer";
+import SingleSelectField from "../../../components/SingleSelectField";
+import i18n from "../../../i18n";
+import { translatedTaxRates as taxRates } from "../../../misc";
+import { TaxRateType } from "../../../types/globalTypes";
+
+interface ProductTypeTaxesProps {
+ data: {
+ chargeTaxes: boolean;
+ taxRate: TaxRateType | null;
+ };
+ disabled: boolean;
+ onChange: (event: React.ChangeEvent<any>) => void;
+}
+const taxRateChoices = Object.keys(taxRates()).map(key => ({
+ label: taxRates()[key],
+ value: key
+}));
+const ProductTypeTaxes: React.StatelessComponent<ProductTypeTaxesProps> = ({
+ data,
+ disabled,
+ onChange
+}) => (
+ <Card>
+ <CardTitle title={i18n.t("Shipping")} />
+ <CardContent>
+ <ControlledCheckbox
+ checked={data.chargeTaxes}
+ disabled={disabled}
+ label={i18n.t("Charge taxes for this product")}
+ name="chargeTaxes"
+ onChange={onChange}
+ />
+ {data.chargeTaxes && (
+ <>
+ <FormSpacer />
+ <SingleSelectField
+ choices={taxRateChoices}
+ label={i18n.t("Tax rate (optional)", {
+ context: "select field label"
+ })}
+ name="taxRate"
+ onChange={onChange}
+ value={data.taxRate}
+ />
+ </>
+ )}
+ </CardContent>
+ </Card>
+);
+ProductTypeTaxes.displayName = "ProductTypeTaxes";
+export default ProductTypeTaxes;
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeTaxes/index.ts b/saleor/static/dashboard-next/productTypes/components/ProductTypeTaxes/index.ts
new file mode 100644
index 0000000000..3996500a92
--- /dev/null
+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeTaxes/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./ProductTypeTaxes";
+export * from "./ProductTypeTaxes";
diff --git a/saleor/static/dashboard-next/productTypes/containers/AttributeSearch.tsx b/saleor/static/dashboard-next/productTypes/containers/AttributeSearch.tsx
index 227462ed83..1dd0a4fd4f 100644
--- a/saleor/static/dashboard-next/productTypes/containers/AttributeSearch.tsx
+++ b/saleor/static/dashboard-next/productTypes/containers/AttributeSearch.tsx
@@ -1,6 +1,6 @@
import * as React from "react";
import { QueryResult } from "react-apollo";
-import { searchAttributeQuery, TypedSearchAttributeQuery } from "../queries";
+import { TypedSearchAttributeQuery } from "../queries";
import {
SearchAttribute,
SearchAttributeVariables
@@ -31,7 +31,6 @@ export class AttributeSearchProvider extends React.Component<
if (typeof children === "function") {
return (
<TypedSearchAttributeQuery
- query={searchAttributeQuery}
variables={{ search: this.state.query }}
skip={!this.state.query}
>
diff --git a/saleor/static/dashboard-next/productTypes/fixtures.ts b/saleor/static/dashboard-next/productTypes/fixtures.ts
index 3c4f996532..02fc5c05a9 100644
--- a/saleor/static/dashboard-next/productTypes/fixtures.ts
+++ b/saleor/static/dashboard-next/productTypes/fixtures.ts
@@ -4,7 +4,7 @@ import { ProductTypeList_productTypes_edges_node } from "./types/ProductTypeList
export const productTypes: ProductTypeList_productTypes_edges_node[] = [
{
- __typename: "ProductType",
+ __typename: "ProductType" as "ProductType",
hasVariants: true,
id: "UHJvZHVjdFR5cGU6NA==",
isShippingRequired: true,
@@ -12,7 +12,7 @@ export const productTypes: ProductTypeList_productTypes_edges_node[] = [
taxRate: "FOODSTUFFS" as TaxRateType
},
{
- __typename: "ProductType",
+ __typename: "ProductType" as "ProductType",
hasVariants: false,
id: "UHJvZHVjdFR5cGU6NQ==",
isShippingRequired: false,
@@ -20,7 +20,7 @@ export const productTypes: ProductTypeList_productTypes_edges_node[] = [
taxRate: "STANDARD" as TaxRateType
},
{
- __typename: "ProductType",
+ __typename: "ProductType" as "ProductType",
hasVariants: false,
id: "UHJvZHVjdFR5cGU6Mg==",
isShippingRequired: true,
@@ -28,7 +28,7 @@ export const productTypes: ProductTypeList_productTypes_edges_node[] = [
taxRate: "STANDARD" as TaxRateType
},
{
- __typename: "ProductType",
+ __typename: "ProductType" as "ProductType",
hasVariants: true,
id: "UHJvZHVjdFR5cGU6Mw==",
isShippingRequired: true,
@@ -36,7 +36,7 @@ export const productTypes: ProductTypeList_productTypes_edges_node[] = [
taxRate: "STANDARD" as TaxRateType
},
{
- __typename: "ProductType",
+ __typename: "ProductType" as "ProductType",
hasVariants: true,
id: "UHJvZHVjdFR5cGU6MQ==",
isShippingRequired: true,
@@ -44,72 +44,519 @@ export const productTypes: ProductTypeList_productTypes_edges_node[] = [
taxRate: "STANDARD" as TaxRateType
}
].map(productType => ({
- ...productType,
- __typename: "ProductType" as "ProductType"
+ __typename: "ProductType" as "ProductType",
+ ...productType
}));
export const productType: ProductTypeDetails_productType = {
- hasVariants: true,
- id: "pt77249",
- isShippingRequired: true,
- name: "Cotton",
+ __typename: "ProductType" as "ProductType",
+ hasVariants: false,
+ id: "UHJvZHVjdFR5cGU6NQ==",
+ isShippingRequired: false,
+ name: "E-books",
productAttributes: [
{
- id: "pta27565",
- name: "Virginia",
- slug: "Virginia",
- sortNumber: 0
+ __typename: "Attribute" as "Attribute",
+ id: "UHJvZHVjdEF0dHJpYnV0ZTo5",
+ name: "Author",
+ slug: "author",
+ values: [
+ {
+ __typename: "AttributeValue" as "AttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjI0",
+ name: "John Doe",
+ slug: "john-doe"
+ },
+ {
+ __typename: "AttributeValue" as "AttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjI1",
+ name: "Milionare Pirate",
+ slug: "milionare-pirate"
+ }
+ ]
},
{
- id: "pta84650",
- name: "Tasty Granite Table",
- slug: "Tasty-Granite-Table",
- sortNumber: 1
+ __typename: "Attribute" as "Attribute",
+ id: "UHJvZHVjdEF0dHJpYnV0ZToxMQ==",
+ name: "Language",
+ slug: "language",
+ values: [
+ {
+ __typename: "AttributeValue" as "AttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjI4",
+ name: "English",
+ slug: "english"
+ },
+ {
+ __typename: "AttributeValue" as "AttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjI5",
+ name: "Pirate",
+ slug: "pirate"
+ }
+ ]
},
- { id: "pta50103", sortNumber: 2, name: "Small", slug: "Small" }
- ].map(attribute => ({
- ...attribute,
- __typename: "Attribute" as "Attribute"
- })),
- taxRate: TaxRateType.ACCOMMODATION,
- variantAttributes: [
{
- id: "pta24175",
- name: "enhance",
- slug: "enhance",
- sortNumber: 4
- },
- {
- id: "pta66068",
- name: "Djibouti Franc",
- slug: "Djibouti-Franc",
- sortNumber: 5
+ __typename: "Attribute" as "Attribute",
+ id: "UHJvZHVjdEF0dHJpYnV0ZToxMA==",
+ name: "Publisher",
+ slug: "publisher",
+ values: [
+ {
+ __typename: "AttributeValue" as "AttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjI2",
+ name: "Mirumee Press",
+ slug: "mirumee-press"
+ },
+ {
+ __typename: "AttributeValue" as "AttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjI3",
+ name: "Saleor Publishing",
+ slug: "saleor-publishing"
+ }
+ ]
}
- ].map(attribute => ({ ...attribute, __typename: "Attribute" as "Attribute" }))
+ ],
+ taxRate: "STANDARD" as TaxRateType,
+ variantAttributes: [],
+ weight: {
+ __typename: "Weight",
+ unit: "kg",
+ value: 7.82
+ }
};
export const attributes = [
- { id: "pta27565", sortNumber: 0, name: "Virginia", slug: "Virginia" },
{
- id: "pta84650",
- name: "Tasty Granite Table",
- slug: "Tasty-Granite-Table",
- sortNumber: 1
+ node: {
+ __typename: "ProductAttribute",
+ id: "UHJvZHVjdEF0dHJpYnV0ZTo5",
+ name: "Author",
+ slug: "author",
+ values: [
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjI0",
+ name: "John Doe",
+ slug: "john-doe",
+ sortOrder: 0,
+ type: "STRING",
+ value: ""
+ },
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjI1",
+ name: "Milionare Pirate",
+ slug: "milionare-pirate",
+ sortOrder: 1,
+ type: "STRING",
+ value: ""
+ }
+ ]
+ }
},
- { id: "pta50103", sortNumber: 2, name: "Small", slug: "Small" },
{
- id: "pta95599",
- name: "Home Loan Account",
- slug: "Home-Loan-Account",
- sortNumber: 3
+ node: {
+ __typename: "ProductAttribute",
+ id: "UHJvZHVjdEF0dHJpYnV0ZTo2",
+ name: "Box Size",
+ slug: "box-size",
+ values: [
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjE1",
+ name: "100g",
+ slug: "100g",
+ sortOrder: 0,
+ type: "STRING",
+ value: ""
+ },
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjE2",
+ name: "250g",
+ slug: "250g",
+ sortOrder: 1,
+ type: "STRING",
+ value: ""
+ },
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjE3",
+ name: "500g",
+ slug: "500g",
+ sortOrder: 2,
+ type: "STRING",
+ value: ""
+ },
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjE4",
+ name: "1kg",
+ slug: "1kg",
+ sortOrder: 3,
+ type: "STRING",
+ value: ""
+ }
+ ]
+ }
},
- { id: "pta24175", sortNumber: 4, name: "enhance", slug: "enhance" },
{
- id: "pta66068",
- name: "Djibouti Franc",
- slug: "Djibouti-Franc",
- sortNumber: 5
+ node: {
+ __typename: "ProductAttribute",
+ id: "UHJvZHVjdEF0dHJpYnV0ZToz",
+ name: "Brand",
+ slug: "brand",
+ values: [
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjY=",
+ name: "Saleor",
+ slug: "saleor",
+ sortOrder: 0,
+ type: "STRING",
+ value: ""
+ }
+ ]
+ }
+ },
+ {
+ node: {
+ __typename: "ProductAttribute",
+ id: "UHJvZHVjdEF0dHJpYnV0ZTo4",
+ name: "Candy Box Size",
+ slug: "candy-box-size",
+ values: [
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjIx",
+ name: "100g",
+ slug: "100g",
+ sortOrder: 0,
+ type: "STRING",
+ value: ""
+ },
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjIy",
+ name: "250g",
+ slug: "250g",
+ sortOrder: 1,
+ type: "STRING",
+ value: ""
+ },
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjIz",
+ name: "500g",
+ slug: "500g",
+ sortOrder: 2,
+ type: "STRING",
+ value: ""
+ }
+ ]
+ }
},
- { id: "pta41930", sortNumber: 6, name: "Rustic", slug: "Rustic" },
- { id: "pta91235", sortNumber: 7, name: "Principal", slug: "Principal" },
- { id: "pta50181", sortNumber: 8, name: "Outdoors", slug: "Outdoors" },
- { id: "pta38700", sortNumber: 9, name: "Canada", slug: "Canada" }
-];
+ {
+ node: {
+ __typename: "ProductAttribute",
+ id: "UHJvZHVjdEF0dHJpYnV0ZTo1",
+ name: "Coffee Genre",
+ slug: "coffee-genre",
+ values: [
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjEz",
+ name: "Arabica",
+ slug: "arabica",
+ sortOrder: 0,
+ type: "STRING",
+ value: ""
+ },
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjE0",
+ name: "Robusta",
+ slug: "robusta",
+ sortOrder: 1,
+ type: "STRING",
+ value: ""
+ }
+ ]
+ }
+ },
+ {
+ node: {
+ __typename: "ProductAttribute",
+ id: "UHJvZHVjdEF0dHJpYnV0ZToy",
+ name: "Collar",
+ slug: "collar",
+ values: [
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjM=",
+ name: "Round",
+ slug: "round",
+ sortOrder: 0,
+ type: "STRING",
+ value: ""
+ },
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjQ=",
+ name: "V-Neck",
+ slug: "v-neck",
+ sortOrder: 1,
+ type: "STRING",
+ value: ""
+ },
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjU=",
+ name: "Polo",
+ slug: "polo",
+ sortOrder: 2,
+ type: "STRING",
+ value: ""
+ }
+ ]
+ }
+ },
+ {
+ node: {
+ __typename: "ProductAttribute",
+ id: "UHJvZHVjdEF0dHJpYnV0ZTox",
+ name: "Color",
+ slug: "color",
+ values: [
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjE=",
+ name: "Blue",
+ slug: "blue",
+ sortOrder: 0,
+ type: "STRING",
+ value: ""
+ },
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjI=",
+ name: "White",
+ slug: "white",
+ sortOrder: 1,
+ type: "STRING",
+ value: ""
+ }
+ ]
+ }
+ },
+ {
+ node: {
+ __typename: "ProductAttribute",
+ id: "UHJvZHVjdEF0dHJpYnV0ZToxMg==",
+ name: "Cover",
+ slug: "cover",
+ values: [
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjMw",
+ name: "Soft",
+ slug: "soft",
+ sortOrder: 0,
+ type: "STRING",
+ value: ""
+ },
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjMx",
+ name: "Hard",
+ slug: "hard",
+ sortOrder: 1,
+ type: "STRING",
+ value: ""
+ },
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjMy",
+ name: "Middle soft",
+ slug: "middle-soft",
+ sortOrder: 2,
+ type: "STRING",
+ value: ""
+ },
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjMz",
+ name: "Middle hard",
+ slug: "middle-hard",
+ sortOrder: 3,
+ type: "STRING",
+ value: ""
+ },
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjM0",
+ name: "Middle",
+ slug: "middle",
+ sortOrder: 4,
+ type: "STRING",
+ value: ""
+ },
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjM1",
+ name: "Very hard",
+ slug: "very-hard",
+ sortOrder: 5,
+ type: "STRING",
+ value: ""
+ }
+ ]
+ }
+ },
+ {
+ node: {
+ __typename: "ProductAttribute",
+ id: "UHJvZHVjdEF0dHJpYnV0ZTo3",
+ name: "Flavor",
+ slug: "flavor",
+ values: [
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjE5",
+ name: "Sour",
+ slug: "sour",
+ sortOrder: 0,
+ type: "STRING",
+ value: ""
+ },
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjIw",
+ name: "Sweet",
+ slug: "sweet",
+ sortOrder: 1,
+ type: "STRING",
+ value: ""
+ }
+ ]
+ }
+ },
+ {
+ node: {
+ __typename: "ProductAttribute",
+ id: "UHJvZHVjdEF0dHJpYnV0ZToxMQ==",
+ name: "Language",
+ slug: "language",
+ values: [
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjI4",
+ name: "English",
+ slug: "english",
+ sortOrder: 0,
+ type: "STRING",
+ value: ""
+ },
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjI5",
+ name: "Pirate",
+ slug: "pirate",
+ sortOrder: 1,
+ type: "STRING",
+ value: ""
+ }
+ ]
+ }
+ },
+ {
+ node: {
+ __typename: "ProductAttribute",
+ id: "UHJvZHVjdEF0dHJpYnV0ZToxMA==",
+ name: "Publisher",
+ slug: "publisher",
+ values: [
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjI2",
+ name: "Mirumee Press",
+ slug: "mirumee-press",
+ sortOrder: 0,
+ type: "STRING",
+ value: ""
+ },
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjI3",
+ name: "Saleor Publishing",
+ slug: "saleor-publishing",
+ sortOrder: 1,
+ type: "STRING",
+ value: ""
+ }
+ ]
+ }
+ },
+ {
+ node: {
+ __typename: "ProductAttribute",
+ id: "UHJvZHVjdEF0dHJpYnV0ZTo0",
+ name: "Size",
+ slug: "size",
+ values: [
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjc=",
+ name: "XS",
+ slug: "xs",
+ sortOrder: 0,
+ type: "STRING",
+ value: ""
+ },
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjg=",
+ name: "S",
+ slug: "s",
+ sortOrder: 1,
+ type: "STRING",
+ value: ""
+ },
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjk=",
+ name: "M",
+ slug: "m",
+ sortOrder: 2,
+ type: "STRING",
+ value: ""
+ },
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjEw",
+ name: "L",
+ slug: "l",
+ sortOrder: 3,
+ type: "STRING",
+ value: ""
+ },
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjEx",
+ name: "XL",
+ slug: "xl",
+ sortOrder: 4,
+ type: "STRING",
+ value: ""
+ },
+ {
+ __typename: "ProductAttributeValue",
+ id: "UHJvZHVjdEF0dHJpYnV0ZVZhbHVlOjEy",
+ name: "XXL",
+ slug: "xxl",
+ sortOrder: 5,
+ type: "STRING",
+ value: ""
+ }
+ ]
+ }
+ }
+].map(edge => edge.node);
diff --git a/saleor/static/dashboard-next/productTypes/queries.ts b/saleor/static/dashboard-next/productTypes/queries.ts
index 5e5c3ee4bb..9854b1e84f 100644
--- a/saleor/static/dashboard-next/productTypes/queries.ts
+++ b/saleor/static/dashboard-next/productTypes/queries.ts
@@ -1,6 +1,7 @@
import gql from "graphql-tag";
-import { Query, QueryProps } from "react-apollo";
+import { TypedQuery } from "../queries";
+import { ProductTypeCreateData } from "./types/ProductTypeCreateData";
import {
ProductTypeDetails,
ProductTypeDetailsVariables
@@ -47,12 +48,13 @@ export const productTypeDetailsFragment = gql`
variantAttributes {
...AttributeFragment
}
+ weight {
+ unit
+ value
+ }
}
`;
-export const TypedProductTypeListQuery = Query as React.ComponentType<
- QueryProps<ProductTypeList, ProductTypeListVariables>
->;
export const productTypeListQuery = gql`
${productTypeFragment}
query ProductTypeList(
@@ -76,22 +78,39 @@ export const productTypeListQuery = gql`
}
}
`;
+export const TypedProductTypeListQuery = TypedQuery<
+ ProductTypeList,
+ ProductTypeListVariables
+>(productTypeListQuery);
-export const TypedProductTypeDetailsQuery = Query as React.ComponentType<
- QueryProps<ProductTypeDetails, ProductTypeDetailsVariables>
->;
export const productTypeDetailsQuery = gql`
${productTypeDetailsFragment}
query ProductTypeDetails($id: ID!) {
productType(id: $id) {
...ProductTypeDetailsFragment
}
+ shop {
+ defaultWeightUnit
+ }
+ }
+`;
+export const TypedProductTypeDetailsQuery = TypedQuery<
+ ProductTypeDetails,
+ ProductTypeDetailsVariables
+>(productTypeDetailsQuery);
+
+export const productTypeCreateDataQuery = gql`
+ query ProductTypeCreateData {
+ shop {
+ defaultWeightUnit
+ }
}
`;
+export const TypedProductTypeCreateDataQuery = TypedQuery<
+ ProductTypeCreateData,
+ {}
+>(productTypeCreateDataQuery);
-export const TypedSearchAttributeQuery = Query as React.ComponentType<
- QueryProps<SearchAttribute, SearchAttributeVariables>
->;
export const searchAttributeQuery = gql`
${attributeFragment}
query SearchAttribute($search: String!) {
@@ -104,3 +123,7 @@ export const searchAttributeQuery = gql`
}
}
`;
+export const TypedSearchAttributeQuery = TypedQuery<
+ SearchAttribute,
+ SearchAttributeVariables
+>(searchAttributeQuery);
diff --git a/saleor/static/dashboard-next/productTypes/types/ProductTypeCreateData.ts b/saleor/static/dashboard-next/productTypes/types/ProductTypeCreateData.ts
new file mode 100644
index 0000000000..e470950a5d
--- /dev/null
+++ b/saleor/static/dashboard-next/productTypes/types/ProductTypeCreateData.ts
@@ -0,0 +1,17 @@
+/* tslint:disable */
+// This file was automatically generated and should not be edited.
+
+import { WeightUnitsEnum } from "./../../types/globalTypes";
+
+// ====================================================
+// GraphQL query operation: ProductTypeCreateData
+// ====================================================
+
+export interface ProductTypeCreateData_shop {
+ __typename: "Shop";
+ defaultWeightUnit: WeightUnitsEnum | null;
+}
+
+export interface ProductTypeCreateData {
+ shop: ProductTypeCreateData_shop | null;
+}
diff --git a/saleor/static/dashboard-next/productTypes/types/ProductTypeDetails.ts b/saleor/static/dashboard-next/productTypes/types/ProductTypeDetails.ts
index d9a7f32770..b327de60e8 100644
--- a/saleor/static/dashboard-next/productTypes/types/ProductTypeDetails.ts
+++ b/saleor/static/dashboard-next/productTypes/types/ProductTypeDetails.ts
@@ -1,7 +1,7 @@
/* tslint:disable */
// This file was automatically generated and should not be edited.
-import { TaxRateType } from "./../../types/globalTypes";
+import { TaxRateType, WeightUnitsEnum } from "./../../types/globalTypes";
// ====================================================
// GraphQL query operation: ProductTypeDetails
@@ -37,6 +37,12 @@ export interface ProductTypeDetails_productType_variantAttributes {
values: (ProductTypeDetails_productType_variantAttributes_values | null)[] | null;
}
+export interface ProductTypeDetails_productType_weight {
+ __typename: "Weight";
+ unit: string;
+ value: number;
+}
+
export interface ProductTypeDetails_productType {
__typename: "ProductType";
id: string;
@@ -46,10 +52,17 @@ export interface ProductTypeDetails_productType {
taxRate: TaxRateType | null;
productAttributes: (ProductTypeDetails_productType_productAttributes | null)[] | null;
variantAttributes: (ProductTypeDetails_productType_variantAttributes | null)[] | null;
+ weight: ProductTypeDetails_productType_weight | null;
+}
+
+export interface ProductTypeDetails_shop {
+ __typename: "Shop";
+ defaultWeightUnit: WeightUnitsEnum | null;
}
export interface ProductTypeDetails {
productType: ProductTypeDetails_productType | null;
+ shop: ProductTypeDetails_shop | null;
}
export interface ProductTypeDetailsVariables {
diff --git a/saleor/static/dashboard-next/productTypes/types/ProductTypeDetailsFragment.ts b/saleor/static/dashboard-next/productTypes/types/ProductTypeDetailsFragment.ts
index 87a0d3daad..4840a92926 100644
--- a/saleor/static/dashboard-next/productTypes/types/ProductTypeDetailsFragment.ts
+++ b/saleor/static/dashboard-next/productTypes/types/ProductTypeDetailsFragment.ts
@@ -37,6 +37,12 @@ export interface ProductTypeDetailsFragment_variantAttributes {
values: (ProductTypeDetailsFragment_variantAttributes_values | null)[] | null;
}
+export interface ProductTypeDetailsFragment_weight {
+ __typename: "Weight";
+ unit: string;
+ value: number;
+}
+
export interface ProductTypeDetailsFragment {
__typename: "ProductType";
id: string;
@@ -46,4 +52,5 @@ export interface ProductTypeDetailsFragment {
taxRate: TaxRateType | null;
productAttributes: (ProductTypeDetailsFragment_productAttributes | null)[] | null;
variantAttributes: (ProductTypeDetailsFragment_variantAttributes | null)[] | null;
+ weight: ProductTypeDetailsFragment_weight | null;
}
diff --git a/saleor/static/dashboard-next/productTypes/views/ProductTypeCreate.tsx b/saleor/static/dashboard-next/productTypes/views/ProductTypeCreate.tsx
index 2e505472b9..7114dd2862 100644
--- a/saleor/static/dashboard-next/productTypes/views/ProductTypeCreate.tsx
+++ b/saleor/static/dashboard-next/productTypes/views/ProductTypeCreate.tsx
@@ -4,68 +4,59 @@ import Navigator from "../../components/Navigator";
import { productTypeDetailsUrl, productTypeListUrl } from "..";
import Messages from "../../components/messages";
import i18n from "../../i18n";
-import ProductTypeDetailsPage, {
+import { maybe } from "../../misc";
+import ProductTypeCreatePage, {
ProductTypeForm
-} from "../components/ProductTypeDetailsPage";
-import { AttributeSearchProvider } from "../containers/AttributeSearch";
+} from "../components/ProductTypeCreatePage";
import { TypedProductTypeCreateMutation } from "../mutations";
+import { TypedProductTypeCreateDataQuery } from "../queries";
import { ProductTypeCreate as ProductTypeCreateMutation } from "../types/ProductTypeCreate";
-const formData = {
- hasVariants: false,
- isShippingRequired: false,
- name: "",
- productAttributes: [],
- taxRate: undefined,
- variantAttributes: []
-};
-
export const ProductTypeCreate: React.StatelessComponent = () => (
<Messages>
{pushMessage => (
<Navigator>
- {navigate => (
- <AttributeSearchProvider>
- {(searchAttribute, searchState) => {
- const handleCreateSuccess = (
- updateData: ProductTypeCreateMutation
+ {navigate => {
+ const handleCreateSuccess = (
+ updateData: ProductTypeCreateMutation
+ ) => {
+ if (updateData.productTypeCreate.errors.length === 0) {
+ pushMessage({
+ text: i18n.t("Successfully created product type")
+ });
+ navigate(
+ productTypeDetailsUrl(
+ updateData.productTypeCreate.productType.id
+ )
+ );
+ }
+ };
+ return (
+ <TypedProductTypeCreateMutation onCompleted={handleCreateSuccess}>
+ {(
+ createProductType,
+ { loading: loadingCreate, data: createProductTypeData }
) => {
- if (updateData.productTypeCreate.errors.length === 0) {
- pushMessage({
- text: i18n.t("Successfully created product type")
+ const handleCreate = (formData: ProductTypeForm) =>
+ createProductType({
+ variables: {
+ input: {
+ hasVariants: false,
+ isShippingRequired: formData.isShippingRequired,
+ name: formData.name,
+ taxRate: formData.chargeTaxes ? formData.taxRate : null,
+ weight: formData.weight
+ }
+ }
});
- navigate(
- productTypeDetailsUrl(
- updateData.productTypeCreate.productType.id
- )
- );
- }
- };
- return (
- <TypedProductTypeCreateMutation
- onCompleted={handleCreateSuccess}
- >
- {(
- createProductType,
- { loading: loadingCreate, data: createProductTypeData }
- ) => {
- const handleCreate = (formData: ProductTypeForm) =>
- createProductType({
- variables: {
- input: {
- ...formData,
- productAttributes: formData.productAttributes.map(
- choice => choice.value
- ),
- variantAttributes: formData.variantAttributes.map(
- choice => choice.value
- )
- }
- }
- });
- return (
- <ProductTypeDetailsPage
- disabled={loadingCreate}
+ return (
+ <TypedProductTypeCreateDataQuery>
+ {({ data, loading }) => (
+ <ProductTypeCreatePage
+ defaultWeightUnit={maybe(
+ () => data.shop.defaultWeightUnit
+ )}
+ disabled={loadingCreate || loading}
errors={
createProductTypeData
? createProductTypeData.productTypeCreate.errors
@@ -74,35 +65,19 @@ export const ProductTypeCreate: React.StatelessComponent = () => (
pageTitle={i18n.t("Create Product Type", {
context: "page title"
})}
- productType={formData}
- productAttributes={[]}
- variantAttributes={[]}
saveButtonBarState={
loadingCreate ? "loading" : "default"
}
- searchLoading={
- searchState ? searchState.loading : false
- }
- searchResults={
- searchState &&
- searchState.data &&
- searchState.data.attributes
- ? searchState.data.attributes.edges.map(
- edge => edge.node
- )
- : []
- }
- onAttributeSearch={searchAttribute}
onBack={() => navigate(productTypeListUrl)}
onSubmit={handleCreate}
/>
- );
- }}
- </TypedProductTypeCreateMutation>
- );
- }}
- </AttributeSearchProvider>
- )}
+ )}
+ </TypedProductTypeCreateDataQuery>
+ );
+ }}
+ </TypedProductTypeCreateMutation>
+ );
+ }}
</Navigator>
)}
</Messages>
diff --git a/saleor/static/dashboard-next/productTypes/views/ProductTypeList.tsx b/saleor/static/dashboard-next/productTypes/views/ProductTypeList.tsx
index 2cf6ca38d5..fbcaa2363a 100644
--- a/saleor/static/dashboard-next/productTypes/views/ProductTypeList.tsx
+++ b/saleor/static/dashboard-next/productTypes/views/ProductTypeList.tsx
@@ -4,12 +4,12 @@ import {
productTypeAddUrl,
productTypeDetailsUrl,
productTypeListUrl
-} from "../";
+} from "..";
import ErrorMessageCard from "../../components/ErrorMessageCard";
import Navigator from "../../components/Navigator";
import { createPaginationData, createPaginationState, maybe } from "../../misc";
import ProductTypeListPage from "../components/ProductTypeListPage";
-import { productTypeListQuery, TypedProductTypeListQuery } from "../queries";
+import { TypedProductTypeListQuery } from "../queries";
interface ProductTypeListProps {
params: {
@@ -27,11 +27,7 @@ export const ProductTypeList: React.StatelessComponent<
{navigate => {
const paginationState = createPaginationState(PAGINATE_BY, params);
return (
- <TypedProductTypeListQuery
- query={productTypeListQuery}
- variables={paginationState}
- fetchPolicy="network-only"
- >
+ <TypedProductTypeListQuery variables={paginationState}>
{({ data, loading, error }) => {
if (error) {
return <ErrorMessageCard message="Something went wrong" />;
diff --git a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate.tsx b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate.tsx
index c355e3886a..fe05d5af7c 100644
--- a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate.tsx
+++ b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate.tsx
@@ -11,10 +11,7 @@ import ProductTypeDetailsPage, {
} from "../components/ProductTypeDetailsPage";
import { AttributeSearchProvider } from "../containers/AttributeSearch";
import ProductTypeOperations from "../containers/ProductTypeOperations";
-import {
- productTypeDetailsQuery,
- TypedProductTypeDetailsQuery
-} from "../queries";
+import { TypedProductTypeDetailsQuery } from "../queries";
import { ProductTypeDelete } from "../types/ProductTypeDelete";
import { ProductTypeUpdate as ProductTypeUpdateMutation } from "../types/ProductTypeUpdate";
@@ -29,10 +26,7 @@ export const ProductTypeUpdate: React.StatelessComponent<
{pushMessage => (
<Navigator>
{navigate => (
- <TypedProductTypeDetailsQuery
- query={productTypeDetailsQuery}
- variables={{ id }}
- >
+ <TypedProductTypeDetailsQuery variables={{ id }}>
{({ data, error, loading: dataLoading }) => {
if (error) {
return (
@@ -81,19 +75,26 @@ export const ProductTypeUpdate: React.StatelessComponent<
updateProductType.mutate({
id,
input: {
- ...formData,
+ hasVariants: formData.hasVariants,
+ isShippingRequired: formData.isShippingRequired,
+ name: formData.name,
productAttributes: formData.productAttributes.map(
choice => choice.value
),
+ taxRate: formData.taxRate,
variantAttributes: formData.variantAttributes.map(
choice => choice.value
- )
+ ),
+ weight: formData.weight
}
});
};
const loading = mutationLoading || dataLoading;
return (
<ProductTypeDetailsPage
+ defaultWeightUnit={maybe(
+ () => data.shop.defaultWeightUnit
+ )}
disabled={loading}
errors={errors}
pageTitle={
@@ -101,30 +102,18 @@ export const ProductTypeUpdate: React.StatelessComponent<
? data.productType.name
: undefined
}
- productType={data ? data.productType : undefined}
- productAttributes={maybe(
- () => data.productType.productAttributes,
- []
- )}
- variantAttributes={maybe(
- () => data.productType.variantAttributes,
- []
- )}
+ productType={maybe(() => data.productType)}
saveButtonBarState={
loading ? "loading" : "default"
}
- searchLoading={
- searchState ? searchState.loading : false
- }
- searchResults={
- searchState &&
- searchState.data &&
- searchState.data.attributes
- ? searchState.data.attributes.edges.map(
- edge => edge.node
- )
- : []
- }
+ searchLoading={maybe(() => searchState.loading)}
+ searchResults={maybe(
+ () =>
+ searchState.data.attributes.edges.map(
+ edge => edge.node
+ ),
+ []
+ )}
onAttributeSearch={searchAttribute}
onBack={() => navigate(productTypeListUrl)}
onDelete={handleDelete}
diff --git a/saleor/static/dashboard-next/storybook/config.js b/saleor/static/dashboard-next/storybook/config.js
index 644ebe8191..d239705acf 100644
--- a/saleor/static/dashboard-next/storybook/config.js
+++ b/saleor/static/dashboard-next/storybook/config.js
@@ -95,6 +95,7 @@ function loadStories() {
require("./stories/vouchers/VoucherListPage");
// Product types
+ require("./stories/productTypes/ProductTypeCreatePage");
require("./stories/productTypes/ProductTypeListPage");
require("./stories/productTypes/ProductTypeDetailsPage");
diff --git a/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeCreatePage.tsx b/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeCreatePage.tsx
new file mode 100644
index 0000000000..83a1887a69
--- /dev/null
+++ b/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeCreatePage.tsx
@@ -0,0 +1,24 @@
+import { storiesOf } from "@storybook/react";
+import * as React from "react";
+
+import ProductTypeCreatePage from "../../../productTypes/components/ProductTypeCreatePage";
+import { WeightUnitsEnum } from "../../../types/globalTypes";
+import Decorator from "../../Decorator";
+
+const props = {
+ defaultWeightUnit: "kg" as WeightUnitsEnum,
+ disabled: false,
+ errors: [],
+ onBack: () => undefined,
+ onDelete: () => undefined,
+ onSubmit: () => undefined,
+ pageTitle: "Create product type",
+ saveButtonBarState: "default"
+};
+
+storiesOf("Views / Product types / Create product type", module)
+ .addDecorator(Decorator)
+ .add("default", () => <ProductTypeCreatePage {...props} />)
+ .add("loading", () => (
+ <ProductTypeCreatePage {...props} disabled={true} pageTitle={undefined} />
+ ));
diff --git a/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeDetailsPage.tsx b/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeDetailsPage.tsx
index 6bad1bd138..6adf3b72a1 100644
--- a/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeDetailsPage.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/productTypes/ProductTypeDetailsPage.tsx
@@ -3,38 +3,32 @@ import * as React from "react";
import ProductTypeDetailsPage from "../../../productTypes/components/ProductTypeDetailsPage";
import { attributes, productType } from "../../../productTypes/fixtures";
+import { WeightUnitsEnum } from "../../../types/globalTypes";
import Decorator from "../../Decorator";
+const props = {
+ defaultWeightUnit: "kg" as WeightUnitsEnum,
+ disabled: false,
+ errors: [],
+ onAttributeSearch: () => undefined,
+ onBack: () => undefined,
+ onDelete: () => undefined,
+ onSubmit: () => undefined,
+ pageTitle: productType.name,
+ productType,
+ saveButtonBarState: "default",
+ searchLoading: false,
+ searchResults: attributes
+};
+
storiesOf("Views / Product types / Product type details", module)
.addDecorator(Decorator)
- .add("default", () => (
- <ProductTypeDetailsPage
- disabled={false}
- errors={[]}
- pageTitle={productType.name}
- productType={productType}
- productAttributes={productType.productAttributes}
- variantAttributes={productType.variantAttributes}
- saveButtonBarState="default"
- searchLoading={false}
- searchResults={attributes}
- onAttributeSearch={undefined}
- onBack={() => undefined}
- onDelete={undefined}
- onSubmit={() => undefined}
- />
- ))
+ .add("default", () => <ProductTypeDetailsPage {...props} />)
.add("loading", () => (
<ProductTypeDetailsPage
+ {...props}
disabled={true}
- errors={[]}
pageTitle={undefined}
- saveButtonBarState="default"
- searchLoading={false}
- searchResults={[]}
- onAttributeSearch={undefined}
- onBack={() => undefined}
- onDelete={undefined}
- onSubmit={() => undefined}
+ productType={undefined}
/>
));