diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 28fa0cbe8..af5f372c5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -70,6 +70,7 @@ jobs: npm run test cypress-run: + if: github.event.pull_request.head.repo.full_name == 'mirumee/saleor-dashboard' runs-on: ubuntu-16.04 steps: - name: Checkout diff --git a/CHANGELOG.md b/CHANGELOG.md index c33a975df..d879366d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ All notable, unreleased changes to this project will be documented in this file. - Add OAuth2 login with OpenID support - #963 by @orzechdev - Fix no channels crash - #984 by @dominik-zeglen - Update webhooks - #982 by @piotrgrundas +- Fix trigger form change when collections are being added to list of product collections - #987 by @gax97 # 2.11.1 diff --git a/Dockerfile.dev b/Dockerfile.dev index 9ac570133..eae810bc0 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -8,8 +8,8 @@ ARG APP_MOUNT_URI ARG API_URI ARG STATIC_URL ENV API_URI ${API_URI:-http://localhost:8000/graphql/} -ENV APP_MOUNT_URI ${APP_MOUNT_URI:-/dashboard/} -ENV STATIC_URL ${STATIC_URL:-/dashboard/} +ENV APP_MOUNT_URI ${APP_MOUNT_URI:-/} +ENV STATIC_URL ${STATIC_URL:-/} EXPOSE 9000 CMD npm start -- --host 0.0.0.0 diff --git a/cypress/apiRequests/storeFront/ProductDetails.js b/cypress/apiRequests/storeFront/ProductDetails.js index 9ad18c5fc..e3bb9d7a1 100644 --- a/cypress/apiRequests/storeFront/ProductDetails.js +++ b/cypress/apiRequests/storeFront/ProductDetails.js @@ -12,7 +12,7 @@ class ProductDetails { availableForPurchase } }`; - return cy.sendFrontShopRequestWithQuery(query); + return cy.sendRequestWithQuery(query, "token"); } } export default ProductDetails; diff --git a/cypress/apiRequests/storeFront/Search.js b/cypress/apiRequests/storeFront/Search.js index 107be2560..776ba2860 100644 --- a/cypress/apiRequests/storeFront/Search.js +++ b/cypress/apiRequests/storeFront/Search.js @@ -14,7 +14,7 @@ class Search { } }`; - return cy.sendFrontShopRequestWithQuery(query); + return cy.sendRequestWithQuery(query, "token"); } } export default Search; diff --git a/cypress/integration/products/menageProducts/availableForPurchaseProducts.js b/cypress/integration/products/menageProducts/availableForPurchaseProducts.js index 9c4a3c468..39413c295 100644 --- a/cypress/integration/products/menageProducts/availableForPurchaseProducts.js +++ b/cypress/integration/products/menageProducts/availableForPurchaseProducts.js @@ -5,7 +5,7 @@ import { productDetailsUrl } from "../../../url/urlList"; import ChannelsUtils from "../../../utils/channelsUtils"; import ProductsUtils from "../../../utils/productsUtils"; import ShippingUtils from "../../../utils/shippingUtils"; -import StoreFrontProductUtils from "../../../utils/storeFront/storeFrontProductUtils"; +import { isProductAvailableForPurchase } from "../../../utils/storeFront/storeFrontProductUtils"; // describe("Products available in listings", () => { @@ -13,7 +13,6 @@ describe("Products available in listings", () => { const channelsUtils = new ChannelsUtils(); const productsUtils = new ProductsUtils(); const productSteps = new ProductSteps(); - const frontShopProductUtils = new StoreFrontProductUtils(); const startsWith = "Cy-"; const name = `${startsWith}${faker.random.number()}`; let productType; @@ -74,14 +73,14 @@ describe("Products available in listings", () => { productSteps.updateProductIsAvailableForPurchase(productUrl, true); }) .then(() => { - frontShopProductUtils.isProductAvailableForPurchase( + isProductAvailableForPurchase( productsUtils.getCreatedProduct().id, defaultChannel.slug, productName ); }) - .then(isProductVisible => { - expect(isProductVisible).to.be.eq(true); + .then(isVisibleResp => { + expect(isVisibleResp).to.be.eq(true); }); }); it("should update product to not available for purchase", () => { @@ -102,7 +101,7 @@ describe("Products available in listings", () => { productSteps.updateProductIsAvailableForPurchase(productUrl, false); }) .then(() => { - frontShopProductUtils.isProductAvailableForPurchase( + isProductAvailableForPurchase( productsUtils.getCreatedProduct().id, defaultChannel.slug, productName diff --git a/cypress/integration/products/menageProducts/publishedProducts.js b/cypress/integration/products/menageProducts/publishedProducts.js index 48015293f..974f5756d 100644 --- a/cypress/integration/products/menageProducts/publishedProducts.js +++ b/cypress/integration/products/menageProducts/publishedProducts.js @@ -4,14 +4,13 @@ import ProductSteps from "../../../steps/productSteps"; import { productDetailsUrl } from "../../../url/urlList"; import ChannelsUtils from "../../../utils/channelsUtils"; import ProductsUtils from "../../../utils/productsUtils"; -import StoreFrontProductUtils from "../../../utils/storeFront/storeFrontProductUtils"; +import { isProductVisible } from "../../../utils/storeFront/storeFrontProductUtils"; // describe("Published products", () => { const channelsUtils = new ChannelsUtils(); const productsUtils = new ProductsUtils(); const productSteps = new ProductSteps(); - const frontShopProductUtils = new StoreFrontProductUtils(); const startsWith = "Cy-"; const name = `${startsWith}${faker.random.number()}`; @@ -53,11 +52,7 @@ describe("Published products", () => { const product = productsUtils.getCreatedProduct(); const productUrl = productDetailsUrl(product.id); productSteps.updateProductPublish(productUrl, true); - frontShopProductUtils.isProductVisible( - product.id, - defaultChannel.slug, - productName - ); + isProductVisible(product.id, defaultChannel.slug, productName); }) .then(isVisible => { expect(isVisible).to.be.eq(true); @@ -84,22 +79,14 @@ describe("Published products", () => { product = productsUtils.getCreatedProduct(); const productUrl = productDetailsUrl(product.id); productSteps.updateProductPublish(productUrl, false); - frontShopProductUtils.isProductVisible( - product.id, - defaultChannel.slug, - productName - ); + isProductVisible(product.id, defaultChannel.slug, productName); }) .then(isVisible => { expect(isVisible).to.be.eq(false); cy.loginInShop(); }) .then(() => { - frontShopProductUtils.isProductVisible( - product.id, - defaultChannel.slug, - productName - ); + isProductVisible(product.id, defaultChannel.slug, productName); }) .then(isVisible => { expect(isVisible).to.be.eq(true); diff --git a/cypress/integration/products/menageProducts/visibleInListingsProducts.js b/cypress/integration/products/menageProducts/visibleInListingsProducts.js index 19463c5ce..b41dc2df9 100644 --- a/cypress/integration/products/menageProducts/visibleInListingsProducts.js +++ b/cypress/integration/products/menageProducts/visibleInListingsProducts.js @@ -4,14 +4,13 @@ import ProductSteps from "../../../steps/productSteps"; import { productDetailsUrl } from "../../../url/urlList"; import ChannelsUtils from "../../../utils/channelsUtils"; import ProductsUtils from "../../../utils/productsUtils"; -import StoreFrontProductUtils from "../../../utils/storeFront/storeFrontProductUtils"; +import { isProductVisibleInSearchResult } from "../../../utils/storeFront/storeFrontProductUtils"; // describe("Products displayed in listings", () => { const channelsUtils = new ChannelsUtils(); const productsUtils = new ProductsUtils(); const productSteps = new ProductSteps(); - const frontShopProductUtils = new StoreFrontProductUtils(); const startsWith = "Cy-"; const name = `${startsWith}${faker.random.number()}`; @@ -53,10 +52,7 @@ describe("Products displayed in listings", () => { const product = productsUtils.getCreatedProduct(); const productUrl = productDetailsUrl(product.id); productSteps.updateProductVisibleInListings(productUrl); - frontShopProductUtils.isProductVisibleInSearchResult( - productName, - defaultChannel.slug - ); + isProductVisibleInSearchResult(productName, defaultChannel.slug); }) .then(isProductVisible => { expect(isProductVisible).to.be.eq(true); @@ -82,18 +78,15 @@ describe("Products displayed in listings", () => { const product = productsUtils.getCreatedProduct(); const productUrl = productDetailsUrl(product.id); productSteps.updateProductVisibleInListings(productUrl); - frontShopProductUtils - .isProductVisibleInSearchResult(productName, defaultChannel.slug) - .then(isProductVisible => { + isProductVisibleInSearchResult(productName, defaultChannel.slug).then( + isProductVisible => { expect(isProductVisible).to.be.eq(false); - }); + } + ); cy.loginInShop(); }) .then(() => { - frontShopProductUtils.isProductVisibleInSearchResult( - productName, - defaultChannel.slug - ); + isProductVisibleInSearchResult(productName, defaultChannel.slug); }) .then(isProductVisible => { expect(isProductVisible).to.be.eq(true); diff --git a/cypress/support/index.js b/cypress/support/index.js index 2d9dad3db..fbeac6e3a 100644 --- a/cypress/support/index.js +++ b/cypress/support/index.js @@ -39,9 +39,6 @@ Cypress.Commands.add("addAliasToGraphRequest", operationName => { }); }); -Cypress.Commands.add("sendFrontShopRequestWithQuery", query => - cy.sendRequestWithQuery(query, "token") -); Cypress.Commands.add("sendRequestWithQuery", (query, authorization = "auth") => cy.request({ body: { diff --git a/cypress/utils/storeFront/storeFrontProductUtils.js b/cypress/utils/storeFront/storeFrontProductUtils.js index 676075f19..854c3f79a 100644 --- a/cypress/utils/storeFront/storeFrontProductUtils.js +++ b/cypress/utils/storeFront/storeFrontProductUtils.js @@ -1,34 +1,32 @@ import ProductDetails from "../../apiRequests/storeFront/ProductDetails"; import Search from "../../apiRequests/storeFront/Search"; -class StoreFrontProductUtils { - isProductVisible(productId, channelSlug, name) { - const productDetails = new ProductDetails(); - return productDetails - .getProductDetails(productId, channelSlug) - .then(productDetailsResp => { - const product = productDetailsResp.body.data.product; - return product !== null && product.name === name; - }); - } - isProductAvailableForPurchase(productId, channelSlug) { - const productDetails = new ProductDetails(); - return productDetails - .getProductDetails(productId, channelSlug) - .then( - productDetailsResp => - productDetailsResp.body.data.product.isAvailableForPurchase - ); - } - isProductVisibleInSearchResult(productName, channelSlug) { - const search = new Search(); - return search - .searchInShop(productName, channelSlug) - .then( - resp => - resp.body.data.products.totalCount !== 0 && - resp.body.data.products.edges[0].node.name === productName - ); - } -} -export default StoreFrontProductUtils; +export const isProductVisible = (productId, channelSlug, name) => { + const productDetails = new ProductDetails(); + return productDetails + .getProductDetails(productId, channelSlug) + .then(productDetailsResp => { + const product = productDetailsResp.body.data.product; + return product !== null && product.name === name; + }); +}; + +export const isProductAvailableForPurchase = (productId, channelSlug) => { + const productDetails = new ProductDetails(); + return productDetails + .getProductDetails(productId, channelSlug) + .then( + productDetailsResp => + productDetailsResp.body.data.product.isAvailableForPurchase + ); +}; +export const isProductVisibleInSearchResult = (productName, channelSlug) => { + const search = new Search(); + return search + .searchInShop(productName, channelSlug) + .then( + resp => + resp.body.data.products.totalCount !== 0 && + resp.body.data.products.edges[0].node.name === productName + ); +}; diff --git a/locale/defaultMessages.json b/locale/defaultMessages.json index 694aeabbc..c4aa3efa4 100644 --- a/locale/defaultMessages.json +++ b/locale/defaultMessages.json @@ -5603,13 +5603,6 @@ "context": "label", "string": "Shipping rate name" }, - "src_dot_shipping_dot_components_dot_ShippingRateZipCodeRangeRemoveDialog_dot_3640694505": { - "string": "Are you sure you want to remove this postal code rule?" - }, - "src_dot_shipping_dot_components_dot_ShippingRateZipCodeRangeRemoveDialog_dot_76039652": { - "context": "header", - "string": "Remove postal codes from Shipping Rate" - }, "src_dot_shipping_dot_components_dot_ShippingWeightUnitForm_dot_2863708228": { "string": "This unit will be used as default shipping weight" }, @@ -5693,6 +5686,54 @@ "context": "label", "string": "Shipping zone name" }, + "src_dot_shipping_dot_components_dot_ShippingZonePostalCodeRangeDialog_dot_3070993206": { + "context": "range input label", + "string": "Postal codes (end)" + }, + "src_dot_shipping_dot_components_dot_ShippingZonePostalCodeRangeDialog_dot_3099331554": { + "context": "add postal code range, button", + "string": "Add" + }, + "src_dot_shipping_dot_components_dot_ShippingZonePostalCodeRangeDialog_dot_3419096551": { + "context": "range input label", + "string": "Postal codes (start)" + }, + "src_dot_shipping_dot_components_dot_ShippingZonePostalCodeRangeDialog_dot_3668595137": { + "string": "Please provide range of postal codes you want to add to the include/exclude list." + }, + "src_dot_shipping_dot_components_dot_ShippingZonePostalCodeRangeDialog_dot_3849853790": { + "context": "dialog header", + "string": "Add postal codes" + }, + "src_dot_shipping_dot_components_dot_ShippingZonePostalCodes_dot_1301350004": { + "string": "This shipping rate has no postal codes assigned" + }, + "src_dot_shipping_dot_components_dot_ShippingZonePostalCodes_dot_1680649143": { + "context": "action", + "string": "Include postal codes" + }, + "src_dot_shipping_dot_components_dot_ShippingZonePostalCodes_dot_1779803917": { + "string": "Added postal codes will be excluded from using this delivery methods. If none are added all postal codes will be able to use that shipping rate" + }, + "src_dot_shipping_dot_components_dot_ShippingZonePostalCodes_dot_1909179974": { + "context": "button", + "string": "Add postal code range" + }, + "src_dot_shipping_dot_components_dot_ShippingZonePostalCodes_dot_2274108851": { + "context": "number of postal code ranges", + "string": "{number} postal code ranges" + }, + "src_dot_shipping_dot_components_dot_ShippingZonePostalCodes_dot_2965119249": { + "string": "Only added postal codes will be able to use this shipping rate" + }, + "src_dot_shipping_dot_components_dot_ShippingZonePostalCodes_dot_3782353530": { + "context": "postal codes, header", + "string": "Postal codes" + }, + "src_dot_shipping_dot_components_dot_ShippingZonePostalCodes_dot_399764149": { + "context": "action", + "string": "Exclude postal codes" + }, "src_dot_shipping_dot_components_dot_ShippingZoneRatesCreatePage_dot_1161979494": { "context": "page title", "string": "Price Rate Create" @@ -5753,54 +5794,6 @@ "context": "input placeholder", "string": "Select Warehouse" }, - "src_dot_shipping_dot_components_dot_ShippingZoneZipCodeRangeDialog_dot_3070993206": { - "context": "range input label", - "string": "Postal codes (end)" - }, - "src_dot_shipping_dot_components_dot_ShippingZoneZipCodeRangeDialog_dot_3099331554": { - "context": "add postal code range, button", - "string": "Add" - }, - "src_dot_shipping_dot_components_dot_ShippingZoneZipCodeRangeDialog_dot_3419096551": { - "context": "range input label", - "string": "Postal codes (start)" - }, - "src_dot_shipping_dot_components_dot_ShippingZoneZipCodeRangeDialog_dot_3668595137": { - "string": "Please provide range of postal codes you want to add to the include/exclude list." - }, - "src_dot_shipping_dot_components_dot_ShippingZoneZipCodeRangeDialog_dot_3849853790": { - "context": "dialog header", - "string": "Add postal codes" - }, - "src_dot_shipping_dot_components_dot_ShippingZoneZipCodes_dot_1301350004": { - "string": "This shipping rate has no postal codes assigned" - }, - "src_dot_shipping_dot_components_dot_ShippingZoneZipCodes_dot_1680649143": { - "context": "action", - "string": "Include postal codes" - }, - "src_dot_shipping_dot_components_dot_ShippingZoneZipCodes_dot_1779803917": { - "string": "Added postal codes will be excluded from using this delivery methods. If none are added all postal codes will be able to use that shipping rate" - }, - "src_dot_shipping_dot_components_dot_ShippingZoneZipCodes_dot_1909179974": { - "context": "button", - "string": "Add postal code range" - }, - "src_dot_shipping_dot_components_dot_ShippingZoneZipCodes_dot_2274108851": { - "context": "number of postal code ranges", - "string": "{number} postal code ranges" - }, - "src_dot_shipping_dot_components_dot_ShippingZoneZipCodes_dot_2965119249": { - "string": "Only added postal codes will be able to use this shipping rate" - }, - "src_dot_shipping_dot_components_dot_ShippingZoneZipCodes_dot_3782353530": { - "context": "postal codes, header", - "string": "Postal codes" - }, - "src_dot_shipping_dot_components_dot_ShippingZoneZipCodes_dot_399764149": { - "context": "action", - "string": "Exclude postal codes" - }, "src_dot_shipping_dot_components_dot_ShippingZonesListPage_dot_1325966144": { "context": "header", "string": "Shipping" @@ -5860,10 +5853,6 @@ "src_dot_shipping_dot_views_dot_PriceRatesUpdate_dot_3823295269": { "string": "Manage Channel Availability" }, - "src_dot_shipping_dot_views_dot_PriceRatesUpdate_dot_4243341946": { - "context": "postal code range add error text", - "string": "Cannot add specified postal codes range." - }, "src_dot_shipping_dot_views_dot_PriceRatesUpdate_dot_870815507": { "context": "unassign products from shipping method, button", "string": "Unassign" @@ -5886,10 +5875,6 @@ "src_dot_shipping_dot_views_dot_WeightRatesUpdate_dot_3014453080": { "string": "Manage Channels Availability" }, - "src_dot_shipping_dot_views_dot_WeightRatesUpdate_dot_4243341946": { - "context": "postal code range add error text", - "string": "Cannot add specified postal codes range." - }, "src_dot_shipping_dot_views_dot_WeightRatesUpdate_dot_870815507": { "context": "unassign products from shipping method, button", "string": "Unassign" diff --git a/schema.graphql b/schema.graphql index e82c2e794..9eb934068 100644 --- a/schema.graphql +++ b/schema.graphql @@ -671,7 +671,7 @@ type Category implements Node & ObjectWithMetadata { seoDescription: String id: ID! name: String! - description: JSONString! + description: JSONString slug: String! parent: Category level: Int! @@ -746,7 +746,7 @@ type CategoryTranslatableContent implements Node { seoDescription: String id: ID! name: String! - description: JSONString! + description: JSONString descriptionJson: JSONString @deprecated(reason: "Will be removed in Saleor 4.0. Use the `description` field instead.") translation(languageCode: LanguageCodeEnum!): CategoryTranslation category: Category @@ -763,7 +763,7 @@ type CategoryTranslation implements Node { seoDescription: String id: ID! name: String! - description: JSONString! + description: JSONString language: LanguageDisplay! descriptionJson: JSONString @deprecated(reason: "Will be removed in Saleor 4.0. Use the `description` field instead.") } @@ -1050,7 +1050,7 @@ type Collection implements Node & ObjectWithMetadata { seoDescription: String id: ID! name: String! - description: JSONString! + description: JSONString slug: String! privateMetadata: [MetadataItem]! metadata: [MetadataItem]! @@ -1205,7 +1205,7 @@ type CollectionTranslatableContent implements Node { seoDescription: String id: ID! name: String! - description: JSONString! + description: JSONString descriptionJson: JSONString @deprecated(reason: "Will be removed in Saleor 4.0. Use the `description` field instead.") translation(languageCode: LanguageCodeEnum!): CollectionTranslation collection: Collection @@ -1222,7 +1222,7 @@ type CollectionTranslation implements Node { seoDescription: String id: ID! name: String! - description: JSONString! + description: JSONString language: LanguageDisplay! descriptionJson: JSONString @deprecated(reason: "Will be removed in Saleor 4.0. Use the `description` field instead.") } @@ -2607,8 +2607,6 @@ type Mutation { shopAddressUpdate(input: AddressInput): ShopAddressUpdate orderSettingsUpdate(input: OrderSettingsUpdateInput!): OrderSettingsUpdate shippingMethodChannelListingUpdate(id: ID!, input: ShippingMethodChannelListingInput!): ShippingMethodChannelListingUpdate - shippingMethodZipCodeRulesCreate(input: ShippingZipCodeRulesCreateInput!, shippingMethodId: ID!): ShippingZipCodeRulesCreate - shippingMethodZipCodeRulesDelete(id: ID!): ShippingZipCodeRulesDelete shippingPriceCreate(input: ShippingPriceInput!): ShippingPriceCreate shippingPriceDelete(id: ID!): ShippingPriceDelete shippingPriceBulkDelete(ids: [ID]!): ShippingPriceBulkDelete @@ -3307,7 +3305,7 @@ type Page implements Node & ObjectWithMetadata { seoDescription: String id: ID! title: String! - content: JSONString! + content: JSONString publicationDate: Date isPublished: Boolean! slug: String! @@ -3441,7 +3439,7 @@ type PageTranslatableContent implements Node { seoDescription: String id: ID! title: String! - content: JSONString! + content: JSONString contentJson: JSONString @deprecated(reason: "Will be removed in Saleor 4.0. Use the `content` field instead.") translation(languageCode: LanguageCodeEnum!): PageTranslation page: Page @@ -3458,7 +3456,7 @@ type PageTranslation implements Node { seoDescription: String id: ID! title: String! - content: JSONString! + content: JSONString language: LanguageDisplay! contentJson: JSONString @deprecated(reason: "Will be removed in Saleor 4.0. Use the `content` field instead.") } @@ -3824,6 +3822,11 @@ input PluginUpdateInput { scalar PositiveDecimal +enum PostalCodeRuleInclusionTypeEnum { + INCLUDE + EXCLUDE +} + input PriceRangeInput { gte: Float lte: Float @@ -3834,7 +3837,7 @@ type Product implements Node & ObjectWithMetadata { seoTitle: String seoDescription: String name: String! - description: JSONString! + description: JSONString productType: ProductType! slug: String! category: Category @@ -4140,7 +4143,7 @@ type ProductTranslatableContent implements Node { seoTitle: String seoDescription: String name: String! - description: JSONString! + description: JSONString descriptionJson: JSONString @deprecated(reason: "Will be removed in Saleor 4.0. Use the `description` field instead.") translation(languageCode: LanguageCodeEnum!): ProductTranslation product: Product @@ -4157,7 +4160,7 @@ type ProductTranslation implements Node { seoTitle: String seoDescription: String name: String! - description: JSONString! + description: JSONString language: LanguageDisplay! descriptionJson: JSONString @deprecated(reason: "Will be removed in Saleor 4.0. Use the `description` field instead.") } @@ -4746,7 +4749,7 @@ type ShippingMethod implements Node & ObjectWithMetadata { price: Money maximumOrderPrice: Money minimumOrderPrice: Money - zipCodeRules: [ShippingMethodZipCodeRule] + postalCodeRules: [ShippingMethodPostalCodeRule] excludedProducts(before: String, after: String, first: Int, last: Int): ProductCountableConnection } @@ -4776,6 +4779,13 @@ type ShippingMethodChannelListingUpdate { shippingErrors: [ShippingError!]! } +type ShippingMethodPostalCodeRule implements Node { + start: String + end: String + inclusionType: PostalCodeRuleInclusionTypeEnum + id: ID! +} + type ShippingMethodTranslatableContent implements Node { id: ID! name: String! @@ -4794,10 +4804,9 @@ enum ShippingMethodTypeEnum { WEIGHT } -type ShippingMethodZipCodeRule implements Node { - start: String +input ShippingPostalCodeRulesCreateInputRange { + start: String! end: String - id: ID! } type ShippingPriceBulkDelete { @@ -4838,6 +4847,9 @@ input ShippingPriceInput { minimumDeliveryDays: Int type: ShippingMethodTypeEnum shippingZone: ID + addPostalCodeRules: [ShippingPostalCodeRulesCreateInputRange!] + deletePostalCodeRules: [ID!] + inclusionType: PostalCodeRuleInclusionTypeEnum } type ShippingPriceRemoveProductFromExclude { @@ -4859,29 +4871,6 @@ type ShippingPriceUpdate { shippingErrors: [ShippingError!]! } -type ShippingZipCodeRulesCreate { - errors: [Error!]! @deprecated(reason: "Use typed errors with error codes. This field will be removed after 2020-07-31.") - zipCodeRules: [ShippingMethodZipCodeRule] - shippingMethod: ShippingMethod - shippingErrors: [ShippingError!]! -} - -input ShippingZipCodeRulesCreateInput { - zipCodeRules: [ShippingZipCodeRulesCreateInputRange]! -} - -input ShippingZipCodeRulesCreateInputRange { - start: String! - end: String -} - -type ShippingZipCodeRulesDelete { - errors: [Error!]! @deprecated(reason: "Use typed errors with error codes. This field will be removed after 2020-07-31.") - shippingMethod: ShippingMethod - shippingErrors: [ShippingError!]! - shippingMethodZipCodeRule: ShippingMethodZipCodeRule -} - type ShippingZone implements Node & ObjectWithMetadata { id: ID! name: String! diff --git a/src/categories/types/CategoryCreate.ts b/src/categories/types/CategoryCreate.ts index 3a9b822b7..b1d7643e8 100644 --- a/src/categories/types/CategoryCreate.ts +++ b/src/categories/types/CategoryCreate.ts @@ -39,7 +39,7 @@ export interface CategoryCreate_categoryCreate_category { backgroundImage: CategoryCreate_categoryCreate_category_backgroundImage | null; name: string; slug: string; - description: any; + description: any | null; seoDescription: string | null; seoTitle: string | null; parent: CategoryCreate_categoryCreate_category_parent | null; diff --git a/src/categories/types/CategoryDetails.ts b/src/categories/types/CategoryDetails.ts index d1c245f13..d4a4306a0 100644 --- a/src/categories/types/CategoryDetails.ts +++ b/src/categories/types/CategoryDetails.ts @@ -165,7 +165,7 @@ export interface CategoryDetails_category { backgroundImage: CategoryDetails_category_backgroundImage | null; name: string; slug: string; - description: any; + description: any | null; seoDescription: string | null; seoTitle: string | null; parent: CategoryDetails_category_parent | null; diff --git a/src/categories/types/CategoryUpdate.ts b/src/categories/types/CategoryUpdate.ts index bfd4ec9c9..f45c6ca68 100644 --- a/src/categories/types/CategoryUpdate.ts +++ b/src/categories/types/CategoryUpdate.ts @@ -39,7 +39,7 @@ export interface CategoryUpdate_categoryUpdate_category { backgroundImage: CategoryUpdate_categoryUpdate_category_backgroundImage | null; name: string; slug: string; - description: any; + description: any | null; seoDescription: string | null; seoTitle: string | null; parent: CategoryUpdate_categoryUpdate_category_parent | null; diff --git a/src/categories/views/CategoryCreate.tsx b/src/categories/views/CategoryCreate.tsx index a0f271eb2..a21e29a87 100644 --- a/src/categories/views/CategoryCreate.tsx +++ b/src/categories/views/CategoryCreate.tsx @@ -1,6 +1,7 @@ import { WindowTitle } from "@saleor/components/WindowTitle"; import useNavigator from "@saleor/hooks/useNavigator"; import useNotifier from "@saleor/hooks/useNotifier"; +import { getParsedDataForJsonStringField } from "@saleor/translations/utils"; import createMetadataCreateHandler from "@saleor/utils/handlers/metadataCreateHandler"; import { useMetadataUpdate, @@ -48,7 +49,7 @@ export const CategoryCreateView: React.FC = ({ const result = await createCategory({ variables: { input: { - description: JSON.stringify(formData.description), + description: getParsedDataForJsonStringField(formData.description), name: formData.name, seo: { description: formData.seoDescription, diff --git a/src/categories/views/CategoryDetails.tsx b/src/categories/views/CategoryDetails.tsx index e97265d89..b6ddb47a2 100644 --- a/src/categories/views/CategoryDetails.tsx +++ b/src/categories/views/CategoryDetails.tsx @@ -13,6 +13,7 @@ import usePaginator, { createPaginationState } from "@saleor/hooks/usePaginator"; import { commonMessages } from "@saleor/intl"; +import { getParsedDataForJsonStringField } from "@saleor/translations/utils"; import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers"; import createMetadataUpdateHandler from "@saleor/utils/handlers/metadataUpdateHandler"; import { mapNodeToChoice } from "@saleor/utils/maps"; @@ -188,7 +189,7 @@ export const CategoryDetails: React.FC = ({ id, input: { backgroundImageAlt: formData.backgroundImageAlt, - description: JSON.stringify(formData.description), + description: getParsedDataForJsonStringField(formData.description), name: formData.name, seo: { description: formData.seoDescription, diff --git a/src/channels/components/ChannelDeleteDialog/ChannelDeleteDialog.stories.tsx b/src/channels/components/ChannelDeleteDialog/ChannelDeleteDialog.stories.tsx index 0c0785f4e..871f077af 100644 --- a/src/channels/components/ChannelDeleteDialog/ChannelDeleteDialog.stories.tsx +++ b/src/channels/components/ChannelDeleteDialog/ChannelDeleteDialog.stories.tsx @@ -10,8 +10,8 @@ import ChannelDeleteDialog, { const props: ChannelDeleteDialogProps = { channelsChoices: mapNodeToChoice(channelsList), - hasOrders: true, confirmButtonState: "default", + hasOrders: true, onBack: () => undefined, onClose: () => undefined, onConfirm: () => undefined, diff --git a/src/channels/components/ChannelDeleteDialog/ChannelDeleteDialog.tsx b/src/channels/components/ChannelDeleteDialog/ChannelDeleteDialog.tsx index c97df56eb..87e9ad9ae 100644 --- a/src/channels/components/ChannelDeleteDialog/ChannelDeleteDialog.tsx +++ b/src/channels/components/ChannelDeleteDialog/ChannelDeleteDialog.tsx @@ -13,16 +13,20 @@ import { defineMessages, useIntl } from "react-intl"; import { useStyles } from "../styles"; const messages = defineMessages({ - needToBeMoved: { - defaultMessage: - "All order information from this channel need to be moved to a different channel. Please select channel orders need to be moved to:.", - description: "delete channel" + deleteChannel: { + defaultMessage: "Delete Channel", + description: "dialog header" }, deletingAllProductData: { defaultMessage: "Deleting channel will delete all product data regarding this channel. Are you sure you want to delete this channel?", description: "delete channel" }, + needToBeMoved: { + defaultMessage: + "All order information from this channel need to be moved to a different channel. Please select channel orders need to be moved to:.", + description: "delete channel" + }, noAvailableChannel: { defaultMessage: "There is no available channel to move order information to. Please create a channel with same currency so that information can be moved to it.", @@ -31,10 +35,6 @@ const messages = defineMessages({ selectChannel: { defaultMessage: "Select Channel", description: "dialog header" - }, - deleteChannel: { - defaultMessage: "Delete Channel", - description: "dialog header" } }); diff --git a/src/channels/fixtures.ts b/src/channels/fixtures.ts index f040c41cf..2a4617f63 100644 --- a/src/channels/fixtures.ts +++ b/src/channels/fixtures.ts @@ -72,8 +72,8 @@ export const channelsList: Channels_channels[] = [ { __typename: "Channel", currencyCode: "euro", - id: "Q2hhbm5lbDo5w0z", hasOrders: false, + id: "Q2hhbm5lbDo5w0z", isActive: true, name: "Channel USD", slug: "channel-usd1" diff --git a/src/collections/types/CollectionDetails.ts b/src/collections/types/CollectionDetails.ts index 3d8dca339..2b31df0ad 100644 --- a/src/collections/types/CollectionDetails.ts +++ b/src/collections/types/CollectionDetails.ts @@ -102,7 +102,7 @@ export interface CollectionDetails_collection { privateMetadata: (CollectionDetails_collection_privateMetadata | null)[]; backgroundImage: CollectionDetails_collection_backgroundImage | null; slug: string; - description: any; + description: any | null; seoDescription: string | null; seoTitle: string | null; products: CollectionDetails_collection_products | null; diff --git a/src/collections/types/CollectionUpdate.ts b/src/collections/types/CollectionUpdate.ts index d0f28cc7f..45218fa1b 100644 --- a/src/collections/types/CollectionUpdate.ts +++ b/src/collections/types/CollectionUpdate.ts @@ -48,7 +48,7 @@ export interface CollectionUpdate_collectionUpdate_collection { privateMetadata: (CollectionUpdate_collectionUpdate_collection_privateMetadata | null)[]; backgroundImage: CollectionUpdate_collectionUpdate_collection_backgroundImage | null; slug: string; - description: any; + description: any | null; seoDescription: string | null; seoTitle: string | null; } diff --git a/src/collections/types/CreateCollection.ts b/src/collections/types/CreateCollection.ts index e660d3a20..208bfbcef 100644 --- a/src/collections/types/CreateCollection.ts +++ b/src/collections/types/CreateCollection.ts @@ -48,7 +48,7 @@ export interface CreateCollection_collectionCreate_collection { privateMetadata: (CreateCollection_collectionCreate_collection_privateMetadata | null)[]; backgroundImage: CreateCollection_collectionCreate_collection_backgroundImage | null; slug: string; - description: any; + description: any | null; seoDescription: string | null; seoTitle: string | null; } diff --git a/src/collections/views/CollectionCreate.tsx b/src/collections/views/CollectionCreate.tsx index 9995af199..df484059b 100644 --- a/src/collections/views/CollectionCreate.tsx +++ b/src/collections/views/CollectionCreate.tsx @@ -7,6 +7,7 @@ import useChannels from "@saleor/hooks/useChannels"; import useNavigator from "@saleor/hooks/useNavigator"; import useNotifier from "@saleor/hooks/useNotifier"; import { commonMessages } from "@saleor/intl"; +import { getParsedDataForJsonStringField } from "@saleor/translations/utils"; import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers"; import createMetadataCreateHandler from "@saleor/utils/handlers/metadataCreateHandler"; import { @@ -102,7 +103,7 @@ export const CollectionCreate: React.FC = ({ input: { backgroundImage: formData.backgroundImage.value, backgroundImageAlt: formData.backgroundImageAlt, - description: JSON.stringify(formData.description), + description: getParsedDataForJsonStringField(formData.description), name: formData.name, seo: { description: formData.seoDescription, diff --git a/src/collections/views/CollectionDetails.tsx b/src/collections/views/CollectionDetails.tsx index 7e661ea52..8c145a16a 100644 --- a/src/collections/views/CollectionDetails.tsx +++ b/src/collections/views/CollectionDetails.tsx @@ -21,6 +21,7 @@ import usePaginator, { } from "@saleor/hooks/usePaginator"; import { commonMessages } from "@saleor/intl"; import useProductSearch from "@saleor/searches/useProductSearch"; +import { getParsedDataForJsonStringField } from "@saleor/translations/utils"; import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers"; import createMetadataUpdateHandler from "@saleor/utils/handlers/metadataUpdateHandler"; import { @@ -198,7 +199,7 @@ export const CollectionDetails: React.FC = ({ const handleUpdate = async (formData: CollectionUpdateData) => { const input: CollectionInput = { backgroundImageAlt: formData.backgroundImageAlt, - description: JSON.stringify(formData.description), + description: getParsedDataForJsonStringField(formData.description), name: formData.name, seo: { description: formData.seoDescription, diff --git a/src/customers/components/CustomerAddress/CustomerAddress.tsx b/src/customers/components/CustomerAddress/CustomerAddress.tsx index 900ccb803..5d0e8dddb 100644 --- a/src/customers/components/CustomerAddress/CustomerAddress.tsx +++ b/src/customers/components/CustomerAddress/CustomerAddress.tsx @@ -26,26 +26,26 @@ const messages = defineMessages({ defaultAddress: { defaultMessage: "Default Address" }, - defaultShippingAddress: { - defaultMessage: "Default Shipping Address" - }, defaultBillingAddress: { defaultMessage: "Default Billing Address" }, - setDefaultShipping: { - defaultMessage: "Set as default shipping address", - description: "button" + defaultShippingAddress: { + defaultMessage: "Default Shipping Address" }, - setDefaultBilling: { - defaultMessage: "Set as default billing address", + deleteAddress: { + defaultMessage: "Delete Address", description: "button" }, editAddress: { defaultMessage: "Edit Address", description: "button" }, - deleteAddress: { - defaultMessage: "Delete Address", + setDefaultBilling: { + defaultMessage: "Set as default billing address", + description: "button" + }, + setDefaultShipping: { + defaultMessage: "Set as default shipping address", description: "button" } }); diff --git a/src/customers/components/CustomerAddressListPage/CustomerAddressListPage.tsx b/src/customers/components/CustomerAddressListPage/CustomerAddressListPage.tsx index 731e3db38..e77239552 100644 --- a/src/customers/components/CustomerAddressListPage/CustomerAddressListPage.tsx +++ b/src/customers/components/CustomerAddressListPage/CustomerAddressListPage.tsx @@ -23,6 +23,14 @@ export interface CustomerAddressListPageProps { } const messages = defineMessages({ + addAddress: { + defaultMessage: "Add address", + description: "button" + }, + doesntHaveAddresses: { + defaultMessage: + "This customer doesn’t have any adresses added to his address book. You can add address using the button below." + }, fullNameAddress: { defaultMessage: "{fullName}'s Address Book", description: "customer's address book, header" @@ -31,16 +39,8 @@ const messages = defineMessages({ defaultMessage: "{fullName} Details", description: "customer details, header" }, - addAddress: { - defaultMessage: "Add address", - description: "button" - }, noAddressToShow: { defaultMessage: "There is no address to show for this customer" - }, - doesntHaveAddresses: { - defaultMessage: - "This customer doesn’t have any adresses added to his address book. You can add address using the button below." } }); diff --git a/src/customers/components/CustomerDetailsPage/CustomerDetailsPage.tsx b/src/customers/components/CustomerDetailsPage/CustomerDetailsPage.tsx index f4a2d8ae3..16836042d 100644 --- a/src/customers/components/CustomerDetailsPage/CustomerDetailsPage.tsx +++ b/src/customers/components/CustomerDetailsPage/CustomerDetailsPage.tsx @@ -64,8 +64,8 @@ const CustomerDetailsPage: React.FC = ({ firstName: customer?.firstName || "", isActive: customer?.isActive || false, lastName: customer?.lastName || "", - note: customer?.note || "", metadata: customer?.metadata.map(mapMetadataItemToInput), + note: customer?.note || "", privateMetadata: customer?.privateMetadata.map(mapMetadataItemToInput) }; diff --git a/src/customers/fixtures.ts b/src/customers/fixtures.ts index 018da8138..19b882ceb 100644 --- a/src/customers/fixtures.ts +++ b/src/customers/fixtures.ts @@ -946,8 +946,6 @@ export const customerList: ListCustomers_customers_edges_node[] = [ ]; export const customer: CustomerDetails_user & CustomerAddresses_user = { __typename: "User", - metadata: [], - privateMetadata: [], addresses: [ { __typename: "Address", @@ -1046,6 +1044,7 @@ export const customer: CustomerDetails_user & CustomerAddresses_user = { } ] }, + metadata: [], note: null, orders: { __typename: "OrderCountableConnection", @@ -1069,5 +1068,6 @@ export const customer: CustomerDetails_user & CustomerAddresses_user = { } } ] - } + }, + privateMetadata: [] }; diff --git a/src/fragments/shipping.ts b/src/fragments/shipping.ts index a77a19bb7..4d483024c 100644 --- a/src/fragments/shipping.ts +++ b/src/fragments/shipping.ts @@ -17,11 +17,12 @@ export const shippingZoneFragment = gql` } `; -export const shippingMethodWithZipCodesFragment = gql` - fragment ShippingMethodWithZipCodesFragment on ShippingMethod { +export const shippingMethodWithPostalCodesFragment = gql` + fragment ShippingMethodWithPostalCodesFragment on ShippingMethod { id - zipCodeRules { + postalCodeRules { id + inclusionType start end } @@ -30,9 +31,9 @@ export const shippingMethodWithZipCodesFragment = gql` export const shippingMethodFragment = gql` ${metadataFragment} ${fragmentMoney} - ${shippingMethodWithZipCodesFragment} + ${shippingMethodWithPostalCodesFragment} fragment ShippingMethodFragment on ShippingMethod { - ...ShippingMethodWithZipCodesFragment + ...ShippingMethodWithPostalCodesFragment ...MetadataFragment minimumOrderWeight { unit diff --git a/src/fragments/types/CategoryDetailsFragment.ts b/src/fragments/types/CategoryDetailsFragment.ts index 1190c711d..6ecb638c3 100644 --- a/src/fragments/types/CategoryDetailsFragment.ts +++ b/src/fragments/types/CategoryDetailsFragment.ts @@ -37,7 +37,7 @@ export interface CategoryDetailsFragment { backgroundImage: CategoryDetailsFragment_backgroundImage | null; name: string; slug: string; - description: any; + description: any | null; seoDescription: string | null; seoTitle: string | null; parent: CategoryDetailsFragment_parent | null; diff --git a/src/fragments/types/CategoryTranslationFragment.ts b/src/fragments/types/CategoryTranslationFragment.ts index ed3f656cd..ed941efb3 100644 --- a/src/fragments/types/CategoryTranslationFragment.ts +++ b/src/fragments/types/CategoryTranslationFragment.ts @@ -14,7 +14,7 @@ export interface CategoryTranslationFragment_translation_language { export interface CategoryTranslationFragment_translation { __typename: "CategoryTranslation"; id: string; - description: any; + description: any | null; language: CategoryTranslationFragment_translation_language; name: string; seoDescription: string | null; @@ -25,7 +25,7 @@ export interface CategoryTranslationFragment_category { __typename: "Category"; id: string; name: string; - description: any; + description: any | null; seoDescription: string | null; seoTitle: string | null; } diff --git a/src/fragments/types/CollectionDetailsFragment.ts b/src/fragments/types/CollectionDetailsFragment.ts index ae823d602..8b170980e 100644 --- a/src/fragments/types/CollectionDetailsFragment.ts +++ b/src/fragments/types/CollectionDetailsFragment.ts @@ -46,7 +46,7 @@ export interface CollectionDetailsFragment { privateMetadata: (CollectionDetailsFragment_privateMetadata | null)[]; backgroundImage: CollectionDetailsFragment_backgroundImage | null; slug: string; - description: any; + description: any | null; seoDescription: string | null; seoTitle: string | null; } diff --git a/src/fragments/types/CollectionTranslationFragment.ts b/src/fragments/types/CollectionTranslationFragment.ts index 0b27b4a6a..0e77f2c0d 100644 --- a/src/fragments/types/CollectionTranslationFragment.ts +++ b/src/fragments/types/CollectionTranslationFragment.ts @@ -10,7 +10,7 @@ export interface CollectionTranslationFragment_collection { __typename: "Collection"; id: string; name: string; - description: any; + description: any | null; seoDescription: string | null; seoTitle: string | null; } @@ -23,7 +23,7 @@ export interface CollectionTranslationFragment_translation_language { export interface CollectionTranslationFragment_translation { __typename: "CollectionTranslation"; id: string; - description: any; + description: any | null; language: CollectionTranslationFragment_translation_language; name: string; seoDescription: string | null; diff --git a/src/fragments/types/PageDetailsFragment.ts b/src/fragments/types/PageDetailsFragment.ts index 8750634ac..1abbe5c7d 100644 --- a/src/fragments/types/PageDetailsFragment.ts +++ b/src/fragments/types/PageDetailsFragment.ts @@ -109,7 +109,7 @@ export interface PageDetailsFragment { pageType: PageDetailsFragment_pageType; metadata: (PageDetailsFragment_metadata | null)[]; privateMetadata: (PageDetailsFragment_privateMetadata | null)[]; - content: any; + content: any | null; seoTitle: string | null; seoDescription: string | null; publicationDate: any | null; diff --git a/src/fragments/types/PageTranslatableFragment.ts b/src/fragments/types/PageTranslatableFragment.ts index 8088d7a2f..59ac73eef 100644 --- a/src/fragments/types/PageTranslatableFragment.ts +++ b/src/fragments/types/PageTranslatableFragment.ts @@ -17,7 +17,7 @@ export interface PageTranslatableFragment_translation_language { export interface PageTranslatableFragment_translation { __typename: "PageTranslation"; id: string; - content: any; + content: any | null; seoDescription: string | null; seoTitle: string | null; title: string; @@ -27,7 +27,7 @@ export interface PageTranslatableFragment_translation { export interface PageTranslatableFragment { __typename: "PageTranslatableContent"; id: string; - content: any; + content: any | null; seoDescription: string | null; seoTitle: string | null; title: string; diff --git a/src/fragments/types/PageTranslationFragment.ts b/src/fragments/types/PageTranslationFragment.ts index a0e87d4da..3c89e43a1 100644 --- a/src/fragments/types/PageTranslationFragment.ts +++ b/src/fragments/types/PageTranslationFragment.ts @@ -11,7 +11,7 @@ import { LanguageCodeEnum } from "./../../types/globalTypes"; export interface PageTranslationFragment_page { __typename: "Page"; id: string; - content: any; + content: any | null; seoDescription: string | null; seoTitle: string | null; title: string; @@ -26,7 +26,7 @@ export interface PageTranslationFragment_translation_language { export interface PageTranslationFragment_translation { __typename: "PageTranslation"; id: string; - content: any; + content: any | null; seoDescription: string | null; seoTitle: string | null; title: string; diff --git a/src/fragments/types/Product.ts b/src/fragments/types/Product.ts index 8792e55a4..6d2912612 100644 --- a/src/fragments/types/Product.ts +++ b/src/fragments/types/Product.ts @@ -253,7 +253,7 @@ export interface Product { privateMetadata: (Product_privateMetadata | null)[]; name: string; slug: string; - description: any; + description: any | null; seoTitle: string | null; seoDescription: string | null; rating: number | null; diff --git a/src/fragments/types/ProductTranslationFragment.ts b/src/fragments/types/ProductTranslationFragment.ts index 6bd9548fd..4280e43ec 100644 --- a/src/fragments/types/ProductTranslationFragment.ts +++ b/src/fragments/types/ProductTranslationFragment.ts @@ -12,7 +12,7 @@ export interface ProductTranslationFragment_product { __typename: "Product"; id: string; name: string; - description: any; + description: any | null; seoDescription: string | null; seoTitle: string | null; } @@ -26,7 +26,7 @@ export interface ProductTranslationFragment_translation_language { export interface ProductTranslationFragment_translation { __typename: "ProductTranslation"; id: string; - description: any; + description: any | null; language: ProductTranslationFragment_translation_language; name: string; seoDescription: string | null; diff --git a/src/fragments/types/ShippingMethodFragment.ts b/src/fragments/types/ShippingMethodFragment.ts index 18f00b309..fc1740df5 100644 --- a/src/fragments/types/ShippingMethodFragment.ts +++ b/src/fragments/types/ShippingMethodFragment.ts @@ -2,15 +2,16 @@ /* eslint-disable */ // This file was automatically generated and should not be edited. -import { WeightUnitsEnum, ShippingMethodTypeEnum } from "./../../types/globalTypes"; +import { PostalCodeRuleInclusionTypeEnum, WeightUnitsEnum, ShippingMethodTypeEnum } from "./../../types/globalTypes"; // ==================================================== // GraphQL fragment: ShippingMethodFragment // ==================================================== -export interface ShippingMethodFragment_zipCodeRules { - __typename: "ShippingMethodZipCodeRule"; +export interface ShippingMethodFragment_postalCodeRules { + __typename: "ShippingMethodPostalCodeRule"; id: string; + inclusionType: PostalCodeRuleInclusionTypeEnum | null; start: string | null; end: string | null; } @@ -76,7 +77,7 @@ export interface ShippingMethodFragment_channelListings { export interface ShippingMethodFragment { __typename: "ShippingMethod"; id: string; - zipCodeRules: (ShippingMethodFragment_zipCodeRules | null)[] | null; + postalCodeRules: (ShippingMethodFragment_postalCodeRules | null)[] | null; metadata: (ShippingMethodFragment_metadata | null)[]; privateMetadata: (ShippingMethodFragment_privateMetadata | null)[]; minimumOrderWeight: ShippingMethodFragment_minimumOrderWeight | null; diff --git a/src/fragments/types/ShippingMethodWithExcludedProductsFragment.ts b/src/fragments/types/ShippingMethodWithExcludedProductsFragment.ts index c980fec94..c011e4aa0 100644 --- a/src/fragments/types/ShippingMethodWithExcludedProductsFragment.ts +++ b/src/fragments/types/ShippingMethodWithExcludedProductsFragment.ts @@ -2,15 +2,16 @@ /* eslint-disable */ // This file was automatically generated and should not be edited. -import { WeightUnitsEnum, ShippingMethodTypeEnum } from "./../../types/globalTypes"; +import { PostalCodeRuleInclusionTypeEnum, WeightUnitsEnum, ShippingMethodTypeEnum } from "./../../types/globalTypes"; // ==================================================== // GraphQL fragment: ShippingMethodWithExcludedProductsFragment // ==================================================== -export interface ShippingMethodWithExcludedProductsFragment_zipCodeRules { - __typename: "ShippingMethodZipCodeRule"; +export interface ShippingMethodWithExcludedProductsFragment_postalCodeRules { + __typename: "ShippingMethodPostalCodeRule"; id: string; + inclusionType: PostalCodeRuleInclusionTypeEnum | null; start: string | null; end: string | null; } @@ -107,7 +108,7 @@ export interface ShippingMethodWithExcludedProductsFragment_excludedProducts { export interface ShippingMethodWithExcludedProductsFragment { __typename: "ShippingMethod"; id: string; - zipCodeRules: (ShippingMethodWithExcludedProductsFragment_zipCodeRules | null)[] | null; + postalCodeRules: (ShippingMethodWithExcludedProductsFragment_postalCodeRules | null)[] | null; metadata: (ShippingMethodWithExcludedProductsFragment_metadata | null)[]; privateMetadata: (ShippingMethodWithExcludedProductsFragment_privateMetadata | null)[]; minimumOrderWeight: ShippingMethodWithExcludedProductsFragment_minimumOrderWeight | null; diff --git a/src/fragments/types/ShippingMethodWithPostalCodesFragment.ts b/src/fragments/types/ShippingMethodWithPostalCodesFragment.ts new file mode 100644 index 000000000..26f79fa6c --- /dev/null +++ b/src/fragments/types/ShippingMethodWithPostalCodesFragment.ts @@ -0,0 +1,23 @@ +/* tslint:disable */ +/* eslint-disable */ +// This file was automatically generated and should not be edited. + +import { PostalCodeRuleInclusionTypeEnum } from "./../../types/globalTypes"; + +// ==================================================== +// GraphQL fragment: ShippingMethodWithPostalCodesFragment +// ==================================================== + +export interface ShippingMethodWithPostalCodesFragment_postalCodeRules { + __typename: "ShippingMethodPostalCodeRule"; + id: string; + inclusionType: PostalCodeRuleInclusionTypeEnum | null; + start: string | null; + end: string | null; +} + +export interface ShippingMethodWithPostalCodesFragment { + __typename: "ShippingMethod"; + id: string; + postalCodeRules: (ShippingMethodWithPostalCodesFragment_postalCodeRules | null)[] | null; +} diff --git a/src/fragments/types/ShippingMethodWithZipCodesFragment.ts b/src/fragments/types/ShippingMethodWithZipCodesFragment.ts index 52a7d6567..87fab4dcf 100644 --- a/src/fragments/types/ShippingMethodWithZipCodesFragment.ts +++ b/src/fragments/types/ShippingMethodWithZipCodesFragment.ts @@ -2,13 +2,16 @@ /* eslint-disable */ // This file was automatically generated and should not be edited. +import { PostalCodeRuleInclusionTypeEnum } from "./../../types/globalTypes"; + // ==================================================== // GraphQL fragment: ShippingMethodWithZipCodesFragment // ==================================================== -export interface ShippingMethodWithZipCodesFragment_zipCodeRules { - __typename: "ShippingMethodZipCodeRule"; +export interface ShippingMethodWithZipCodesFragment_postalCodeRules { + __typename: "ShippingMethodPostalCodeRule"; id: string; + inclusionType: PostalCodeRuleInclusionTypeEnum | null; start: string | null; end: string | null; } @@ -16,5 +19,5 @@ export interface ShippingMethodWithZipCodesFragment_zipCodeRules { export interface ShippingMethodWithZipCodesFragment { __typename: "ShippingMethod"; id: string; - zipCodeRules: (ShippingMethodWithZipCodesFragment_zipCodeRules | null)[] | null; + postalCodeRules: (ShippingMethodWithZipCodesFragment_postalCodeRules | null)[] | null; } diff --git a/src/fragments/types/ShippingZoneDetailsFragment.ts b/src/fragments/types/ShippingZoneDetailsFragment.ts index 1600675ae..9e1aea63c 100644 --- a/src/fragments/types/ShippingZoneDetailsFragment.ts +++ b/src/fragments/types/ShippingZoneDetailsFragment.ts @@ -2,7 +2,7 @@ /* eslint-disable */ // This file was automatically generated and should not be edited. -import { WeightUnitsEnum, ShippingMethodTypeEnum } from "./../../types/globalTypes"; +import { PostalCodeRuleInclusionTypeEnum, WeightUnitsEnum, ShippingMethodTypeEnum } from "./../../types/globalTypes"; // ==================================================== // GraphQL fragment: ShippingZoneDetailsFragment @@ -26,9 +26,10 @@ export interface ShippingZoneDetailsFragment_countries { country: string; } -export interface ShippingZoneDetailsFragment_shippingMethods_zipCodeRules { - __typename: "ShippingMethodZipCodeRule"; +export interface ShippingZoneDetailsFragment_shippingMethods_postalCodeRules { + __typename: "ShippingMethodPostalCodeRule"; id: string; + inclusionType: PostalCodeRuleInclusionTypeEnum | null; start: string | null; end: string | null; } @@ -94,7 +95,7 @@ export interface ShippingZoneDetailsFragment_shippingMethods_channelListings { export interface ShippingZoneDetailsFragment_shippingMethods { __typename: "ShippingMethod"; id: string; - zipCodeRules: (ShippingZoneDetailsFragment_shippingMethods_zipCodeRules | null)[] | null; + postalCodeRules: (ShippingZoneDetailsFragment_shippingMethods_postalCodeRules | null)[] | null; metadata: (ShippingZoneDetailsFragment_shippingMethods_metadata | null)[]; privateMetadata: (ShippingZoneDetailsFragment_shippingMethods_privateMetadata | null)[]; minimumOrderWeight: ShippingZoneDetailsFragment_shippingMethods_minimumOrderWeight | null; diff --git a/src/index.tsx b/src/index.tsx index eb9a26f03..13edb0f0a 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -167,8 +167,8 @@ const Routes: React.FC = () => { dispatchAppState({ payload: { - errorId, - error: "unhandled" + error: "unhandled", + errorId }, type: "displayError" }); diff --git a/src/pages/components/PageDetailsPage/form.tsx b/src/pages/components/PageDetailsPage/form.tsx index e1c21856f..cfbe1c0fa 100644 --- a/src/pages/components/PageDetailsPage/form.tsx +++ b/src/pages/components/PageDetailsPage/form.tsx @@ -122,7 +122,7 @@ function usePageForm( title: page?.title || "" }); const [content, changeContent] = useRichText({ - initial: pageExists ? page?.content : null, + initial: page?.content, triggerChange }); diff --git a/src/pages/types/PageCreate.ts b/src/pages/types/PageCreate.ts index f91bff45a..ecd908f0d 100644 --- a/src/pages/types/PageCreate.ts +++ b/src/pages/types/PageCreate.ts @@ -117,7 +117,7 @@ export interface PageCreate_pageCreate_page { pageType: PageCreate_pageCreate_page_pageType; metadata: (PageCreate_pageCreate_page_metadata | null)[]; privateMetadata: (PageCreate_pageCreate_page_privateMetadata | null)[]; - content: any; + content: any | null; seoTitle: string | null; seoDescription: string | null; publicationDate: any | null; diff --git a/src/pages/types/PageDetails.ts b/src/pages/types/PageDetails.ts index a596547d6..45bdc00f9 100644 --- a/src/pages/types/PageDetails.ts +++ b/src/pages/types/PageDetails.ts @@ -109,7 +109,7 @@ export interface PageDetails_page { pageType: PageDetails_page_pageType; metadata: (PageDetails_page_metadata | null)[]; privateMetadata: (PageDetails_page_privateMetadata | null)[]; - content: any; + content: any | null; seoTitle: string | null; seoDescription: string | null; publicationDate: any | null; diff --git a/src/pages/types/PageUpdate.ts b/src/pages/types/PageUpdate.ts index a32762485..1b9b567fc 100644 --- a/src/pages/types/PageUpdate.ts +++ b/src/pages/types/PageUpdate.ts @@ -116,7 +116,7 @@ export interface PageUpdate_pageUpdate_page { pageType: PageUpdate_pageUpdate_page_pageType; metadata: (PageUpdate_pageUpdate_page_metadata | null)[]; privateMetadata: (PageUpdate_pageUpdate_page_privateMetadata | null)[]; - content: any; + content: any | null; seoTitle: string | null; seoDescription: string | null; publicationDate: any | null; diff --git a/src/pages/views/PageCreate.tsx b/src/pages/views/PageCreate.tsx index 5289ddc4a..b3b2f6fb6 100644 --- a/src/pages/views/PageCreate.tsx +++ b/src/pages/views/PageCreate.tsx @@ -12,6 +12,7 @@ import useNotifier from "@saleor/hooks/useNotifier"; import usePageSearch from "@saleor/searches/usePageSearch"; import usePageTypeSearch from "@saleor/searches/usePageTypeSearch"; import useProductSearch from "@saleor/searches/useProductSearch"; +import { getParsedDataForJsonStringField } from "@saleor/translations/utils"; import createMetadataCreateHandler from "@saleor/utils/handlers/metadataCreateHandler"; import { useMetadataUpdate, @@ -128,7 +129,7 @@ export const PageCreate: React.FC = ({ params }) => { attributes: formData.attributes, updatedFileAttributes }), - content: JSON.stringify(formData.content), + content: getParsedDataForJsonStringField(formData.content), isPublished: formData.isPublished, pageType: formData.pageType, publicationDate: formData.publicationDate, diff --git a/src/pages/views/PageDetails.tsx b/src/pages/views/PageDetails.tsx index 32d2eb608..db773768f 100644 --- a/src/pages/views/PageDetails.tsx +++ b/src/pages/views/PageDetails.tsx @@ -23,6 +23,7 @@ import useNotifier from "@saleor/hooks/useNotifier"; import { commonMessages } from "@saleor/intl"; import usePageSearch from "@saleor/searches/usePageSearch"; import useProductSearch from "@saleor/searches/useProductSearch"; +import { getParsedDataForJsonStringField } from "@saleor/translations/utils"; import createMetadataUpdateHandler from "@saleor/utils/handlers/metadataUpdateHandler"; import { useMetadataUpdate, @@ -53,7 +54,7 @@ const createPageInput = ( attributes: data.attributes, updatedFileAttributes }), - content: JSON.stringify(data.content), + content: getParsedDataForJsonStringField(data.content), isPublished: data.isPublished, publicationDate: data.publicationDate, seo: { diff --git a/src/products/components/ProductUpdatePage/form.tsx b/src/products/components/ProductUpdatePage/form.tsx index 5aad36e97..8d5793d6e 100644 --- a/src/products/components/ProductUpdatePage/form.tsx +++ b/src/products/components/ProductUpdatePage/form.tsx @@ -220,7 +220,7 @@ function useProductUpdateForm( triggerChange(); }; const handleCollectionSelect = createMultiAutocompleteSelectHandler( - form.toggleValue, + event => form.toggleValue(event, triggerChange), opts.setSelectedCollections, opts.selectedCollections, opts.collections diff --git a/src/products/types/ProductChannelListingUpdate.ts b/src/products/types/ProductChannelListingUpdate.ts index 795e8368c..e06f8dca6 100644 --- a/src/products/types/ProductChannelListingUpdate.ts +++ b/src/products/types/ProductChannelListingUpdate.ts @@ -253,7 +253,7 @@ export interface ProductChannelListingUpdate_productChannelListingUpdate_product privateMetadata: (ProductChannelListingUpdate_productChannelListingUpdate_product_privateMetadata | null)[]; name: string; slug: string; - description: any; + description: any | null; seoTitle: string | null; seoDescription: string | null; rating: number | null; diff --git a/src/products/types/ProductCreate.ts b/src/products/types/ProductCreate.ts index 531a73af0..782132b2a 100644 --- a/src/products/types/ProductCreate.ts +++ b/src/products/types/ProductCreate.ts @@ -260,7 +260,7 @@ export interface ProductCreate_productCreate_product { privateMetadata: (ProductCreate_productCreate_product_privateMetadata | null)[]; name: string; slug: string; - description: any; + description: any | null; seoTitle: string | null; seoDescription: string | null; rating: number | null; diff --git a/src/products/types/ProductDetails.ts b/src/products/types/ProductDetails.ts index 960e25330..d181c34b5 100644 --- a/src/products/types/ProductDetails.ts +++ b/src/products/types/ProductDetails.ts @@ -253,7 +253,7 @@ export interface ProductDetails_product { privateMetadata: (ProductDetails_product_privateMetadata | null)[]; name: string; slug: string; - description: any; + description: any | null; seoTitle: string | null; seoDescription: string | null; rating: number | null; diff --git a/src/products/types/ProductImageCreate.ts b/src/products/types/ProductImageCreate.ts index 13e0a706b..9297b016f 100644 --- a/src/products/types/ProductImageCreate.ts +++ b/src/products/types/ProductImageCreate.ts @@ -259,7 +259,7 @@ export interface ProductImageCreate_productImageCreate_product { privateMetadata: (ProductImageCreate_productImageCreate_product_privateMetadata | null)[]; name: string; slug: string; - description: any; + description: any | null; seoTitle: string | null; seoDescription: string | null; rating: number | null; diff --git a/src/products/types/ProductImageUpdate.ts b/src/products/types/ProductImageUpdate.ts index 2545adbd8..f66a65fc5 100644 --- a/src/products/types/ProductImageUpdate.ts +++ b/src/products/types/ProductImageUpdate.ts @@ -259,7 +259,7 @@ export interface ProductImageUpdate_productImageUpdate_product { privateMetadata: (ProductImageUpdate_productImageUpdate_product_privateMetadata | null)[]; name: string; slug: string; - description: any; + description: any | null; seoTitle: string | null; seoDescription: string | null; rating: number | null; diff --git a/src/products/types/ProductUpdate.ts b/src/products/types/ProductUpdate.ts index b2780eff1..c23225475 100644 --- a/src/products/types/ProductUpdate.ts +++ b/src/products/types/ProductUpdate.ts @@ -260,7 +260,7 @@ export interface ProductUpdate_productUpdate_product { privateMetadata: (ProductUpdate_productUpdate_product_privateMetadata | null)[]; name: string; slug: string; - description: any; + description: any | null; seoTitle: string | null; seoDescription: string | null; rating: number | null; diff --git a/src/products/types/ProductVariantReorder.ts b/src/products/types/ProductVariantReorder.ts index 5070100c3..f84bcd8a0 100644 --- a/src/products/types/ProductVariantReorder.ts +++ b/src/products/types/ProductVariantReorder.ts @@ -259,7 +259,7 @@ export interface ProductVariantReorder_productVariantReorder_product { privateMetadata: (ProductVariantReorder_productVariantReorder_product_privateMetadata | null)[]; name: string; slug: string; - description: any; + description: any | null; seoTitle: string | null; seoDescription: string | null; rating: number | null; diff --git a/src/products/types/ProductVariantSetDefault.ts b/src/products/types/ProductVariantSetDefault.ts index d59a4aaca..227e55526 100644 --- a/src/products/types/ProductVariantSetDefault.ts +++ b/src/products/types/ProductVariantSetDefault.ts @@ -259,7 +259,7 @@ export interface ProductVariantSetDefault_productVariantSetDefault_product { privateMetadata: (ProductVariantSetDefault_productVariantSetDefault_product_privateMetadata | null)[]; name: string; slug: string; - description: any; + description: any | null; seoTitle: string | null; seoDescription: string | null; rating: number | null; diff --git a/src/products/types/SimpleProductUpdate.ts b/src/products/types/SimpleProductUpdate.ts index b4d7a0a70..41c4b19c4 100644 --- a/src/products/types/SimpleProductUpdate.ts +++ b/src/products/types/SimpleProductUpdate.ts @@ -260,7 +260,7 @@ export interface SimpleProductUpdate_productUpdate_product { privateMetadata: (SimpleProductUpdate_productUpdate_product_privateMetadata | null)[]; name: string; slug: string; - description: any; + description: any | null; seoTitle: string | null; seoDescription: string | null; rating: number | null; diff --git a/src/products/views/ProductCreate/handlers.ts b/src/products/views/ProductCreate/handlers.ts index 4cbe4b801..0798775f5 100644 --- a/src/products/views/ProductCreate/handlers.ts +++ b/src/products/views/ProductCreate/handlers.ts @@ -37,6 +37,7 @@ import { } from "@saleor/products/types/VariantCreate"; import { getAvailabilityVariables } from "@saleor/products/utils/handlers"; import { SearchProductTypes_search_edges_node } from "@saleor/searches/types/SearchProductTypes"; +import { getParsedDataForJsonStringField } from "@saleor/translations/utils"; import { MutationFetchResult } from "react-apollo"; const getChannelsVariables = (productId: string, channels: ChannelData[]) => ({ @@ -108,7 +109,7 @@ export function createHandler( category: formData.category, chargeTaxes: formData.chargeTaxes, collections: formData.collections, - description: JSON.stringify(formData.description), + description: getParsedDataForJsonStringField(formData.description), name: formData.name, productType: formData.productType?.id, rating: formData.rating, diff --git a/src/products/views/ProductUpdate/handlers.ts b/src/products/views/ProductUpdate/handlers.ts index 47b36da63..e191a8db2 100644 --- a/src/products/views/ProductUpdate/handlers.ts +++ b/src/products/views/ProductUpdate/handlers.ts @@ -56,6 +56,7 @@ import { } from "@saleor/products/types/VariantCreate"; import { mapFormsetStockToStockInput } from "@saleor/products/utils/data"; import { getAvailabilityVariables } from "@saleor/products/utils/handlers"; +import { getParsedDataForJsonStringField } from "@saleor/translations/utils"; import { ReorderEvent } from "@saleor/types"; import { move } from "@saleor/utils/lists"; import { diff } from "fast-array-diff"; @@ -185,7 +186,7 @@ export function createUpdateHandler( category: data.category, chargeTaxes: data.chargeTaxes, collections: data.collections, - description: JSON.stringify(data.description), + description: getParsedDataForJsonStringField(data.description), name: data.name, rating: data.rating, seo: { diff --git a/src/shipping/components/ShippingRateZipCodeRangeRemoveDialog/ShippingRateZipCodeRangeRemoveDialog.tsx b/src/shipping/components/ShippingRateZipCodeRangeRemoveDialog/ShippingRateZipCodeRangeRemoveDialog.tsx deleted file mode 100644 index f04e41163..000000000 --- a/src/shipping/components/ShippingRateZipCodeRangeRemoveDialog/ShippingRateZipCodeRangeRemoveDialog.tsx +++ /dev/null @@ -1,42 +0,0 @@ -import DialogContentText from "@material-ui/core/DialogContentText"; -import ActionDialog from "@saleor/components/ActionDialog"; -import { ConfirmButtonTransitionState } from "@saleor/components/ConfirmButton"; -import { DialogProps } from "@saleor/types"; -import React from "react"; -import { FormattedMessage, useIntl } from "react-intl"; - -export interface ShippingRateZipCodeRangeRemoveDialogProps extends DialogProps { - confirmButtonState: ConfirmButtonTransitionState; - onConfirm: () => void; -} - -const ShippingRateZipCodeRangeRemoveDialog: React.FC = ({ - confirmButtonState, - open, - onClose, - onConfirm -}) => { - const intl = useIntl(); - - return ( - - - - - - ); -}; - -ShippingRateZipCodeRangeRemoveDialog.displayName = - "ShippingRateZipCodeRangeRemoveDialog"; -export default ShippingRateZipCodeRangeRemoveDialog; diff --git a/src/shipping/components/ShippingRateZipCodeRangeRemoveDialog/index.ts b/src/shipping/components/ShippingRateZipCodeRangeRemoveDialog/index.ts deleted file mode 100644 index 0d9ae9266..000000000 --- a/src/shipping/components/ShippingRateZipCodeRangeRemoveDialog/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./ShippingRateZipCodeRangeRemoveDialog"; -export { default } from "./ShippingRateZipCodeRangeRemoveDialog"; diff --git a/src/shipping/components/ShippingZoneZipCodeRangeDialog/ShippingZoneZipCodeRangeDialog.stories.tsx b/src/shipping/components/ShippingZonePostalCodeRangeDialog/ShippingZonePostalCodeRangeDialog.stories.tsx similarity index 74% rename from src/shipping/components/ShippingZoneZipCodeRangeDialog/ShippingZoneZipCodeRangeDialog.stories.tsx rename to src/shipping/components/ShippingZonePostalCodeRangeDialog/ShippingZonePostalCodeRangeDialog.stories.tsx index 84825d06c..ba9cb7125 100644 --- a/src/shipping/components/ShippingZoneZipCodeRangeDialog/ShippingZoneZipCodeRangeDialog.stories.tsx +++ b/src/shipping/components/ShippingZonePostalCodeRangeDialog/ShippingZonePostalCodeRangeDialog.stories.tsx @@ -2,12 +2,12 @@ import Decorator from "@saleor/storybook/Decorator"; import { storiesOf } from "@storybook/react"; import React from "react"; -import ShippingZoneZipCodeRangeDialog from "./ShippingZoneZipCodeRangeDialog"; +import ShippingZonePostalCodeRangeDialog from "./ShippingZonePostalCodeRangeDialog"; storiesOf("Shipping / Add postal code range", module) .addDecorator(Decorator) .add("default", () => ( - undefined} diff --git a/src/shipping/components/ShippingZoneZipCodeRangeDialog/ShippingZoneZipCodeRangeDialog.tsx b/src/shipping/components/ShippingZonePostalCodeRangeDialog/ShippingZonePostalCodeRangeDialog.tsx similarity index 89% rename from src/shipping/components/ShippingZoneZipCodeRangeDialog/ShippingZoneZipCodeRangeDialog.tsx rename to src/shipping/components/ShippingZonePostalCodeRangeDialog/ShippingZonePostalCodeRangeDialog.tsx index 02a2f498c..4baf45d25 100644 --- a/src/shipping/components/ShippingZoneZipCodeRangeDialog/ShippingZoneZipCodeRangeDialog.tsx +++ b/src/shipping/components/ShippingZonePostalCodeRangeDialog/ShippingZonePostalCodeRangeDialog.tsx @@ -16,7 +16,7 @@ import { DialogProps, MinMax } from "@saleor/types"; import React from "react"; import { FormattedMessage, useIntl } from "react-intl"; -export interface ShippingZoneZipCodeRangeDialogProps extends DialogProps { +export interface ShippingZonePostalCodeRangeDialogProps extends DialogProps { confirmButtonState: ConfirmButtonTransitionState; onSubmit: (range: MinMax) => void; } @@ -28,11 +28,11 @@ const useStyles = makeStyles( } }), { - name: "ShippingZoneZipCodeRangeDialog" + name: "ShippingZonePostalCodeRangeDialog" } ); -const ShippingZoneZipCodeRangeDialog: React.FC = ({ +const ShippingZonePostalCodeRangeDialog: React.FC = ({ confirmButtonState, open, onClose, @@ -105,5 +105,6 @@ const ShippingZoneZipCodeRangeDialog: React.FC; +export interface ShippingZonePostalCodesProps { disabled: boolean; initialExpanded?: boolean; - zipCodes: ShippingMethodFragment_zipCodeRules[] | undefined; - onZipCodeInclusionChange: FormChange; - onZipCodeDelete: (id: string) => void; - onZipCodeRangeAdd: () => void; + initialInclusionType?: PostalCodeRuleInclusionTypeEnum; + postalCodes: ShippingMethodFragment_postalCodeRules[] | undefined; + onPostalCodeInclusionChange: ( + inclusion: PostalCodeRuleInclusionTypeEnum + ) => void; + onPostalCodeDelete: (code: ShippingMethodFragment_postalCodeRules) => void; + onPostalCodeRangeAdd: () => void; } const useStyles = makeStyles( @@ -60,23 +57,45 @@ const useStyles = makeStyles( } }), { - name: "ShippingZoneZipCodes" + name: "ShippingZonePostalCodes" } ); -const ShippingZoneZipCodes: React.FC = ({ - data, +const ShippingZonePostalCodes: React.FC = ({ disabled, - initialExpanded, - zipCodes, - onZipCodeDelete, - onZipCodeInclusionChange, - onZipCodeRangeAdd + initialExpanded = true, + initialInclusionType = PostalCodeRuleInclusionTypeEnum.EXCLUDE, + postalCodes, + onPostalCodeDelete, + onPostalCodeInclusionChange, + onPostalCodeRangeAdd }) => { const [expanded, setExpanded] = React.useState(initialExpanded); + const [inclusionType, setInclusionType] = React.useState(null); const intl = useIntl(); const classes = useStyles({}); + const onInclusionRadioChange = (event: React.ChangeEvent) => { + const value = event.target.value; + setInclusionType(value); + onPostalCodeInclusionChange(value); + }; + + const getPostalCodeRangeLabel = ( + postalCodeRange: ShippingMethodFragment_postalCodeRules + ) => { + if (!postalCodeRange?.start) { + return ; + } + if (postalCodeRange?.end) { + return `${postalCodeRange.start} - ${postalCodeRange.end}`; + } + return postalCodeRange.start; + }; + + const getInlcusionType = () => + inclusionType === null ? initialInclusionType : inclusionType; + return ( = ({ toolbar={ } - onZipCodeAssign={() => openModal("add-range")} - onZipCodeUnassign={id => - openModal("remove-range", { - id - }) - } + onPostalCodeInclusionChange={onPostalCodeInclusionChange} + onPostalCodeAssign={() => openModal("add-range")} + onPostalCodeUnassign={onPostalCodeUnassign} /> - - assignZipCodeRange({ - variables: { - id: rateId, - input: { - zipCodeRules: [ - { - end: data.max || null, - start: data.min - } - ] - } - } - }) - } + onSubmit={code => { + onPostalCodeAssign(code); + setHavePostalCodesChanged(true); + }} open={params.action === "add-range"} /> - - unassignZipCodeRange({ - variables: { - id: params.id - } - }) - } - open={params.action === "remove-range"} - /> ); }; diff --git a/src/shipping/views/WeightRatesCreate/WeightRatesCreate.tsx b/src/shipping/views/WeightRatesCreate/WeightRatesCreate.tsx index da233ae65..eccc1e15d 100644 --- a/src/shipping/views/WeightRatesCreate/WeightRatesCreate.tsx +++ b/src/shipping/views/WeightRatesCreate/WeightRatesCreate.tsx @@ -5,13 +5,11 @@ import { } from "@saleor/channels/utils"; import ChannelsAvailabilityDialog from "@saleor/components/ChannelsAvailabilityDialog"; import { WindowTitle } from "@saleor/components/WindowTitle"; -import { ShippingMethodFragment_zipCodeRules } from "@saleor/fragments/types/ShippingMethodFragment"; import useChannels from "@saleor/hooks/useChannels"; import useNavigator from "@saleor/hooks/useNavigator"; import { sectionNames } from "@saleor/intl"; -import ShippingRateZipCodeRangeRemoveDialog from "@saleor/shipping/components/ShippingRateZipCodeRangeRemoveDialog"; +import ShippingZonePostalCodeRangeDialog from "@saleor/shipping/components/ShippingZonePostalCodeRangeDialog"; import ShippingZoneRatesCreatePage from "@saleor/shipping/components/ShippingZoneRatesCreatePage"; -import ShippingZoneZipCodeRangeDialog from "@saleor/shipping/components/ShippingZoneZipCodeRangeDialog"; import { useShippingRateCreator } from "@saleor/shipping/handlers"; import { ShippingRateCreateUrlDialog, @@ -19,10 +17,13 @@ import { shippingWeightRatesUrl, shippingZoneUrl } from "@saleor/shipping/urls"; +import filterPostalCodes from "@saleor/shipping/views/utils"; import { MinMax } from "@saleor/types"; -import { ShippingMethodTypeEnum } from "@saleor/types/globalTypes"; +import { + PostalCodeRuleInclusionTypeEnum, + ShippingMethodTypeEnum +} from "@saleor/types/globalTypes"; import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers"; -import { remove } from "@saleor/utils/lists"; import React from "react"; import { useIntl } from "react-intl"; @@ -38,9 +39,10 @@ export const WeightRatesCreate: React.FC = ({ const navigate = useNavigator(); const intl = useIntl(); - const [zipCodes, setZipCodes] = React.useState< - ShippingMethodFragment_zipCodeRules[] - >([]); + const [postalCodes, setPostalCodes] = React.useState([]); + const [radioInclusionType, setRadioInclusionType] = React.useState( + PostalCodeRuleInclusionTypeEnum.EXCLUDE + ); const { data: channelsData, loading: channelsLoading } = useChannelsList({}); @@ -70,30 +72,38 @@ export const WeightRatesCreate: React.FC = ({ createShippingRate, errors, status - } = useShippingRateCreator(id, ShippingMethodTypeEnum.WEIGHT, zipCodes); + } = useShippingRateCreator( + id, + ShippingMethodTypeEnum.WEIGHT, + postalCodes, + radioInclusionType + ); const handleBack = () => navigate(shippingZoneUrl(id)); - const handleZipCodeRangeAdd = (data: MinMax) => { - setZipCodes(zipCodes => [ - ...zipCodes, + const handlePostalCodeRangeAdd = (data: MinMax) => { + setPostalCodes(postalCodes => [ + ...postalCodes, { - __typename: "ShippingMethodZipCodeRule", + __typename: "ShippingMethodPostalCodeRule", end: data.max, - id: zipCodes.length.toString(), + id: postalCodes.length.toString(), + inclusionType: postalCodes?.[0]?.inclusionType, start: data.min } ]); closeModal(); }; - const handleZipCodeRangeDelete = (id: string) => { - setZipCodes(zipCodes => - remove( - zipCodes.find(zipCode => zipCode.id === id), - zipCodes, - (a, b) => a.id === b.id - ) - ); + + const onPostalCodeInclusionChange = ( + inclusion: PostalCodeRuleInclusionTypeEnum + ) => { + setRadioInclusionType(inclusion); + setPostalCodes([]); + }; + + const onPostalCodeUnassign = code => { + setPostalCodes(filterPostalCodes(postalCodes, code)); closeModal(); }; @@ -126,29 +136,20 @@ export const WeightRatesCreate: React.FC = ({ onBack={handleBack} errors={errors} channelErrors={channelErrors} - zipCodes={zipCodes} + postalCodes={postalCodes} openChannelsModal={handleChannelsModalOpen} onChannelsChange={setCurrentChannels} - onZipCodeAssign={() => openModal("add-range")} - onZipCodeUnassign={id => - openModal("remove-range", { - id - }) - } + onPostalCodeAssign={() => openModal("add-range")} + onPostalCodeUnassign={onPostalCodeUnassign} + onPostalCodeInclusionChange={onPostalCodeInclusionChange} variant={ShippingMethodTypeEnum.WEIGHT} /> - - handleZipCodeRangeDelete(params.id)} - open={params.action === "remove-range"} - /> ); }; diff --git a/src/shipping/views/WeightRatesUpdate/WeightRatesUpdate.tsx b/src/shipping/views/WeightRatesUpdate/WeightRatesUpdate.tsx index 53193e688..aa7984c31 100644 --- a/src/shipping/views/WeightRatesUpdate/WeightRatesUpdate.tsx +++ b/src/shipping/views/WeightRatesUpdate/WeightRatesUpdate.tsx @@ -20,11 +20,10 @@ import { commonMessages } from "@saleor/intl"; import useProductSearch from "@saleor/searches/useProductSearch"; import DeleteShippingRateDialog from "@saleor/shipping/components/DeleteShippingRateDialog"; import ShippingMethodProductsAddDialog from "@saleor/shipping/components/ShippingMethodProductsAddDialog"; -import ShippingRateZipCodeRangeRemoveDialog from "@saleor/shipping/components/ShippingRateZipCodeRangeRemoveDialog"; +import ShippingZonePostalCodeRangeDialog from "@saleor/shipping/components/ShippingZonePostalCodeRangeDialog"; import ShippingZoneRatesPage, { FormData } from "@saleor/shipping/components/ShippingZoneRatesPage"; -import ShippingZoneZipCodeRangeDialog from "@saleor/shipping/components/ShippingZoneZipCodeRangeDialog"; import UnassignDialog from "@saleor/shipping/components/UnassignDialog"; import { getShippingMethodChannelVariables, @@ -32,8 +31,6 @@ import { } from "@saleor/shipping/handlers"; import { useShippingMethodChannelListingUpdate, - useShippingMethodZipCodeRangeAssign, - useShippingMethodZipCodeRangeUnassign, useShippingPriceExcludeProduct, useShippingPriceRemoveProductsFromExclude, useShippingRateDelete, @@ -46,7 +43,12 @@ import { shippingWeightRatesEditUrl, shippingZoneUrl } from "@saleor/shipping/urls"; -import { ShippingMethodTypeEnum } from "@saleor/types/globalTypes"; +import filterPostalCodes from "@saleor/shipping/views/utils"; +import { MinMax } from "@saleor/types"; +import { + PostalCodeRuleInclusionTypeEnum, + ShippingMethodTypeEnum +} from "@saleor/types/globalTypes"; import createDialogActionHandlers from "@saleor/utils/handlers/dialogActionHandlers"; import createMetadataUpdateHandler from "@saleor/utils/handlers/metadataUpdateHandler"; import { @@ -84,6 +86,51 @@ export const WeightRatesUpdate: React.FC = ({ ShippingRateUrlQueryParams >(navigate, params => shippingWeightRatesEditUrl(id, rateId, params), params); + const [codesToDelete, setCodesToDelete] = React.useState([]); + const [havePostalCodesChanged, setHavePostalCodesChanged] = React.useState( + false + ); + const [originalCodes, setOriginalCodes] = React.useState([]); + const [inclusionType, setInclusionType] = React.useState( + PostalCodeRuleInclusionTypeEnum.EXCLUDE + ); + + const onPostalCodeInclusionChange = ( + inclusion: PostalCodeRuleInclusionTypeEnum + ) => { + setInclusionType(inclusion); + setCodesToDelete( + rate.postalCodeRules + .filter(code => code.id !== undefined) + .map(code => code.id) + ); + setHavePostalCodesChanged(true); + rate.postalCodeRules = []; + }; + + const onPostalCodeAssign = (rule: MinMax) => { + if (!originalCodes.length) { + setOriginalCodes([...rate.postalCodeRules]); + } + if ( + rate.postalCodeRules.filter( + item => item.start === rule.min && item.end === rule.max + ).length > 0 + ) { + closeModal(); + return; + } + const newCode = { + __typename: undefined, + end: rule.max, + id: undefined, + inclusionType, + start: rule.min + }; + rate.postalCodeRules.push(newCode); + closeModal(); + }; + const { loadMore, search: productsSearch, @@ -171,50 +218,21 @@ export const WeightRatesUpdate: React.FC = ({ } }); - const [ - assignZipCodeRange, - assignZipCodeRangeOpts - ] = useShippingMethodZipCodeRangeAssign({ - onCompleted: data => { - if (data.shippingMethodZipCodeRulesCreate.errors.length === 0) { - notify({ - status: "success", - text: intl.formatMessage(commonMessages.savedChanges) - }); - closeModal(); - } else { - notify({ - status: "error", - text: intl.formatMessage({ - defaultMessage: "Cannot add specified postal codes range.", - description: "postal code range add error text" - }) - }); - } - } - }); - const [ - unassignZipCodeRange, - unassignZipCodeRangeOpts - ] = useShippingMethodZipCodeRangeUnassign({ - onCompleted: data => { - if (data.shippingMethodZipCodeRulesDelete.errors.length === 0) { - notify({ - status: "success", - text: intl.formatMessage(commonMessages.savedChanges) - }); - closeModal(); - } - } - }); - const [updateMetadata] = useMetadataUpdate({}); const [updatePrivateMetadata] = usePrivateMetadataUpdate({}); const updateData = async (data: FormData) => { const response = await updateShippingRate({ - variables: getUpdateShippingWeightRateVariables(data, id, rateId) + variables: getUpdateShippingWeightRateVariables( + data, + id, + rateId, + rate.postalCodeRules, + codesToDelete + ) }); + setCodesToDelete([]); + setHavePostalCodesChanged(false); const errors = response.data.shippingPriceUpdate.errors; if (errors.length === 0) { handleSuccess(); @@ -231,6 +249,18 @@ export const WeightRatesUpdate: React.FC = ({ return errors; }; + const onPostalCodeUnassign = code => { + if (code.id !== undefined) { + setCodesToDelete([...codesToDelete, code.id]); + rate.postalCodeRules = rate.postalCodeRules.filter( + rule => rule.id !== code.id + ); + } else { + rate.postalCodeRules = filterPostalCodes(rate.postalCodeRules, code); + } + setHavePostalCodesChanged(true); + }; + const handleSubmit = createMetadataUpdateHandler( rate, updateData, @@ -316,6 +346,7 @@ export const WeightRatesUpdate: React.FC = ({ assignProductOpts?.status === "loading" } hasChannelChanged={shippingChannels?.length !== currentChannels?.length} + havePostalCodesChanged={havePostalCodesChanged} saveButtonBarState={updateShippingRateOpts.status} onDelete={() => openModal("remove")} onSubmit={handleSubmit} @@ -346,45 +377,19 @@ export const WeightRatesUpdate: React.FC = ({ /> } - onZipCodeAssign={() => openModal("add-range")} - onZipCodeUnassign={id => - openModal("remove-range", { - id - }) - } + onPostalCodeInclusionChange={onPostalCodeInclusionChange} + onPostalCodeAssign={() => openModal("add-range")} + onPostalCodeUnassign={onPostalCodeUnassign} /> - - assignZipCodeRange({ - variables: { - id: rateId, - input: { - zipCodeRules: [ - { - end: data.max || null, - start: data.min - } - ] - } - } - }) - } + onSubmit={code => { + onPostalCodeAssign(code); + setHavePostalCodesChanged(true); + }} open={params.action === "add-range"} /> - - unassignZipCodeRange({ - variables: { - id: params.id - } - }) - } - open={params.action === "remove-range"} - /> ); }; diff --git a/src/shipping/views/utils.tsx b/src/shipping/views/utils.tsx new file mode 100644 index 000000000..077c4dcb6 --- /dev/null +++ b/src/shipping/views/utils.tsx @@ -0,0 +1,7 @@ +const filterPostalCodes = (postalCodes, codeToFilterOut) => + postalCodes.filter( + rule => + rule.start !== codeToFilterOut.start && rule.end !== codeToFilterOut.end + ); + +export default filterPostalCodes; diff --git a/src/storybook/__snapshots__/Stories.test.ts.snap b/src/storybook/__snapshots__/Stories.test.ts.snap index f0dac3fd8..5166159e0 100644 --- a/src/storybook/__snapshots__/Stories.test.ts.snap +++ b/src/storybook/__snapshots__/Stories.test.ts.snap @@ -17131,7 +17131,7 @@ exports[`Storyshots Shipping / ShippingZoneRatesCreatePage page create price 1`] > + + + @@ -208915,7 +208951,7 @@ exports[`Storyshots Views / Shipping / Shipping rate loading 1`] = ` >