Skip to content

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

Fix after rebase

dominik-zeglena7085bef3fe5
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeCreatePage/ProductTypeCreatePage.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeCreatePage/ProductTypeCreatePage.tsx
index 43c7172ccc..a202af5e03 100644
--- a/saleor/static/dashboard-next/productTypes/components/ProductTypeCreatePage/ProductTypeCreatePage.tsx
+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeCreatePage/ProductTypeCreatePage.tsx
@@ -8,6 +8,10 @@ import Form from "@saleor/components/Form";
import Grid from "@saleor/components/Grid";
import PageHeader from "@saleor/components/PageHeader";
import SaveButtonBar from "@saleor/components/SaveButtonBar";
+import { ChangeEvent, FormChange } from "@saleor/hooks/useForm";
+import useStateFromProps from "@saleor/hooks/useStateFromProps";
+import { ProductTypeDetails_taxTypes } from "@saleor/productTypes/types/ProductTypeDetails";
+import { UserError } from "@saleor/types";
import i18n from "../../../i18n";
import { WeightUnitsEnum } from "../../../types/globalTypes";
import ProductTypeDetails from "../ProductTypeDetails/ProductTypeDetails";
@@ -15,33 +19,42 @@ import ProductTypeShipping from "../ProductTypeShipping/ProductTypeShipping";
import ProductTypeTaxes from "../ProductTypeTaxes/ProductTypeTaxes";
export interface ProductTypeForm {
- chargeTaxes: boolean;
name: string;
isShippingRequired: boolean;
- taxType: {
- label: string;
- value: string;
- };
+ taxType: string;
weight: number;
}
export interface ProductTypeCreatePageProps {
- errors: Array<{
- field: string;
- message: string;
- }>;
+ errors: UserError[];
defaultWeightUnit: WeightUnitsEnum;
disabled: boolean;
pageTitle: string;
saveButtonBarState: ConfirmButtonTransitionState;
- taxTypes: Array<{
- description: string;
- taxCode: string;
- }>;
+ taxTypes: ProductTypeDetails_taxTypes[];
onBack: () => void;
onSubmit: (data: ProductTypeForm) => void;
}
+const formInitialData: ProductTypeForm = {
+ isShippingRequired: false,
+ name: "",
+ taxType: "",
+ weight: 0
+};
+
+function handleTaxTypeChange(
+ event: ChangeEvent,
+ taxTypes: ProductTypeDetails_taxTypes[],
+ formChange: FormChange,
+ displayChange: (name: string) => void
+) {
+ formChange(event);
+ displayChange(
+ taxTypes.find(taxType => taxType.taxCode === event.target.value).description
+ );
+}
+
const ProductTypeCreatePage: React.StatelessComponent<
ProductTypeCreatePageProps
> = ({
@@ -54,16 +67,8 @@ const ProductTypeCreatePage: React.StatelessComponent<
onBack,
onSubmit
}: ProductTypeCreatePageProps) => {
- const formInitialData: ProductTypeForm = {
- chargeTaxes: true,
- isShippingRequired: false,
- name: "",
- taxType: {
- label: "",
- value: ""
- },
- weight: 0
- };
+ const [taxTypeDisplayName, setTaxTypeDisplayName] = useStateFromProps("");
+
return (
<Form
errors={errors}
@@ -87,7 +92,15 @@ const ProductTypeCreatePage: React.StatelessComponent<
disabled={disabled}
data={data}
taxTypes={taxTypes}
- onChange={change}
+ taxTypeDisplayName={taxTypeDisplayName}
+ onChange={event =>
+ handleTaxTypeChange(
+ event,
+ taxTypes,
+ change,
+ setTaxTypeDisplayName
+ )
+ }
/>
</div>
<div>
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx
index b7c48214f2..9b320c2eb3 100644
--- a/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx
+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx
@@ -9,6 +9,8 @@ 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 { ChangeEvent, FormChange } from "@saleor/hooks/useForm";
+import useStateFromProps from "@saleor/hooks/useStateFromProps";
import i18n from "@saleor/i18n";
import { maybe } from "@saleor/misc";
import { ListActions, UserError } from "@saleor/types";
@@ -31,10 +33,7 @@ export interface ProductTypeForm {
name: string;
hasVariants: boolean;
isShippingRequired: boolean;
- taxType: {
- label: string;
- value: string;
- };
+ taxType: string;
productAttributes: ChoiceType[];
variantAttributes: ChoiceType[];
weight: number;
@@ -58,6 +57,18 @@ export interface ProductTypeDetailsPageProps {
onSubmit: (data: ProductTypeForm) => void;
}
+function handleTaxTypeChange(
+ event: ChangeEvent,
+ taxTypes: ProductTypeDetails_taxTypes[],
+ formChange: FormChange,
+ displayChange: (name: string) => void
+) {
+ formChange(event);
+ displayChange(
+ taxTypes.find(taxType => taxType.taxCode === event.target.value).description
+ );
+}
+
const ProductTypeDetailsPage: React.StatelessComponent<
ProductTypeDetailsPageProps
> = ({
@@ -77,6 +88,9 @@ const ProductTypeDetailsPage: React.StatelessComponent<
onDelete,
onSubmit
}) => {
+ const [taxTypeDisplayName, setTaxTypeDisplayName] = useStateFromProps(
+ maybe(() => productType.taxType.description)
+ );
const formInitialData: ProductTypeForm = {
hasVariants:
maybe(() => productType.hasVariants) !== undefined
@@ -94,16 +108,7 @@ const ProductTypeDetailsPage: React.StatelessComponent<
value: attribute.id
}))
: [],
- taxType:
- maybe(() => productType.taxType) !== undefined
- ? {
- label: productType.taxType.description,
- value: productType.taxType.taxCode
- }
- : {
- label: "",
- value: ""
- },
+ taxType: maybe(() => productType.taxType.taxCode, ""),
variantAttributes:
maybe(() => productType.variantAttributes) !== undefined
? productType.variantAttributes.map(attribute => ({
@@ -134,11 +139,18 @@ const ProductTypeDetailsPage: React.StatelessComponent<
<ProductTypeTaxes
disabled={disabled}
data={data}
- taxTypes={maybe(() => taxTypes, [])}
- onChange={change}
+ taxTypes={taxTypes}
+ taxTypeDisplayName={taxTypeDisplayName}
+ onChange={event =>
+ handleTaxTypeChange(
+ event,
+ taxTypes,
+ change,
+ setTaxTypeDisplayName
+ )
+ }
/>
<CardSpacer />
- <CardSpacer />
<ProductTypeAttributes
attributes={maybe(() => productType.productAttributes)}
disabled={disabled}
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeTaxes/ProductTypeTaxes.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeTaxes/ProductTypeTaxes.tsx
index 8276e36340..a03edfd799 100644
--- a/saleor/static/dashboard-next/productTypes/components/ProductTypeTaxes/ProductTypeTaxes.tsx
+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeTaxes/ProductTypeTaxes.tsx
@@ -5,21 +5,17 @@ import React from "react";
import CardTitle from "@saleor/components/CardTitle";
import SingleAutocompleteSelectField from "@saleor/components/SingleAutocompleteSelectField";
+import { ProductTypeDetails_taxTypes } from "@saleor/productTypes/types/ProductTypeDetails";
import i18n from "../../../i18n";
import { maybe } from "../../../misc";
import { ProductTypeForm } from "../ProductTypeDetailsPage/ProductTypeDetailsPage";
interface ProductTypeTaxesProps extends WithStyles<typeof styles> {
data: {
- taxType: {
- label: string;
- value: string;
- };
+ taxType: string;
};
- taxTypes: Array<{
- description: string;
- taxCode: string;
- }>;
+ taxTypeDisplayName: string;
+ taxTypes: ProductTypeDetails_taxTypes[];
disabled: boolean;
onChange: (event: React.ChangeEvent<any>) => void;
}
@@ -31,19 +27,24 @@ const styles = createStyles({
});
const ProductTypeTaxes = withStyles(styles, { name: "ProductTypeTaxes" })(
- ({ classes, data, disabled, taxTypes, onChange }: ProductTypeTaxesProps) => (
+ ({
+ classes,
+ data,
+ disabled,
+ taxTypes,
+ taxTypeDisplayName,
+ onChange
+ }: ProductTypeTaxesProps) => (
<Card className={classes.root}>
<CardTitle title={i18n.t("Taxes")} />
<CardContent>
<SingleAutocompleteSelectField
disabled={disabled}
+ displayValue={taxTypeDisplayName}
label={i18n.t("Taxes")}
name={"taxType" as keyof ProductTypeForm}
onChange={onChange}
- value={{
- label: data.taxType.label,
- value: data.taxType.value
- }}
+ value={data.taxType}
choices={maybe(
() =>
taxTypes.map(c => ({ label: c.description, value: c.taxCode })),
diff --git a/saleor/static/dashboard-next/productTypes/fixtures.ts b/saleor/static/dashboard-next/productTypes/fixtures.ts
index 92bff0e157..b7999a7f10 100644
--- a/saleor/static/dashboard-next/productTypes/fixtures.ts
+++ b/saleor/static/dashboard-next/productTypes/fixtures.ts
@@ -574,7 +574,20 @@ export const productType: ProductTypeDetails_productType = {
description: "PH405458",
taxCode: "Shields"
},
- variantAttributes: [attributes[1], attributes[6]],
+ variantAttributes: [
+ {
+ ...attributes[1],
+ filterableInDashboard: true,
+ filterableInStorefront: false,
+ visibleInStorefront: true
+ },
+ {
+ ...attributes[6],
+ filterableInDashboard: true,
+ filterableInStorefront: false,
+ visibleInStorefront: true
+ }
+ ],
weight: {
__typename: "Weight",
unit: "kg",
diff --git a/saleor/static/dashboard-next/productTypes/views/ProductTypeCreate.tsx b/saleor/static/dashboard-next/productTypes/views/ProductTypeCreate.tsx
index ec9c02b4c0..2427377f10 100644
--- a/saleor/static/dashboard-next/productTypes/views/ProductTypeCreate.tsx
+++ b/saleor/static/dashboard-next/productTypes/views/ProductTypeCreate.tsx
@@ -39,7 +39,7 @@ export const ProductTypeCreate: React.StatelessComponent = () => {
hasVariants: false,
isShippingRequired: formData.isShippingRequired,
name: formData.name,
- taxCode: formData.taxType.value,
+ taxCode: formData.taxType,
weight: formData.weight
}
}
diff --git a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsx b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsx
index 2839a969dc..e54d8d97d8 100644
--- a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsx
+++ b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsx
@@ -144,7 +144,7 @@ export const ProductTypeUpdate: React.FC<ProductTypeUpdateProps> = ({
productAttributes: formData.productAttributes.map(
choice => choice.value
),
- taxCode: formData.taxType.value,
+ taxCode: formData.taxType,
variantAttributes: formData.variantAttributes.map(
choice => choice.value
),
diff --git a/saleor/static/dashboard-next/siteSettings/components/SiteSettingsAddress/SiteSettingsAddress.tsx b/saleor/static/dashboard-next/siteSettings/components/SiteSettingsAddress/SiteSettingsAddress.tsx
index 8326f2b45a..966078c03d 100644
--- a/saleor/static/dashboard-next/siteSettings/components/SiteSettingsAddress/SiteSettingsAddress.tsx
+++ b/saleor/static/dashboard-next/siteSettings/components/SiteSettingsAddress/SiteSettingsAddress.tsx
@@ -7,22 +7,23 @@ import React from "react";
import CardTitle from "@saleor/components/CardTitle";
import FormSpacer from "@saleor/components/FormSpacer";
import Grid from "@saleor/components/Grid";
-import SingleAutocompleteSelectField from "@saleor/components/SingleAutocompleteSelectField";
+import SingleAutocompleteSelectField, {
+ SingleAutocompleteChoiceType
+} from "@saleor/components/SingleAutocompleteSelectField";
import { AddressTypeInput } from "@saleor/customers/types";
+import { ChangeEvent } from "@saleor/hooks/useForm";
import i18n from "@saleor/i18n";
-import { maybe } from "@saleor/misc";
import { FormErrors } from "@saleor/types";
import { SiteSettingsPageFormData } from "../SiteSettingsPage";
interface SiteSettingsAddressProps extends WithStyles<typeof styles> {
- countries?: Array<{
- code: string;
- label: string;
- }>;
+ countries: SingleAutocompleteChoiceType[];
data: SiteSettingsPageFormData;
+ displayCountry: string;
errors: FormErrors<keyof AddressTypeInput>;
disabled: boolean;
- onChange: (event: React.ChangeEvent<any>) => void;
+ onChange: (event: ChangeEvent) => void;
+ onCountryChange: (event: ChangeEvent) => void;
}
const styles = createStyles({
@@ -37,8 +38,10 @@ const SiteSettingsAddress = withStyles(styles, { name: "SiteSettingsAddress" })(
countries,
data,
disabled,
+ displayCountry,
errors,
- onChange
+ onChange,
+ onCountryChange
}: SiteSettingsAddressProps) => (
<Card className={classes.root}>
<CardTitle
@@ -106,19 +109,14 @@ const SiteSettingsAddress = withStyles(styles, { name: "SiteSettingsAddress" })(
<Grid>
<SingleAutocompleteSelectField
disabled={disabled}
+ displayValue={displayCountry}
error={!!errors.country}
helperText={errors.country}
label={i18n.t("Country")}
name={"country" as keyof SiteSettingsPageFormData}
- onChange={onChange}
- value={{
- label: data.country.country,
- value: data.country.code
- }}
- choices={maybe(
- () => countries.map(c => ({ ...c, value: c.code })),
- []
- )}
+ onChange={onCountryChange}
+ value={data.country}
+ choices={countries}
InputProps={{
autoComplete: "off"
}}
diff --git a/saleor/static/dashboard-next/siteSettings/components/SiteSettingsPage/SiteSettingsPage.tsx b/saleor/static/dashboard-next/siteSettings/components/SiteSettingsPage/SiteSettingsPage.tsx
index ee1d462b67..794b7ac1a2 100644
--- a/saleor/static/dashboard-next/siteSettings/components/SiteSettingsPage/SiteSettingsPage.tsx
+++ b/saleor/static/dashboard-next/siteSettings/components/SiteSettingsPage/SiteSettingsPage.tsx
@@ -8,6 +8,10 @@ import Form from "@saleor/components/Form";
import Grid from "@saleor/components/Grid";
import PageHeader from "@saleor/components/PageHeader";
import SaveButtonBar from "@saleor/components/SaveButtonBar";
+import useStateFromProps from "@saleor/hooks/useStateFromProps";
+import { UserError } from "@saleor/types";
+import createSingleAutocompleteSelectHandler from "@saleor/utils/handlers/singleAutocompleteSelectChangeHandler";
+import { mapCountriesToChoices } from "@saleor/utils/maps";
import i18n from "../../../i18n";
import { maybe } from "../../../misc";
import { AuthorizationKeyType } from "../../../types/globalTypes";
@@ -19,10 +23,7 @@ import SiteSettingsKeys from "../SiteSettingsKeys/SiteSettingsKeys";
export interface SiteSettingsPageAddressFormData {
city: string;
companyName: string;
- country: {
- code: string;
- country: string;
- };
+ country: string;
countryArea: string;
phone: string;
postalCode: string;
@@ -39,10 +40,7 @@ export interface SiteSettingsPageFormData
export interface SiteSettingsPageProps {
disabled: boolean;
- errors: Array<{
- field: string;
- message: string;
- }>;
+ errors: UserError[];
shop: SiteSettings_shop;
saveButtonBarState: ConfirmButtonTransitionState;
onBack: () => void;
@@ -61,13 +59,14 @@ const SiteSettingsPage: React.StatelessComponent<SiteSettingsPageProps> = ({
onKeyRemove,
onSubmit
}) => {
+ const [displayCountry, setDisplayCountry] = useStateFromProps(
+ maybe(() => shop.companyAddress.country.code, "")
+ );
+
const initialForm: SiteSettingsPageFormData = {
city: maybe(() => shop.companyAddress.city, ""),
companyName: maybe(() => shop.companyAddress.companyName, ""),
- country: maybe(() => shop.companyAddress.country, {
- code: "",
- country: ""
- }),
+ country: maybe(() => shop.companyAddress.country.code, ""),
countryArea: maybe(() => shop.companyAddress.countryArea, ""),
description: maybe(() => shop.description, ""),
domain: maybe(() => shop.domain.host, ""),
@@ -77,6 +76,7 @@ const SiteSettingsPage: React.StatelessComponent<SiteSettingsPageProps> = ({
streetAddress1: maybe(() => shop.companyAddress.streetAddress1, ""),
streetAddress2: maybe(() => shop.companyAddress.streetAddress2, "")
};
+
return (
<Form
errors={errors}
@@ -84,57 +84,63 @@ const SiteSettingsPage: React.StatelessComponent<SiteSettingsPageProps> = ({
onSubmit={onSubmit}
confirmLeave
>
- {({ change, data, errors: formErrors, hasChanged, submit }) => (
- <Container>
- <AppHeader onBack={onBack}>{i18n.t("Configuration")}</AppHeader>
- <PageHeader
- title={i18n.t("General Information", {
- context: "page header"
- })}
- />
- <Grid variant="inverted">
- <Typography variant="h6">{i18n.t("Site Settings")}</Typography>
- <SiteSettingsDetails
- data={data}
- errors={formErrors}
- disabled={disabled}
- onChange={change}
- />
- <Typography variant="h6">
- {i18n.t("Company information")}
- </Typography>
- <SiteSettingsAddress
- data={data}
- countries={maybe(
- () =>
- shop.countries.map(country => ({
- code: country.code,
- label: country.country
- })),
- []
- )}
- errors={formErrors}
- disabled={disabled}
- onChange={change}
+ {({ change, data, errors: formErrors, hasChanged, submit }) => {
+ const countryChoices = mapCountriesToChoices(
+ maybe(() => shop.countries, [])
+ );
+ const handleCountryChange = createSingleAutocompleteSelectHandler(
+ change,
+ setDisplayCountry,
+ countryChoices
+ );
+
+ return (
+ <Container>
+ <AppHeader onBack={onBack}>{i18n.t("Configuration")}</AppHeader>
+ <PageHeader
+ title={i18n.t("General Information", {
+ context: "page header"
+ })}
/>
- <Typography variant="h6">
- {i18n.t("Authentication keys")}
- </Typography>
- <SiteSettingsKeys
- disabled={disabled}
- keys={maybe(() => shop.authorizationKeys)}
- onAdd={onKeyAdd}
- onRemove={onKeyRemove}
+ <Grid variant="inverted">
+ <Typography variant="h6">{i18n.t("Site Settings")}</Typography>
+ <SiteSettingsDetails
+ data={data}
+ errors={formErrors}
+ disabled={disabled}
+ onChange={change}
+ />
+ <Typography variant="h6">
+ {i18n.t("Company information")}
+ </Typography>
+ <SiteSettingsAddress
+ data={data}
+ displayCountry={displayCountry}
+ countries={countryChoices}
+ errors={formErrors}
+ disabled={disabled}
+ onChange={change}
+ onCountryChange={handleCountryChange}
+ />
+ <Typography variant="h6">
+ {i18n.t("Authentication keys")}
+ </Typography>
+ <SiteSettingsKeys
+ disabled={disabled}
+ keys={maybe(() => shop.authorizationKeys)}
+ onAdd={onKeyAdd}
+ onRemove={onKeyRemove}
+ />
+ </Grid>
+ <SaveButtonBar
+ state={saveButtonBarState}
+ disabled={disabled || !hasChanged}
+ onCancel={onBack}
+ onSave={submit}
/>
- </Grid>
- <SaveButtonBar
- state={saveButtonBarState}
- disabled={disabled || !hasChanged}
- onCancel={onBack}
- onSave={submit}
- />
- </Container>
- )}
+ </Container>
+ );
+ }}
</Form>
);
};
diff --git a/saleor/static/dashboard-next/siteSettings/views/index.tsx b/saleor/static/dashboard-next/siteSettings/views/index.tsx
index 16cea78ae3..bb593d9074 100644
--- a/saleor/static/dashboard-next/siteSettings/views/index.tsx
+++ b/saleor/static/dashboard-next/siteSettings/views/index.tsx
@@ -129,7 +129,7 @@ export const SiteSettings: React.StatelessComponent<SiteSettingsProps> = ({
addressInput: {
city: data.city,
companyName: data.companyName,
- country: data.country.code,
+ country: data.country,
countryArea: data.countryArea,
phone: data.phone,
postalCode: data.postalCode,
diff --git a/saleor/static/dashboard-next/utils/maps.ts b/saleor/static/dashboard-next/utils/maps.ts
new file mode 100644
index 0000000000..11b76640ef
--- /dev/null
+++ b/saleor/static/dashboard-next/utils/maps.ts
@@ -0,0 +1,12 @@
+import { MultiAutocompleteChoiceType } from "@saleor/components/MultiAutocompleteSelectField";
+import { ShopInfo_shop_countries } from "@saleor/components/Shop/types/ShopInfo";
+import { SingleAutocompleteChoiceType } from "@saleor/components/SingleAutocompleteSelectField";
+
+export function mapCountriesToChoices(
+ countries: ShopInfo_shop_countries[]
+): Array<SingleAutocompleteChoiceType | MultiAutocompleteChoiceType> {
+ return countries.map(country => ({
+ label: country.country,
+ value: country.code
+ }));
+}