Skip to content

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

Add VAT rate types fetching

dominik-zeglen563484f54b6f
diff --git a/saleor/static/dashboard-next/gql-types.ts b/saleor/static/dashboard-next/gql-types.ts
index 046de2a8c6..910838316b 100644
--- a/saleor/static/dashboard-next/gql-types.ts
+++ b/saleor/static/dashboard-next/gql-types.ts
@@ -632,6 +632,37 @@ export interface ProductTypeDetailsQuery {
isShippingRequired: boolean,
taxRate: string,
} | null,
+ // Represents a shop resources.
+ shop: {
+ // VAT tax rates for a specific country.
+ taxRate: {
+ // Standard VAT rate in percent.
+ standardRate: number | null,
+ //
+ // Country's VAT rate exceptions for specific types of goods.
+ reducedRates: Array< {
+ // A type of goods.
+ rateType: string,
+ } | null > | null,
+ },
+ } | null,
+};
+
+export interface ProductTypeCreateDataQuery {
+ // Represents a shop resources.
+ shop: {
+ // VAT tax rates for a specific country.
+ taxRate: {
+ // Standard VAT rate in percent.
+ standardRate: number | null,
+ //
+ // Country's VAT rate exceptions for specific types of goods.
+ reducedRates: Array< {
+ // A type of goods.
+ rateType: string,
+ } | null > | null,
+ },
+ } | null,
};
export interface SearchAttributeQueryVariables {
diff --git a/saleor/static/dashboard-next/productTypes/queries.ts b/saleor/static/dashboard-next/productTypes/queries.ts
index 02735691d5..af3aa62f13 100644
--- a/saleor/static/dashboard-next/productTypes/queries.ts
+++ b/saleor/static/dashboard-next/productTypes/queries.ts
@@ -2,6 +2,7 @@ import gql from "graphql-tag";
import { Query, QueryProps } from "react-apollo";
import {
+ ProductTypeCreateDataQuery,
ProductTypeDetailsQuery,
ProductTypeDetailsQueryVariables,
ProductTypeListQuery,
@@ -84,6 +85,30 @@ export const productTypeDetailsQuery = gql`
isShippingRequired
taxRate
}
+ shop {
+ taxRate(countryCode: "PL") {
+ standardRate
+ reducedRates {
+ rateType
+ }
+ }
+ }
+ }
+`;
+
+export const TypedProductTypeCreateDataQuery = Query as React.ComponentType<
+ QueryProps<ProductTypeCreateDataQuery>
+>;
+export const productTypeCreateQuery = gql`
+ query ProductTypeCreateData {
+ shop {
+ taxRate(countryCode: "PL") {
+ standardRate
+ reducedRates {
+ rateType
+ }
+ }
+ }
}
`;
diff --git a/saleor/static/dashboard-next/productTypes/views/ProductTypeCreate.tsx b/saleor/static/dashboard-next/productTypes/views/ProductTypeCreate.tsx
index 40efa24c8c..a00fed4048 100644
--- a/saleor/static/dashboard-next/productTypes/views/ProductTypeCreate.tsx
+++ b/saleor/static/dashboard-next/productTypes/views/ProductTypeCreate.tsx
@@ -13,8 +13,10 @@ import {
productTypeCreateMutation,
TypedProductTypeCreateMutation
} from "../mutations";
-
-const taxRates = ["standard", "electronics", "food", "apparel"]; // FIXME: delet dis
+import {
+ productTypeCreateQuery,
+ TypedProductTypeCreateDataQuery
+} from "../queries";
const formData = {
hasVariants: false,
@@ -30,82 +32,95 @@ export const ProductTypeUpdate: React.StatelessComponent = () => (
{pushMessage => (
<Navigator>
{navigate => (
- <AttributeSearchProvider>
- {(searchAttribute, searchState) => {
- 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
- mutation={productTypeCreateMutation}
- onCompleted={handleCreateSuccess}
- >
- {(
- createProductType,
- { loading: loadingCreate, data: createProductTypeData }
+ <TypedProductTypeCreateDataQuery query={productTypeCreateQuery}>
+ {createData => (
+ <AttributeSearchProvider>
+ {(searchAttribute, searchState) => {
+ const handleCreateSuccess = (
+ updateData: ProductTypeCreateMutation
) => {
- const handleCreate = (formData: ProductTypeForm) =>
- createProductType({
- variables: {
- input: {
- hasVariants: formData.hasVariants,
- isShippingRequired: formData.isShippingRequired,
- name: formData.name,
- productAttributes: formData.productAttributes.map(
- choice => choice.value
- ),
- variantAttributes: formData.variantAttributes.map(
- choice => choice.value
- )
- }
- }
+ if (updateData.productTypeCreate.errors.length === 0) {
+ pushMessage({
+ text: i18n.t("Successfully created product type")
});
- return (
- <ProductTypeDetailsPage
- disabled={loadingCreate}
- 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
- )
- : []
- }
- taxRates={taxRates}
- onAttributeSearch={searchAttribute}
- onBack={() => navigate(productTypeListUrl)}
- onSubmit={handleCreate}
- />
- );
- }}
- </TypedProductTypeCreateMutation>
- );
- }}
- </AttributeSearchProvider>
+ navigate(
+ productTypeDetailsUrl(
+ updateData.productTypeCreate.productType.id
+ )
+ );
+ }
+ };
+ return (
+ <TypedProductTypeCreateMutation
+ mutation={productTypeCreateMutation}
+ onCompleted={handleCreateSuccess}
+ >
+ {(
+ createProductType,
+ { loading: loadingCreate, data: createProductTypeData }
+ ) => {
+ const handleCreate = (formData: ProductTypeForm) =>
+ createProductType({
+ variables: {
+ input: {
+ hasVariants: formData.hasVariants,
+ isShippingRequired: formData.isShippingRequired,
+ name: formData.name,
+ productAttributes: formData.productAttributes.map(
+ choice => choice.value
+ ),
+ variantAttributes: formData.variantAttributes.map(
+ choice => choice.value
+ )
+ }
+ }
+ });
+ return (
+ <ProductTypeDetailsPage
+ disabled={loadingCreate}
+ 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
+ )
+ : []
+ }
+ taxRates={
+ createData.data &&
+ createData.data.shop &&
+ createData.data.shop.taxRate &&
+ createData.data.shop.taxRate.reducedRates
+ ? createData.data.shop.taxRate.reducedRates
+ .map(rate => rate.rateType)
+ .concat(["standard"])
+ : ["standard"]
+ }
+ onAttributeSearch={searchAttribute}
+ onBack={() => navigate(productTypeListUrl)}
+ onSubmit={handleCreate}
+ />
+ );
+ }}
+ </TypedProductTypeCreateMutation>
+ );
+ }}
+ </AttributeSearchProvider>
+ )}
+ </TypedProductTypeCreateDataQuery>
)}
</Navigator>
)}
diff --git a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate.tsx b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate.tsx
index 3a87dee341..5b9b611a40 100644
--- a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate.tsx
+++ b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate.tsx
@@ -19,8 +19,6 @@ import {
TypedProductTypeDetailsQuery
} from "../queries";
-const taxRates = ["standard", "electronics", "food", "apparel"]; // FIXME: delet dis
-
interface ProductTypeUpdateProps {
id: string;
}
@@ -140,7 +138,16 @@ export const ProductTypeUpdate: React.StatelessComponent<
)
: []
}
- taxRates={taxRates}
+ taxRates={
+ data &&
+ data.shop &&
+ data.shop.taxRate &&
+ data.shop.taxRate.reducedRates
+ ? data.shop.taxRate.reducedRates
+ .map(rate => rate.rateType)
+ .concat(["standard"])
+ : ["standard"]
+ }
onAttributeSearch={searchAttribute}
onBack={() => navigate(productTypeListUrl)}
onDelete={handleDelete}