Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add adress component
Krzysztof Bialoglowicz0e2c37992ff7
diff --git a/saleor/static/dashboard-next/siteSettings/components/SiteSettingsAddress/SiteSettingsAddress.tsx b/saleor/static/dashboard-next/siteSettings/components/SiteSettingsAddress/SiteSettingsAddress.tsxnew file mode 100644index 0000000000..773e5f0f60--- /dev/null+++ b/saleor/static/dashboard-next/siteSettings/components/SiteSettingsAddress/SiteSettingsAddress.tsx@@ -0,0 +1,139 @@+import Card from "@material-ui/core/Card";+import CardContent from "@material-ui/core/CardContent";+import TextField from "@material-ui/core/TextField";+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 { AddressTypeInput } from "../../../customers/types";+import i18n from "../../../i18n";+import { maybe } from "../../../misc";+import { FormErrors } from "../../../types";+import { SiteSettingsPageFormData } from "../SiteSettingsPage";++interface SiteSettingsAddressProps {+ countries?: Array<{+ code: string;+ label: string;+ }>;+ data: SiteSettingsPageFormData;+ errors: FormErrors<keyof AddressTypeInput>;+ disabled: boolean;+ onChange: (event: React.ChangeEvent<any>) => void;+}++const SiteSettingsAddress: React.StatelessComponent<+ SiteSettingsAddressProps+> = ({ countries, data, disabled, errors, onChange }) => (+ <Card>+ <CardTitle+ title={i18n.t("Store information", {+ context: "store configuration"+ })}+ />+ <CardContent>+ <TextField+ disabled={disabled}+ error={!!errors.companyName}+ helperText={errors.companyName}+ label={i18n.t("Company")}+ name={"companyName" as keyof SiteSettingsPageFormData}+ onChange={onChange}+ value={data.companyName}+ fullWidth+ />+ <FormSpacer />+ <TextField+ disabled={disabled}+ error={!!errors.streetAddress1}+ helperText={errors.streetAddress1}+ label={i18n.t("Address line 1")}+ name={"streetAddress1" as keyof SiteSettingsPageFormData}+ onChange={onChange}+ value={data.streetAddress1}+ fullWidth+ />+ <FormSpacer />+ <TextField+ disabled={disabled}+ error={!!errors.streetAddress2}+ helperText={errors.streetAddress2}+ label={i18n.t("Address line 2")}+ name={"streetAddress2" as keyof SiteSettingsPageFormData}+ onChange={onChange}+ value={data.streetAddress2}+ fullWidth+ />+ <FormSpacer />+ <Grid>+ <TextField+ disabled={disabled}+ error={!!errors.city}+ helperText={errors.city}+ label={i18n.t("City")}+ name={"city" as keyof SiteSettingsPageFormData}+ onChange={onChange}+ value={data.city}+ fullWidth+ />+ <TextField+ disabled={disabled}+ error={!!errors.postalCode}+ helperText={errors.postalCode}+ label={i18n.t("ZIP / Postal code")}+ name={"postalCode" as keyof SiteSettingsPageFormData}+ onChange={onChange}+ value={data.postalCode}+ fullWidth+ />+ </Grid>+ <FormSpacer />+ <Grid>+ <SingleAutocompleteSelectField+ disabled={disabled}+ 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 })),+ []+ )}+ InputProps={{+ autoComplete: "off"+ }}+ />+ <TextField+ disabled={disabled}+ error={!!errors.countryArea}+ helperText={errors.countryArea}+ label={i18n.t("Country area")}+ name={"countryArea" as keyof SiteSettingsPageFormData}+ onChange={onChange}+ value={data.countryArea}+ fullWidth+ />+ </Grid>+ <FormSpacer />+ <TextField+ disabled={disabled}+ error={!!errors.phone}+ fullWidth+ helperText={errors.phone}+ label={i18n.t("Phone")}+ name={"phone" as keyof SiteSettingsPageFormData}+ value={data.phone}+ onChange={onChange}+ />+ </CardContent>+ </Card>+);+SiteSettingsAddress.displayName = "SiteSettingsAddress";+export default SiteSettingsAddress;diff --git a/saleor/static/dashboard-next/siteSettings/components/SiteSettingsPage/SiteSettingsPage.tsx b/saleor/static/dashboard-next/siteSettings/components/SiteSettingsPage/SiteSettingsPage.tsxindex 5cfa4c6f31..096bf1fb8b 100644--- a/saleor/static/dashboard-next/siteSettings/components/SiteSettingsPage/SiteSettingsPage.tsx+++ b/saleor/static/dashboard-next/siteSettings/components/SiteSettingsPage/SiteSettingsPage.tsx@@ -12,13 +12,25 @@ import i18n from "../../../i18n";import { maybe } from "../../../misc";import { AuthorizationKeyType } from "../../../types/globalTypes";import { SiteSettings_shop } from "../../types/SiteSettings";+import SiteSettingsAddress from "../SiteSettingsAddress/SiteSettingsAddress";import SiteSettingsDetails from "../SiteSettingsDetails/SiteSettingsDetails";import SiteSettingsKeys from "../SiteSettingsKeys/SiteSettingsKeys";export interface SiteSettingsPageFormData {+ city: string;+ companyName: string;+ country: {+ code: string;+ country: string;+ };+ countryArea: string;description: string;domain: string;name: string;+ phone: string;+ postalCode: string;+ streetAddress1: string;+ streetAddress2: string;}export interface SiteSettingsPageProps {@@ -46,9 +58,20 @@ const SiteSettingsPage: React.StatelessComponent<SiteSettingsPageProps> = ({onSubmit}) => {const initialForm: SiteSettingsPageFormData = {+ city: maybe(() => shop.companyAddress.city, ""),+ companyName: maybe(() => shop.companyAddress.companyName, ""),+ country: maybe(() => shop.companyAddress.country, {+ code: "",+ country: ""+ }),+ countryArea: maybe(() => shop.companyAddress.countryArea, ""),description: maybe(() => shop.description, ""),domain: maybe(() => shop.domain.host, ""),- name: maybe(() => shop.name, "")+ name: maybe(() => shop.name, ""),+ phone: maybe(() => shop.companyAddress.phone, ""),+ postalCode: maybe(() => shop.companyAddress.city, ""),+ streetAddress1: maybe(() => shop.companyAddress.streetAddress1, ""),+ streetAddress2: maybe(() => shop.companyAddress.streetAddress2, "")};return (<Form@@ -73,6 +96,23 @@ const SiteSettingsPage: React.StatelessComponent<SiteSettingsPageProps> = ({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}+ /><Typography variant="h6">{i18n.t("Authentication keys")}</Typography>diff --git a/saleor/static/dashboard-next/siteSettings/mutations.ts b/saleor/static/dashboard-next/siteSettings/mutations.tsindex 31b531d852..048217b7a7 100644--- a/saleor/static/dashboard-next/siteSettings/mutations.ts+++ b/saleor/static/dashboard-next/siteSettings/mutations.ts@@ -1,6 +1,7 @@import gql from "graphql-tag";import { TypedMutation } from "../mutations";+import { fragmentAddress } from "../orders/queries";import { shopFragment } from "./queries";import {AuthorizationKeyAdd,@@ -58,9 +59,11 @@ export const TypedAuthorizationKeyDelete = TypedMutation<const shopSettingsUpdate = gql`${shopFragment}+ ${fragmentAddress}mutation ShopSettingsUpdate($shopDomainInput: SiteDomainInput!$shopSettingsInput: ShopSettingsInput!+ $addressInput: AddressInput!) {shopSettingsUpdate(input: $shopSettingsInput) {errors {@@ -83,6 +86,17 @@ const shopSettingsUpdate = gql`}}}+ shopAddressUpdate(input: $addressInput) {+ errors {+ field+ message+ }+ shop {+ companyAddress {+ ...AddressFragment+ }+ }+ }}`;export const TypedShopSettingsUpdate = TypedMutation<diff --git a/saleor/static/dashboard-next/siteSettings/queries.ts b/saleor/static/dashboard-next/siteSettings/queries.tsindex 07128b8739..b6a57c61ab 100644--- a/saleor/static/dashboard-next/siteSettings/queries.ts+++ b/saleor/static/dashboard-next/siteSettings/queries.ts@@ -1,13 +1,22 @@import gql from "graphql-tag";+import { fragmentAddress } from "../orders/queries";import { TypedQuery } from "../queries";import { SiteSettings } from "./types/SiteSettings";export const shopFragment = gql`+ ${fragmentAddress}fragment ShopFragment on Shop {authorizationKeys {keyname}+ companyAddress {+ ...AddressFragment+ }+ countries {+ code+ country+ }descriptiondomain {hostdiff --git a/saleor/static/dashboard-next/siteSettings/views/index.tsx b/saleor/static/dashboard-next/siteSettings/views/index.tsxindex a1032f38ed..c1041abd1c 100644--- a/saleor/static/dashboard-next/siteSettings/views/index.tsx+++ b/saleor/static/dashboard-next/siteSettings/views/index.tsx@@ -119,6 +119,16 @@ export const SiteSettings: React.StatelessComponent<SiteSettingsProps> = ({) =>updateShopSettings({variables: {+ addressInput: {+ city: data.city,+ companyName: data.companyName,+ country: data.country.code,+ countryArea: data.countryArea,+ phone: data.phone,+ postalCode: data.postalCode,+ streetAddress1: data.streetAddress1,+ streetAddress2: data.streetAddress2+ },shopDomainInput: {domain: data.domain,name: data.name