Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Use slugs
dominik-zeglencd704ac69c66
diff --git a/saleor/static/dashboard-next/components/AddressEdit/AddressEdit.tsx b/saleor/static/dashboard-next/components/AddressEdit/AddressEdit.tsxindex 428340604e..1822bc5318 100644--- a/saleor/static/dashboard-next/components/AddressEdit/AddressEdit.tsx+++ b/saleor/static/dashboard-next/components/AddressEdit/AddressEdit.tsx@@ -9,10 +9,11 @@ import React from "react";import { AddressTypeInput } from "../../customers/types";import i18n from "../../i18n";-import { maybe } from "../../misc";import { FormErrors } from "../../types";import FormSpacer from "../FormSpacer";-import SingleAutocompleteSelectField from "../SingleAutocompleteSelectField";+import SingleAutocompleteSelectField, {+ SingleAutocompleteChoiceType+} from "../SingleAutocompleteSelectField";const styles = (theme: Theme) =>createStyles({@@ -24,24 +25,25 @@ const styles = (theme: Theme) =>});interface AddressEditProps extends WithStyles<typeof styles> {- countries?: Array<{- code: string;- label: string;- }>;+ countries: SingleAutocompleteChoiceType[];+ countryDisplayValue: string;data: AddressTypeInput;disabled?: boolean;errors: FormErrors<keyof AddressTypeInput>;onChange(event: React.ChangeEvent<any>);+ onCountryChange(event: React.ChangeEvent<any>);}const AddressEdit = withStyles(styles, { name: "AddressEdit" })(({classes,countries,+ countryDisplayValue,data,disabled,errors,- onChange+ onChange,+ onCountryChange}: AddressEditProps) => (<><div className={classes.root}>@@ -152,16 +154,14 @@ const AddressEdit = withStyles(styles, { name: "AddressEdit" })(<div><SingleAutocompleteSelectFielddisabled={disabled}+ displayValue={countryDisplayValue}error={!!errors.country}helperText={errors.country}label={i18n.t("Country")}name="country"- onChange={onChange}+ onChange={onCountryChange}value={data.country}- choices={maybe(- () => countries.map(c => ({ ...c, value: c.code })),- []- )}+ choices={countries}InputProps={{autoComplete: "off"}}diff --git a/saleor/static/dashboard-next/components/MultiAutocompleteSelectField/MultiAutocompleteSelectField.tsx b/saleor/static/dashboard-next/components/MultiAutocompleteSelectField/MultiAutocompleteSelectField.tsxindex 5edc763714..ff57834da8 100644--- a/saleor/static/dashboard-next/components/MultiAutocompleteSelectField/MultiAutocompleteSelectField.tsx+++ b/saleor/static/dashboard-next/components/MultiAutocompleteSelectField/MultiAutocompleteSelectField.tsx@@ -234,7 +234,7 @@ export const MultiAutocompleteSelectFieldComponent = withStyles(styles, {</Downshift><div className={classes.chipContainer}>{displayValues.map(value => (- <div className={classes.chip}>+ <div className={classes.chip} key={value.value}><div className={classes.chipInner}><Typography className={classes.chipLabel} variant="caption">{value.label}diff --git a/saleor/static/dashboard-next/customers/components/CustomerAddressDialog/CustomerAddressDialog.tsx b/saleor/static/dashboard-next/customers/components/CustomerAddressDialog/CustomerAddressDialog.tsxindex dd2d77d809..1925f7d8c2 100644--- a/saleor/static/dashboard-next/customers/components/CustomerAddressDialog/CustomerAddressDialog.tsx+++ b/saleor/static/dashboard-next/customers/components/CustomerAddressDialog/CustomerAddressDialog.tsx@@ -12,9 +12,11 @@ import ConfirmButton, {ConfirmButtonTransitionState} from "@saleor/components/ConfirmButton";import Form from "@saleor/components/Form";-import i18n from "../../../i18n";-import { maybe } from "../../../misc";-import { UserError } from "../../../types";+import useStateFromProps from "@saleor/hooks/useStateFromProps";+import i18n from "@saleor/i18n";+import { maybe } from "@saleor/misc";+import { UserError } from "@saleor/types";+import createSingleAutocompleteSelectHandler from "@saleor/utils/handlers/singleAutocompleteSelectChangeHandler";import { AddressTypeInput } from "../../types";import { CustomerAddresses_user_addresses } from "../../types/CustomerAddresses";@@ -50,14 +52,14 @@ const CustomerAddressDialog = withStyles(styles, {})(onClose,onConfirm}: CustomerAddressDialogProps & WithStyles<typeof styles>) => {+ const [countryDisplayName, setCountryDisplayName] = useStateFromProps(+ maybe(() => address.country.country, "")+ );const initialForm: AddressTypeInput = {city: maybe(() => address.city, ""),cityArea: maybe(() => address.cityArea, ""),companyName: maybe(() => address.companyName, ""),- country: {- label: maybe(() => address.country.country, ""),- value: maybe(() => address.country.code, "")- },+ country: maybe(() => address.country.code, ""),countryArea: maybe(() => address.countryArea, ""),firstName: maybe(() => address.firstName, ""),lastName: maybe(() => address.lastName, ""),@@ -66,6 +68,16 @@ const CustomerAddressDialog = withStyles(styles, {})(streetAddress1: maybe(() => address.streetAddress1, ""),streetAddress2: maybe(() => address.streetAddress2, "")};++ const countryChoices = maybe(+ () =>+ countries.map(country => ({+ label: country.label,+ value: country.code+ })),+ []+ );+return (<DialogonClose={onClose}@@ -75,38 +87,48 @@ const CustomerAddressDialog = withStyles(styles, {})(maxWidth="sm"><Form initial={initialForm} errors={errors} onSubmit={onConfirm}>- {({ change, data, errors, submit }) => (- <>- <DialogTitle>- {variant === "create"- ? i18n.t("Add Address")- : i18n.t("Edit Address")}- </DialogTitle>- <DialogContent className={classes.overflow}>- <AddressEdit- countries={countries}- data={data}- errors={errors}- onChange={change}- />- </DialogContent>- <DialogActions>- <Button onClick={onClose}>- {i18n.t("Cancel", { context: "button" })}- </Button>- <ConfirmButton- transitionState={confirmButtonState}- color="primary"- variant="contained"- onClick={submit}- type="submit"- >- {i18n.t("Save Address", { context: "button" })}- <AddIcon />- </ConfirmButton>- </DialogActions>- </>- )}+ {({ change, data, errors, submit }) => {+ const handleCountrySelect = createSingleAutocompleteSelectHandler(+ change,+ setCountryDisplayName,+ countryChoices+ );++ return (+ <>+ <DialogTitle>+ {variant === "create"+ ? i18n.t("Add Address")+ : i18n.t("Edit Address")}+ </DialogTitle>+ <DialogContent className={classes.overflow}>+ <AddressEdit+ countries={countryChoices}+ data={data}+ countryDisplayValue={countryDisplayName}+ errors={errors}+ onChange={change}+ onCountryChange={handleCountrySelect}+ />+ </DialogContent>+ <DialogActions>+ <Button onClick={onClose}>+ {i18n.t("Cancel", { context: "button" })}+ </Button>+ <ConfirmButton+ transitionState={confirmButtonState}+ color="primary"+ variant="contained"+ onClick={submit}+ type="submit"+ >+ {i18n.t("Save Address", { context: "button" })}+ <AddIcon />+ </ConfirmButton>+ </DialogActions>+ </>+ );+ }}</Form></Dialog>);diff --git a/saleor/static/dashboard-next/customers/components/CustomerCreateAddress/CustomerCreateAddress.tsx b/saleor/static/dashboard-next/customers/components/CustomerCreateAddress/CustomerCreateAddress.tsxindex eb4e13fc7a..9ba4fa0c2e 100644--- a/saleor/static/dashboard-next/customers/components/CustomerCreateAddress/CustomerCreateAddress.tsx+++ b/saleor/static/dashboard-next/customers/components/CustomerCreateAddress/CustomerCreateAddress.tsx@@ -7,10 +7,10 @@ import React from "react";import AddressEdit from "@saleor/components/AddressEdit";import CardTitle from "@saleor/components/CardTitle";import { FormSpacer } from "@saleor/components/FormSpacer";+import { SingleAutocompleteChoiceType } from "@saleor/components/SingleAutocompleteSelectField";import i18n from "../../../i18n";import { FormErrors } from "../../../types";import { AddressTypeInput } from "../../types";-import { CustomerCreateData_shop_countries } from "../../types/CustomerCreateData";const styles = createStyles({overflow: {@@ -19,11 +19,13 @@ const styles = createStyles({});export interface CustomerCreateAddressProps extends WithStyles<typeof styles> {- countries: CustomerCreateData_shop_countries[];+ countries: SingleAutocompleteChoiceType[];+ countryDisplayName: string;data: AddressTypeInput;disabled: boolean;errors: FormErrors<keyof AddressTypeInput>;onChange(event: React.ChangeEvent<any>);+ onCountryChange(event: React.ChangeEvent<any>);}const CustomerCreateAddress = withStyles(styles, {@@ -32,10 +34,12 @@ const CustomerCreateAddress = withStyles(styles, {({classes,countries,+ countryDisplayName,data,disabled,errors,- onChange+ onChange,+ onCountryChange}: CustomerCreateAddressProps) => (<Card className={classes.overflow}><CardTitle title={i18n.t("Primary address")} />@@ -45,14 +49,13 @@ const CustomerCreateAddress = withStyles(styles, {</Typography><FormSpacer /><AddressEdit- countries={countries.map(country => ({- code: country.code,- label: country.country- }))}+ countries={countries}data={data}disabled={disabled}+ countryDisplayValue={countryDisplayName}errors={errors}onChange={onChange}+ onCountryChange={onCountryChange}/></CardContent></Card>diff --git a/saleor/static/dashboard-next/customers/components/CustomerCreatePage/CustomerCreatePage.tsx b/saleor/static/dashboard-next/customers/components/CustomerCreatePage/CustomerCreatePage.tsxindex 1894148a61..a38cc3cbb7 100644--- a/saleor/static/dashboard-next/customers/components/CustomerCreatePage/CustomerCreatePage.tsx+++ b/saleor/static/dashboard-next/customers/components/CustomerCreatePage/CustomerCreatePage.tsx@@ -8,6 +8,7 @@ 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 createSingleAutocompleteSelectHandler from "@saleor/utils/handlers/singleAutocompleteSelectChangeHandler";import i18n from "../../../i18n";import { UserError } from "../../../types";import { AddressTypeInput } from "../../types";@@ -27,10 +28,7 @@ const initialForm: CustomerCreatePageFormData = {city: "",cityArea: "",companyName: "",- country: {- label: "",- value: ""- },+ country: "",countryArea: "",customerFirstName: "",customerLastName: "",@@ -60,46 +58,69 @@ const CustomerCreatePage: React.StatelessComponent<CustomerCreatePageProps> = ({saveButtonBar,onBack,onSubmit-}: CustomerCreatePageProps) => (- <Form initial={initialForm} onSubmit={onSubmit} errors={errors} confirmLeave>- {({ change, data, errors: formErrors, hasChanged, submit }) => (- <Container>- <AppHeader onBack={onBack}>{i18n.t("Customers")}</AppHeader>- <PageHeader title={i18n.t("Add customer")} />- <Grid>- <div>- <CustomerCreateDetails- data={data}- disabled={disabled}- errors={formErrors}- onChange={change}- />- <CardSpacer />- <CustomerCreateAddress- countries={countries}- data={data}- disabled={disabled}- errors={formErrors}- onChange={change}- />- <CardSpacer />- <CustomerCreateNote- data={data}- disabled={disabled}- errors={formErrors}- onChange={change}+}: CustomerCreatePageProps) => {+ const [countryDisplayName, setCountryDisplayName] = React.useState("");+ const countryChoices = countries.map(country => ({+ label: country.country,+ value: country.code+ }));++ return (+ <Form+ initial={initialForm}+ onSubmit={onSubmit}+ errors={errors}+ confirmLeave+ >+ {({ change, data, errors: formErrors, hasChanged, submit }) => {+ const handleCountrySelect = createSingleAutocompleteSelectHandler(+ change,+ setCountryDisplayName,+ countryChoices+ );++ return (+ <Container>+ <AppHeader onBack={onBack}>{i18n.t("Customers")}</AppHeader>+ <PageHeader title={i18n.t("Add customer")} />+ <Grid>+ <div>+ <CustomerCreateDetails+ data={data}+ disabled={disabled}+ errors={formErrors}+ onChange={change}+ />+ <CardSpacer />+ <CustomerCreateAddress+ countries={countryChoices}+ countryDisplayName={countryDisplayName}+ data={data}+ disabled={disabled}+ errors={formErrors}+ onChange={change}+ onCountryChange={handleCountrySelect}+ />+ <CardSpacer />+ <CustomerCreateNote+ data={data}+ disabled={disabled}+ errors={formErrors}+ onChange={change}+ />+ </div>+ </Grid>+ <SaveButtonBar+ disabled={disabled || !hasChanged}+ state={saveButtonBar}+ onSave={submit}+ onCancel={onBack}/>- </div>- </Grid>- <SaveButtonBar- disabled={disabled || !hasChanged}- state={saveButtonBar}- onSave={submit}- onCancel={onBack}- />- </Container>- )}- </Form>-);+ </Container>+ );+ }}+ </Form>+ );+};CustomerCreatePage.displayName = "CustomerCreatePage";export default CustomerCreatePage;diff --git a/saleor/static/dashboard-next/customers/types.ts b/saleor/static/dashboard-next/customers/types.tsindex 1eee8acacf..fa3a76f4ed 100644--- a/saleor/static/dashboard-next/customers/types.ts+++ b/saleor/static/dashboard-next/customers/types.ts@@ -2,10 +2,7 @@ export interface AddressTypeInput {city: string;cityArea?: string;companyName?: string;- country: {- label: string;- value: string;- };+ country: string;countryArea?: string;firstName: string;lastName: string;diff --git a/saleor/static/dashboard-next/customers/views/CustomerAddresses.tsx b/saleor/static/dashboard-next/customers/views/CustomerAddresses.tsxindex bbb4fb0dc5..9f72bce6ab 100644--- a/saleor/static/dashboard-next/customers/views/CustomerAddresses.tsx+++ b/saleor/static/dashboard-next/customers/views/CustomerAddresses.tsx@@ -133,6 +133,16 @@ const CustomerAddresses: React.FC<CustomerAddressesProps> = ({[]));++ const countryChoices = maybe(+ () =>+ shop.countries.map(country => ({+ code: country.code,+ label: country.country+ })),+ []+ );+return (<><WindowTitle@@ -156,14 +166,7 @@ const CustomerAddresses: React.FC<CustomerAddressesProps> = ({<CustomerAddressDialogaddress={undefined}confirmButtonState={createAddressTransitionState}- countries={maybe(- () =>- shop.countries.map(country => ({- code: country.code,- label: country.country- })),- []- )}+ countries={countryChoices}errors={maybe(() =>createCustomerAddressOpts.data.addressCreate@@ -173,14 +176,11 @@ const CustomerAddresses: React.FC<CustomerAddressesProps> = ({open={params.action === "add"}variant="create"onClose={closeModal}- onConfirm={formData =>+ onConfirm={input =>createCustomerAddress({variables: {id,- input: {- ...formData,- country: formData.country.value- }+ input}})}@@ -192,7 +192,7 @@ const CustomerAddresses: React.FC<CustomerAddressesProps> = ({))}confirmButtonState={updateAddressTransitionState}- countries={[]}+ countries={countryChoices}errors={maybe(() =>updateCustomerAddressOpts.data.addressUpdate@@ -202,14 +202,11 @@ const CustomerAddresses: React.FC<CustomerAddressesProps> = ({open={params.action === "edit"}variant="edit"onClose={closeModal}- onConfirm={formData =>+ onConfirm={input =>updateCustomerAddress({variables: {id: params.id,- input: {- ...formData,- country: formData.country.value- }+ input}})}diff --git a/saleor/static/dashboard-next/customers/views/CustomerCreate.tsx b/saleor/static/dashboard-next/customers/views/CustomerCreate.tsxindex f89a867d68..10b5719d03 100644--- a/saleor/static/dashboard-next/customers/views/CustomerCreate.tsx+++ b/saleor/static/dashboard-next/customers/views/CustomerCreate.tsx@@ -67,14 +67,8 @@ export const CustomerCreate: React.StatelessComponent<{}> = () => {createCustomer({variables: {input: {- defaultBillingAddress: {- ...address,- country: address.country.value- },- defaultShippingAddress: {- ...address,- country: address.country.value- },+ defaultBillingAddress: address,+ defaultShippingAddress: address,email: formData.email,firstName: formData.customerFirstName,lastName: formData.customerLastName,diff --git a/saleor/static/dashboard-next/misc.ts b/saleor/static/dashboard-next/misc.tsindex c4686dd1a6..91a2311608 100644--- a/saleor/static/dashboard-next/misc.ts+++ b/saleor/static/dashboard-next/misc.ts@@ -96,10 +96,7 @@ export const transformAddressToForm = (data: AddressType) => ({city: maybe(() => data.city, ""),cityArea: maybe(() => data.cityArea, ""),companyName: maybe(() => data.companyName, ""),- country: {- label: maybe(() => data.country.country, ""),- value: maybe(() => data.country.code, "")- },+ country: maybe(() => data.country.code, ""),countryArea: maybe(() => data.countryArea, ""),firstName: maybe(() => data.firstName, ""),lastName: maybe(() => data.lastName, ""),diff --git a/saleor/static/dashboard-next/orders/components/OrderAddressEditDialog/OrderAddressEditDialog.tsx b/saleor/static/dashboard-next/orders/components/OrderAddressEditDialog/OrderAddressEditDialog.tsxindex fa5eb177fb..c351178cb8 100644--- a/saleor/static/dashboard-next/orders/components/OrderAddressEditDialog/OrderAddressEditDialog.tsx+++ b/saleor/static/dashboard-next/orders/components/OrderAddressEditDialog/OrderAddressEditDialog.tsx@@ -11,6 +11,9 @@ import ConfirmButton, {ConfirmButtonTransitionState} from "@saleor/components/ConfirmButton";import Form from "@saleor/components/Form";+import useStateFromProps from "@saleor/hooks/useStateFromProps";+import { maybe } from "@saleor/misc";+import createSingleAutocompleteSelectHandler from "@saleor/utils/handlers/singleAutocompleteSelectChangeHandler";import { AddressTypeInput } from "../../../customers/types";import i18n from "../../../i18n";import { UserError } from "../../../types";@@ -48,43 +51,69 @@ const OrderAddressEditDialog = withStyles(styles, {countries,onClose,onConfirm- }: OrderAddressEditDialogProps) => (- <Dialog onClose={onClose} open={open} classes={{ paper: classes.overflow }}>- <Form initial={address} errors={errors} onSubmit={onConfirm}>- {({ change, data, errors, submit }) => (- <>- <DialogTitle>- {variant === "billing"- ? i18n.t("Edit billing address", { context: "title" })- : i18n.t("Edit shipping address", { context: "title" })}- </DialogTitle>- <DialogContent className={classes.overflow}>- <AddressEdit- countries={countries}- data={data}- errors={errors}- onChange={change}- />- </DialogContent>- <DialogActions>- <Button onClick={onClose}>- {i18n.t("Cancel", { context: "button" })}- </Button>- <ConfirmButton- transitionState={confirmButtonState}- color="primary"- variant="contained"- onClick={submit}- type="submit"- >- {i18n.t("Confirm", { context: "button" })}- </ConfirmButton>- </DialogActions>- </>- )}- </Form>- </Dialog>- )+ }: OrderAddressEditDialogProps) => {+ const [countryDisplayName, setCountryDisplayName] = useStateFromProps(+ maybe(+ () => countries.find(country => address.country === country.code).label+ )+ );+ const countryChoices = countries.map(country => ({+ label: country.label,+ value: country.code+ }));++ return (+ <Dialog+ onClose={onClose}+ open={open}+ classes={{ paper: classes.overflow }}+ >+ <Form initial={address} errors={errors} onSubmit={onConfirm}>+ {({ change, data, errors, submit }) => {+ const handleCountrySelect = createSingleAutocompleteSelectHandler(+ change,+ setCountryDisplayName,+ countryChoices+ );++ return (+ <>+ <DialogTitle>+ {variant === "billing"+ ? i18n.t("Edit billing address", { context: "title" })+ : i18n.t("Edit shipping address", { context: "title" })}+ </DialogTitle>+ <DialogContent className={classes.overflow}>+ <AddressEdit+ countries={countryChoices}+ countryDisplayValue={countryDisplayName}+ data={data}+ errors={errors}+ onChange={change}+ onCountryChange={handleCountrySelect}+ />+ </DialogContent>+ <DialogActions>+ <Button onClick={onClose}>+ {i18n.t("Cancel", { context: "button" })}+ </Button>+ <ConfirmButton+ transitionState={confirmButtonState}+ color="primary"+ variant="contained"+ onClick={submit}+ type="submit"+ >+ {i18n.t("Confirm", { context: "button" })}+ </ConfirmButton>+ </DialogActions>+ </>+ );+ }}+ </Form>+ </Dialog>+ );+ });OrderAddressEditDialog.displayName = "OrderAddressEditDialog";export default OrderAddressEditDialog;diff --git a/saleor/static/dashboard-next/orders/components/OrderCustomer/OrderCustomer.tsx b/saleor/static/dashboard-next/orders/components/OrderCustomer/OrderCustomer.tsxindex 54be95db30..c2319a9118 100644--- a/saleor/static/dashboard-next/orders/components/OrderCustomer/OrderCustomer.tsx+++ b/saleor/static/dashboard-next/orders/components/OrderCustomer/OrderCustomer.tsx@@ -17,6 +17,8 @@ import Hr from "@saleor/components/Hr";import Link from "@saleor/components/Link";import SingleAutocompleteSelectField from "@saleor/components/SingleAutocompleteSelectField";import Skeleton from "@saleor/components/Skeleton";+import useStateFromProps from "@saleor/hooks/useStateFromProps";+import createSingleAutocompleteSelectHandler from "@saleor/utils/handlers/singleAutocompleteSelectChangeHandler";import { SearchCustomers_customers_edges_node } from "../../../containers/SearchCustomers/types/SearchCustomers";import { customerUrl } from "../../../customers/urls";import i18n from "../../../i18n";@@ -72,12 +74,17 @@ const OrderCustomer = withStyles(styles, { name: "OrderCustomer" })(onProfileView,onShippingAddressEdit}: OrderCustomerProps) => {+ const user = maybe(() => order.user);++ const [userDisplayName, setUserDisplayName] = useStateFromProps(+ maybe(() => user.email, "")+ );const [isInEditMode, setEditModeStatus] = React.useState(false);const toggleEditMode = () => setEditModeStatus(!isInEditMode);const billingAddress = maybe(() => order.billingAddress);const shippingAddress = maybe(() => order.shippingAddress);- const user = maybe(() => order.user);+return (<Card><CardTitle@@ -99,28 +106,35 @@ const OrderCustomer = withStyles(styles, { name: "OrderCustomer" })({user === undefined ? (<Skeleton />) : isInEditMode && canEditCustomer ? (- <Form initial={{ query: { label: "", value: "" } }}>+ <Form initial={{ query: "" }}>{({ change, data }) => {const handleChange = (event: React.ChangeEvent<any>) => {change(event);+ const value = event.target.value;+onCustomerEdit({- [event.target.value.value.includes("@")- ? "userEmail"- : "user"]: event.target.value.value+ [value.includes("@") ? "userEmail" : "user"]: value});toggleEditMode();};+ const userChoices = maybe(() => users, []).map(user => ({+ label: user.email,+ value: user.id+ }));+ const handleUserChange = createSingleAutocompleteSelectHandler(+ handleChange,+ setUserDisplayName,+ userChoices+ );return (<SingleAutocompleteSelectFieldallowCustomValues={true}- choices={maybe(() => users, []).map(user => ({- label: user.email,- value: user.id- }))}+ choices={userChoices}+ displayValue={userDisplayName}fetchChoices={fetchUsers}loading={loading}placeholder={i18n.t("Search Customers")}- onChange={handleChange}+ onChange={handleUserChange}name="query"value={data.query}/>diff --git a/saleor/static/dashboard-next/orders/components/OrderCustomerEditDialog/OrderCustomerEditDialog.tsx b/saleor/static/dashboard-next/orders/components/OrderCustomerEditDialog/OrderCustomerEditDialog.tsxindex 0c1e7921c2..7000c2289d 100644--- a/saleor/static/dashboard-next/orders/components/OrderCustomerEditDialog/OrderCustomerEditDialog.tsx+++ b/saleor/static/dashboard-next/orders/components/OrderCustomerEditDialog/OrderCustomerEditDialog.tsx@@ -38,10 +38,8 @@ const styles = (theme: Theme) =>interface OrderCustomerEditDialogProps extends WithStyles<typeof styles> {confirmButtonState: ConfirmButtonTransitionState;open: boolean;- user?: {- label: string;- value: string;- };+ user: string;+ userDisplayValue: string;users?: Array<{id: string;email: string;@@ -62,6 +60,7 @@ const OrderCustomerEditDialog = withStyles(styles, {open,loading,user,+ userDisplayValue,users,fetchUsers,onChange,@@ -83,6 +82,7 @@ const OrderCustomerEditDialog = withStyles(styles, {choices={choices}allowCustomValuesloading={loading}+ displayValue={userDisplayValue}name="user"value={user}fetchChoices={fetchUsers}diff --git a/saleor/static/dashboard-next/orders/views/OrderDetails/index.tsx b/saleor/static/dashboard-next/orders/views/OrderDetails/index.tsxindex a186a89b07..8a4052c42f 100644--- a/saleor/static/dashboard-next/orders/views/OrderDetails/index.tsx+++ b/saleor/static/dashboard-next/orders/views/OrderDetails/index.tsx@@ -606,14 +606,11 @@ export const OrderDetails: React.StatelessComponent<OrderDetailsProps> = ({open={params.action === "edit-shipping-address"}variant="shipping"onClose={closeModal}- onConfirm={variables =>+ onConfirm={shippingAddress =>orderUpdate.mutate({id,input: {- shippingAddress: {- ...variables,- country: variables.country.value- }+ shippingAddress}})}@@ -642,14 +639,11 @@ export const OrderDetails: React.StatelessComponent<OrderDetailsProps> = ({open={params.action === "edit-billing-address"}variant="billing"onClose={closeModal}- onConfirm={variables =>+ onConfirm={billingAddress =>orderUpdate.mutate({id,input: {- billingAddress: {- ...variables,- country: variables.country.value- }+ billingAddress}})}diff --git a/saleor/static/dashboard-next/products/components/ProductAttributes/ProductAttributes.tsx b/saleor/static/dashboard-next/products/components/ProductAttributes/ProductAttributes.tsxindex 200e70f8ef..32aab9ecdc 100644--- a/saleor/static/dashboard-next/products/components/ProductAttributes/ProductAttributes.tsx+++ b/saleor/static/dashboard-next/products/components/ProductAttributes/ProductAttributes.tsx@@ -40,6 +40,9 @@ export interface ProductAttributesProps {const useStyles = makeStyles((theme: Theme) => ({attributeSection: {+ "&:last-of-type": {+ paddingBottom: 0+ },padding: `${theme.spacing.unit * 2}px 0`},attributeSectionLabel: {@@ -50,6 +53,9 @@ const useStyles = makeStyles((theme: Theme) => ({overflow: "visible"},cardContent: {+ "&:last-child": {+ paddingBottom: theme.spacing.unit+ },paddingTop: theme.spacing.unit},expansionBar: {@@ -80,7 +86,7 @@ function getMultiChoices(): MultiAutocompleteChoiceType[] {return values.map(value => ({label: value.name,- value: value.id+ value: value.slug}));}@@ -89,7 +95,7 @@ function getSingleChoices(): SingleAutocompleteChoiceType[] {return values.map(value => ({label: value.name,- value: value.id+ value: value.slug}));}@@ -127,61 +133,64 @@ const ProductAttributes: React.FC<ProductAttributesProps> = ({/></IconButton></div>- <Hr />- {expanded &&- attributes.map(attribute => (- <>- <Grid className={classes.attributeSection} variant="uniform">- <div className={classes.attributeSectionLabel}>- <Typography>{attribute.label}</Typography>- </div>- <div>- {attribute.data.inputType ===- AttributeInputTypeEnum.DROPDOWN ? (- <SingleAutocompleteSelectField- choices={getSingleChoices(attribute.data.values)}- disabled={disabled}- displayValue={maybe(- () =>- attribute.data.values.find(- value => value.id === attribute.value[0]- ).name,- ""- )}- name={`attribute:${attribute.label}`}- label={i18n.t("Value")}- value={attribute.value[0]}- onChange={event =>- onChange(attribute.id, event.target.value)- }- />- ) : (- <MultiAutocompleteSelectField- choices={getMultiChoices(attribute.data.values)}- displayValues={attribute.data.values- .filter(- value =>- !!attribute.value.find(attributeValue =>- attributeValue.includes(value.id)- )- )- .map(value => ({- label: value.name,- value: value.id- }))}- label={i18n.t("Values")}- name={`attribute:${attribute.label}`}- value={attribute.value}- onChange={event =>- onMultiChange(attribute.id, event.target.value)- }- />- )}- </div>- </Grid>- <Hr />- </>- ))}+ {expanded && (+ <>+ <Hr />+ {attributes.map((attribute, attributeIndex) => (+ <React.Fragment key={attribute.id}>+ {attributeIndex > 0 && <Hr />}+ <Grid className={classes.attributeSection} variant="uniform">+ <div className={classes.attributeSectionLabel}>+ <Typography>{attribute.label}</Typography>+ </div>+ <div>+ {attribute.data.inputType ===+ AttributeInputTypeEnum.DROPDOWN ? (+ <SingleAutocompleteSelectField+ choices={getSingleChoices(attribute.data.values)}+ disabled={disabled}+ displayValue={maybe(+ () =>+ attribute.data.values.find(+ value => value.slug === attribute.value[0]+ ).name,+ ""+ )}+ name={`attribute:${attribute.label}`}+ label={i18n.t("Value")}+ value={attribute.value[0]}+ onChange={event =>+ onChange(attribute.id, event.target.value)+ }+ />+ ) : (+ <MultiAutocompleteSelectField+ choices={getMultiChoices(attribute.data.values)}+ displayValues={attribute.data.values+ .filter(+ value =>+ !!attribute.value.find(attributeValue =>+ attributeValue.includes(value.slug)+ )+ )+ .map(value => ({+ label: value.name,+ value: value.slug+ }))}+ label={i18n.t("Values")}+ name={`attribute:${attribute.label}`}+ value={attribute.value}+ onChange={event =>+ onMultiChange(attribute.id, event.target.value)+ }+ />+ )}+ </div>+ </Grid>+ </React.Fragment>+ ))}+ </>+ )}</CardContent></Card>);diff --git a/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx b/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsxindex 7c2fcae4aa..5f2f8f52ce 100644--- a/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx+++ b/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx@@ -30,13 +30,11 @@ import {getChoices,getProductUpdatePageFormData,getSelectedAttributesFromProduct,+ ProductAttributeValueChoices,ProductUpdatePageFormData} from "../../utils/data";import {createAttributeChangeHandler,- createCategorySelectHandler,- createCollectionSelectHandler,- AttributeValueChoice,createAttributeMultiChangeHandler} from "../../utils/handlers";import ProductAttributes, { ProductAttributeInput } from "../ProductAttributes";@@ -109,12 +107,16 @@ export const ProductUpdatePage: React.FC<ProductUpdatePageProps> = ({toggleAll,toolbar}) => {+ const attributeInput = React.useMemo(+ () => getAttributeInputFromProduct(product),+ [product]+ );const { change: changeAttributeData, data: attributes } = useFormset(- getAttributeInputFromProduct(product)+ attributeInput);const [selectedAttributes, setSelectedAttributes] = useStateFromProps<- AttributeValueChoice[]+ ProductAttributeValueChoices[]>(getSelectedAttributesFromProduct(product));const [selectedCategory, setSelectedCategory] = useStateFromProps(@@ -172,6 +174,7 @@ export const ProductUpdatePage: React.FC<ProductUpdatePageProps> = ({changeAttributeData,setSelectedAttributes,selectedAttributes,+ attributes,triggerChange);const handleAttributeMultiChange = createAttributeMultiChangeHandler(diff --git a/saleor/static/dashboard-next/products/utils/data.ts b/saleor/static/dashboard-next/products/utils/data.tsindex 4717ca7e70..8359943fec 100644--- a/saleor/static/dashboard-next/products/utils/data.ts+++ b/saleor/static/dashboard-next/products/utils/data.ts@@ -40,7 +40,7 @@ export function getAttributeInputFromProduct(},id: attribute.attribute.id,label: attribute.attribute.name,- value: attribute.values.map(value => value.id)+ value: attribute.values.map(value => value.slug)})),[]);@@ -59,7 +59,7 @@ export function getSelectedAttributesFromProduct(id: attribute.attribute.id,values: attribute.values.map(value => ({label: value.name,- value: value.id+ value: value.slug}))})),[]@@ -124,18 +124,19 @@ export function getProductUpdatePageFormData(variants: ProductDetails_product_variants[]): ProductUpdatePageFormData {return {- basePrice: maybe(() => product.basePrice.amount),- category: maybe(() => product.category.id),+ basePrice: maybe(() => product.basePrice.amount, 0),+ category: maybe(() => product.category.id, ""),chargeTaxes: maybe(() => product.chargeTaxes, false),- collections: maybe(() =>- product.collections.map(collection => collection.id)+ collections: maybe(+ () => product.collections.map(collection => collection.id),+ []),description: maybe(() => JSON.parse(product.descriptionJson)),isPublished: maybe(() => product.isPublished, false),- name: maybe(() => product.name),- publicationDate: maybe(() => product.publicationDate),- seoDescription: maybe(() => product.seoDescription) || "",- seoTitle: maybe(() => product.seoTitle) || "",+ name: maybe(() => product.name, ""),+ publicationDate: maybe(() => product.publicationDate, ""),+ seoDescription: maybe(() => product.seoDescription, ""),+ seoTitle: maybe(() => product.seoTitle, ""),sku: maybe(() =>product.productType.hasVariants? undefineddiff --git a/saleor/static/dashboard-next/products/utils/handlers.ts b/saleor/static/dashboard-next/products/utils/handlers.tsindex 6a936e9344..b821c88d43 100644--- a/saleor/static/dashboard-next/products/utils/handlers.ts+++ b/saleor/static/dashboard-next/products/utils/handlers.ts@@ -9,30 +9,38 @@ import {} from "./data";export function createAttributeChangeHandler(- changeAttributeData: FormsetChange<string>,+ changeAttributeData: FormsetChange<string[]>,setSelectedAttributes: (data: ProductAttributeValueChoices[]) => void,selectedAttributes: ProductAttributeValueChoices[],+ attributes: FormsetData<ProductAttributeInputData>,triggerChange: () => void): FormsetChange {- return (id: string, value: string) => {- const itemIndex = selectedAttributes.findIndex(item => item.id === id);+ return (attributeId: string, value: string) => {+ const attributeValue = attributes+ .find(attribute => attribute.id === attributeId)+ .data.values.find(attributeValue => attributeValue.slug === value);++ const valueChoice = {+ label: attributeValue.name,+ value+ };++ const itemIndex = selectedAttributes.findIndex(+ item => item.id === attributeId+ );const attribute = selectedAttributes[itemIndex];setSelectedAttributes([...selectedAttributes.slice(0, itemIndex),{...attribute,- values: [- attribute.values.find(- attributeValue => attributeValue.value === value- )- ]+ values: [valueChoice]},...selectedAttributes.slice(itemIndex + 1)]);triggerChange();- changeAttributeData(id, value);+ changeAttributeData(attributeId, [value]);};}@@ -43,17 +51,19 @@ export function createAttributeMultiChangeHandler(attributes: FormsetData<ProductAttributeInputData>,triggerChange: () => void): FormsetChange {- return (id: string, value: string) => {+ return (attributeId: string, value: string) => {const attributeValue = attributes- .find(attribute => attribute.id === id)- .data.values.find(attributeValue => attributeValue.id === value);+ .find(attribute => attribute.id === attributeId)+ .data.values.find(attributeValue => attributeValue.slug === value);const valueChoice = {label: attributeValue.name,value};- const itemIndex = selectedAttributes.findIndex(item => item.id === id);+ const itemIndex = selectedAttributes.findIndex(+ item => item.id === attributeId+ );const field = selectedAttributes[itemIndex].values;const attributeValues = toggle(@@ -73,7 +83,7 @@ export function createAttributeMultiChangeHandler(setSelectedAttributes(newSelectedAttributes);triggerChange();- changeAttributeData(id, attributeValues.map(({ value }) => value));+ changeAttributeData(attributeId, attributeValues.map(({ value }) => value));};}diff --git a/saleor/static/dashboard-next/products/views/ProductUpdate.tsx b/saleor/static/dashboard-next/products/views/ProductUpdate.tsxindex ae6661d533..3874002b43 100644--- a/saleor/static/dashboard-next/products/views/ProductUpdate.tsx+++ b/saleor/static/dashboard-next/products/views/ProductUpdate.tsx@@ -17,7 +17,6 @@ import i18n from "../../i18n";import { decimal, getMutationState, maybe } from "../../misc";import { productTypeUrl } from "../../productTypes/urls";import ProductUpdatePage, {- FormData,ProductUpdatePageSubmitData} from "../components/ProductUpdatePage";import ProductUpdateOperations from "../containers/ProductUpdateOperations";