Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Connect components to API
dominik-zeglen2673e288c545
diff --git a/saleor/static/dashboard-next/taxes/components/CountryListPage/CountryListPage.tsx b/saleor/static/dashboard-next/taxes/components/CountryListPage/CountryListPage.tsxindex 0b3248c14d..5523837299 100644--- a/saleor/static/dashboard-next/taxes/components/CountryListPage/CountryListPage.tsx+++ b/saleor/static/dashboard-next/taxes/components/CountryListPage/CountryListPage.tsx@@ -47,9 +47,7 @@ const CountryListPage = withStyles(styles, { name: "CountryListPage" })(onTaxFetch}: CountryListPageProps & WithStyles<typeof styles>) => {const initialForm: FormData = {- // TODO: connect to API- // chargeTaxesOnShipping: maybe(() => shop.chargeTaxesOnShipping),- chargeTaxesOnShipping: false,+ chargeTaxesOnShipping: maybe(() => shop.chargeTaxesOnShipping, false),includeTax: maybe(() => shop.includeTaxesInPrices, false),showGross: maybe(() => shop.displayGrossPrices, false)};diff --git a/saleor/static/dashboard-next/taxes/components/CountryTaxesPage/CountryTaxesPage.tsx b/saleor/static/dashboard-next/taxes/components/CountryTaxesPage/CountryTaxesPage.tsxindex 70504ac8e4..3b3b508ed6 100644--- a/saleor/static/dashboard-next/taxes/components/CountryTaxesPage/CountryTaxesPage.tsx+++ b/saleor/static/dashboard-next/taxes/components/CountryTaxesPage/CountryTaxesPage.tsx@@ -34,13 +34,15 @@ const styles = (theme: Theme) =>export interface CountryTaxesPageProps {countryName: string;taxCategories: CountryList_shop_countries_vat_reducedRates[];+ onBack: () => void;}const CountryTaxesPage = withStyles(styles, { name: "CountryTaxesPage" })(({classes,countryName,- taxCategories+ taxCategories,+ onBack}: CountryTaxesPageProps & WithStyles<typeof styles>) => {const taxRates = translatedTaxRates();return (@@ -54,6 +56,7 @@ const CountryTaxesPage = withStyles(styles, { name: "CountryTaxesPage" })(}): undefined}+ onBack={onBack}/><div className={classes.root}><div>diff --git a/saleor/static/dashboard-next/taxes/index.tsx b/saleor/static/dashboard-next/taxes/index.tsxindex b2c17ca043..8cb67fc24e 100644--- a/saleor/static/dashboard-next/taxes/index.tsx+++ b/saleor/static/dashboard-next/taxes/index.tsx@@ -1,16 +1,28 @@import * as React from "react";-import { Route, Switch } from "react-router-dom";+import { Route, RouteComponentProps, Switch } from "react-router-dom";import { WindowTitle } from "../components/WindowTitle";import i18n from "../i18n";-import { countryListPath } from "./urls";+import { countryListPath, countryTaxRatesPath } from "./urls";import CountryList from "./views/CountryList";+import CountryTaxesComponent, {+ CountryTaxesParams+} from "./views/CountryTaxes";++const CountryTaxes: React.StatelessComponent<+ RouteComponentProps<CountryTaxesParams>+> = ({ match }) => <CountryTaxesComponent code={match.params.code} />;const Component = () => (<><WindowTitle title={i18n.t("Taxes")} /><Switch><Route exact path={countryListPath} component={CountryList} />+ <Route+ exact+ path={countryTaxRatesPath(":code")}+ component={CountryTaxes}+ /></Switch></>);diff --git a/saleor/static/dashboard-next/taxes/mutations.ts b/saleor/static/dashboard-next/taxes/mutations.tsnew file mode 100644index 0000000000..053a5ee09c--- /dev/null+++ b/saleor/static/dashboard-next/taxes/mutations.ts@@ -0,0 +1,46 @@+import gql from "graphql-tag";++import { TypedMutation } from "../mutations";+import { countryFragment, shopTaxesFragment } from "./queries";+import { FetchTaxes } from "./types/FetchTaxes";+import {+ UpdateTaxSettings,+ UpdateTaxSettingsVariables+} from "./types/UpdateTaxSettings";++const updateTaxSettings = gql`+ ${shopTaxesFragment}+ mutation UpdateTaxSettings($input: ShopSettingsInput!) {+ shopSettingsUpdate(input: $input) {+ errors {+ field+ message+ }+ shop {+ ...ShopTaxesFragment+ }+ }+ }+`;+export const TypedUpdateTaxSettings = TypedMutation<+ UpdateTaxSettings,+ UpdateTaxSettingsVariables+>(updateTaxSettings);++const fetchTaxes = gql`+ ${countryFragment}+ mutation FetchTaxes {+ shopFetchTaxRates {+ errors {+ field+ message+ }+ shop {+ countries {+ ...CountryFragment+ }+ }+ }+ }+`;+export const TypedFetchTaxes = TypedMutation<FetchTaxes, {}>(fetchTaxes);diff --git a/saleor/static/dashboard-next/taxes/queries.ts b/saleor/static/dashboard-next/taxes/queries.tsindex 655e7a5ad0..c0e81489e2 100644--- a/saleor/static/dashboard-next/taxes/queries.ts+++ b/saleor/static/dashboard-next/taxes/queries.ts@@ -2,21 +2,35 @@ import gql from "graphql-tag";import { TypedQuery } from "../queries";import { CountryList } from "./types/CountryList";+export const countryFragment = gql`+ fragment CountryFragment on CountryDisplay {+ country+ code+ vat {+ standardRate+ reducedRates {+ rateType+ rate+ }+ }+ }+`;+export const shopTaxesFragment = gql`+ fragment ShopTaxesFragment on Shop {+ chargeTaxesOnShipping+ includeTaxesInPrices+ displayGrossPrices+ }+`;+const countryList = gql`+ ${countryFragment}+ ${shopTaxesFragment}query CountryList {shop {- includeTaxesInPrices- displayGrossPrices+ ...ShopTaxesFragmentcountries {- country- code- vat {- standardRate- reducedRates {- rateType- rate- }- }+ ...CountryFragment}}}diff --git a/saleor/static/dashboard-next/taxes/types/CountryFragment.ts b/saleor/static/dashboard-next/taxes/types/CountryFragment.tsnew file mode 100644index 0000000000..ca07358a99--- /dev/null+++ b/saleor/static/dashboard-next/taxes/types/CountryFragment.ts@@ -0,0 +1,27 @@+/* tslint:disable */+// This file was automatically generated and should not be edited.++import { TaxRateType } from "./../../types/globalTypes";++// ====================================================+// GraphQL fragment: CountryFragment+// ====================================================++export interface CountryFragment_vat_reducedRates {+ __typename: "ReducedRate";+ rateType: TaxRateType;+ rate: number;+}++export interface CountryFragment_vat {+ __typename: "VAT";+ standardRate: number | null;+ reducedRates: (CountryFragment_vat_reducedRates | null)[] | null;+}++export interface CountryFragment {+ __typename: "CountryDisplay";+ country: string;+ code: string;+ vat: CountryFragment_vat | null;+}diff --git a/saleor/static/dashboard-next/taxes/types/CountryList.ts b/saleor/static/dashboard-next/taxes/types/CountryList.tsindex 8b68581cdd..3aa9d19c35 100644--- a/saleor/static/dashboard-next/taxes/types/CountryList.ts+++ b/saleor/static/dashboard-next/taxes/types/CountryList.ts@@ -1,13 +1,15 @@/* tslint:disable */// This file was automatically generated and should not be edited.+import { TaxRateType } from "./../../types/globalTypes";+// ====================================================// GraphQL query operation: CountryList// ====================================================export interface CountryList_shop_countries_vat_reducedRates {__typename: "ReducedRate";- rateType: string;+ rateType: TaxRateType;rate: number;}@@ -26,6 +28,7 @@ export interface CountryList_shop_countries {export interface CountryList_shop {__typename: "Shop";+ chargeTaxesOnShipping: boolean | null;includeTaxesInPrices: boolean | null;displayGrossPrices: boolean | null;countries: (CountryList_shop_countries | null)[];diff --git a/saleor/static/dashboard-next/taxes/types/FetchTaxes.ts b/saleor/static/dashboard-next/taxes/types/FetchTaxes.tsnew file mode 100644index 0000000000..ebb08433d4--- /dev/null+++ b/saleor/static/dashboard-next/taxes/types/FetchTaxes.ts@@ -0,0 +1,48 @@+/* tslint:disable */+// This file was automatically generated and should not be edited.++import { TaxRateType } from "./../../types/globalTypes";++// ====================================================+// GraphQL mutation operation: FetchTaxes+// ====================================================++export interface FetchTaxes_shopFetchTaxRates_errors {+ __typename: "Error";+ field: string | null;+ message: string | null;+}++export interface FetchTaxes_shopFetchTaxRates_shop_countries_vat_reducedRates {+ __typename: "ReducedRate";+ rateType: TaxRateType;+ rate: number;+}++export interface FetchTaxes_shopFetchTaxRates_shop_countries_vat {+ __typename: "VAT";+ standardRate: number | null;+ reducedRates: (FetchTaxes_shopFetchTaxRates_shop_countries_vat_reducedRates | null)[] | null;+}++export interface FetchTaxes_shopFetchTaxRates_shop_countries {+ __typename: "CountryDisplay";+ country: string;+ code: string;+ vat: FetchTaxes_shopFetchTaxRates_shop_countries_vat | null;+}++export interface FetchTaxes_shopFetchTaxRates_shop {+ __typename: "Shop";+ countries: (FetchTaxes_shopFetchTaxRates_shop_countries | null)[];+}++export interface FetchTaxes_shopFetchTaxRates {+ __typename: "ShopFetchTaxRates";+ errors: FetchTaxes_shopFetchTaxRates_errors[] | null;+ shop: FetchTaxes_shopFetchTaxRates_shop | null;+}++export interface FetchTaxes {+ shopFetchTaxRates: FetchTaxes_shopFetchTaxRates | null;+}diff --git a/saleor/static/dashboard-next/taxes/types/ShopTaxesFragment.ts b/saleor/static/dashboard-next/taxes/types/ShopTaxesFragment.tsnew file mode 100644index 0000000000..5864d1b34b--- /dev/null+++ b/saleor/static/dashboard-next/taxes/types/ShopTaxesFragment.ts@@ -0,0 +1,13 @@+/* tslint:disable */+// This file was automatically generated and should not be edited.++// ====================================================+// GraphQL fragment: ShopTaxesFragment+// ====================================================++export interface ShopTaxesFragment {+ __typename: "Shop";+ chargeTaxesOnShipping: boolean | null;+ includeTaxesInPrices: boolean | null;+ displayGrossPrices: boolean | null;+}diff --git a/saleor/static/dashboard-next/taxes/types/UpdateTaxSettings.ts b/saleor/static/dashboard-next/taxes/types/UpdateTaxSettings.tsnew file mode 100644index 0000000000..e6f1ad8ff4--- /dev/null+++ b/saleor/static/dashboard-next/taxes/types/UpdateTaxSettings.ts@@ -0,0 +1,35 @@+/* tslint:disable */+// This file was automatically generated and should not be edited.++import { ShopSettingsInput } from "./../../types/globalTypes";++// ====================================================+// GraphQL mutation operation: UpdateTaxSettings+// ====================================================++export interface UpdateTaxSettings_shopSettingsUpdate_errors {+ __typename: "Error";+ field: string | null;+ message: string | null;+}++export interface UpdateTaxSettings_shopSettingsUpdate_shop {+ __typename: "Shop";+ chargeTaxesOnShipping: boolean | null;+ includeTaxesInPrices: boolean | null;+ displayGrossPrices: boolean | null;+}++export interface UpdateTaxSettings_shopSettingsUpdate {+ __typename: "ShopSettingsUpdate";+ errors: UpdateTaxSettings_shopSettingsUpdate_errors[] | null;+ shop: UpdateTaxSettings_shopSettingsUpdate_shop | null;+}++export interface UpdateTaxSettings {+ shopSettingsUpdate: UpdateTaxSettings_shopSettingsUpdate | null;+}++export interface UpdateTaxSettingsVariables {+ input: ShopSettingsInput;+}diff --git a/saleor/static/dashboard-next/taxes/views/CountryList.tsx b/saleor/static/dashboard-next/taxes/views/CountryList.tsxindex caaf77c33a..32d6b5c6bc 100644--- a/saleor/static/dashboard-next/taxes/views/CountryList.tsx+++ b/saleor/static/dashboard-next/taxes/views/CountryList.tsx@@ -3,26 +3,52 @@ import * as React from "react";import Navigator from "../../components/Navigator";import { maybe } from "../../misc";import CountryListPage from "../components/CountryListPage";+import { TypedFetchTaxes, TypedUpdateTaxSettings } from "../mutations";import { TypedCountryListQuery } from "../queries";import { countryTaxRatesUrl } from "../urls";export const CountryList: React.StatelessComponent = () => (<Navigator>{navigate => (- <TypedCountryListQuery displayLoader={true}>- {({ data, loading }) => (- <CountryListPage- disabled={loading}- onRowClick={code => navigate(countryTaxRatesUrl(code))}- onSubmit={() => undefined}- onTaxFetch={() => undefined}- shop={maybe(() => ({- ...data.shop,- countries: data.shop.countries.filter(country => country.vat)- }))}- />+ <TypedUpdateTaxSettings>+ {(updateTaxSettings, updateTaxSettingsOpts) => (+ <TypedFetchTaxes>+ {(fetchTaxes, fetchTaxesOpts) => (+ <TypedCountryListQuery displayLoader={true}>+ {({ data, loading }) => (+ <CountryListPage+ disabled={+ loading ||+ fetchTaxesOpts.loading ||+ updateTaxSettingsOpts.loading+ }+ onRowClick={code => navigate(countryTaxRatesUrl(code))}+ onSubmit={formData =>+ updateTaxSettings({+ variables: {+ input: {+ chargeTaxesOnShipping:+ formData.chargeTaxesOnShipping,+ displayGrossPrices: formData.showGross,+ includeTaxesInPrices: formData.includeTax+ }+ }+ })+ }+ onTaxFetch={fetchTaxes}+ shop={maybe(() => ({+ ...data.shop,+ countries: data.shop.countries.filter(+ country => country.vat+ )+ }))}+ />+ )}+ </TypedCountryListQuery>+ )}+ </TypedFetchTaxes>)}- </TypedCountryListQuery>+ </TypedUpdateTaxSettings>)}</Navigator>);diff --git a/saleor/static/dashboard-next/taxes/views/CountryTaxes.tsx b/saleor/static/dashboard-next/taxes/views/CountryTaxes.tsxnew file mode 100644index 0000000000..d2bb2a2a4e--- /dev/null+++ b/saleor/static/dashboard-next/taxes/views/CountryTaxes.tsx@@ -0,0 +1,35 @@+import * as React from "react";++import Navigator from "../../components/Navigator";+import { maybe } from "../../misc";+import CountryTaxesPage from "../components/CountryTaxesPage";+import { TypedCountryListQuery } from "../queries";+import { countryListUrl } from "../urls";++export interface CountryTaxesParams {+ code: string;+}++export const CountryTaxes: React.StatelessComponent<CountryTaxesParams> = ({+ code+}) => (+ <Navigator>+ {navigate => (+ <TypedCountryListQuery displayLoader={true}>+ {({ data }) => {+ const country = maybe(() =>+ data.shop.countries.find(country => country.code === code)+ );+ return (+ <CountryTaxesPage+ countryName={maybe(() => country.country)}+ taxCategories={maybe(() => country.vat.reducedRates)}+ onBack={() => navigate(countryListUrl)}+ />+ );+ }}+ </TypedCountryListQuery>+ )}+ </Navigator>+);+export default CountryTaxes;