saleor-dashboard/src/shipping/mutations.ts
AlicjaSzu b774cc9002
Excluded Products in shipping view (#866)
* Clean up stories

* Add missing props

* Add zip codes section (#861)

* Add zip code listing

* Add list wrapping

* Update snapshots

* Set up API data

* Fix lgtm warning

* Update snapshots

* Run Actions on all PR

* Checks on PR

* Test envs on PR

* Cleanup action on PR

* Update messages

Co-authored-by: Krzysztof Wolski <krzysztof.k.wolski@gmail.com>

* Allow zip codes to be assigned to shipping method

* Add zip code deletion (#871)

* Add zip code range dialog

* Fix path management

* Use query params to handle modal actions

* Allow zip codes to be assigned to shipping method

* Make params optional

* Fix types

* Clean up urls

* Add zip code range delete action

* Update snapshots and messages

* Update schema

* Refresh zip code list after assigning them

* Update types and snapshots

* Update snapshots

* Fix error message, checkbox default value (#880)

* Fix error message, checkbox default value

* Update snapshots

* Update schema and types

* Update stories

* add excluded products section in shipping methods views

* create UnassignDialog component

* use priceRangeFragment in shipping queries

* remove unneeded price from ShippingMethodAddProductsDialog

* update messages in ShippingMethodProducts

* updates after rebase

* update snapshots, fix lint errors

* fix ShippingMethodProductsAddDialog

* update snapshots

* small fix in ShippingMethodProducts

* update snapshots after rebase

* add handleClose func in ShippingMethodProductsAddDialog

* Fix metadata not showing in category update

* update snapshots again

* update ShippingMethodProductsAddDialog

* updates after rebase

* update Price and Weight rates views

Co-authored-by: dominik-zeglen <flesz3@o2.pl>
Co-authored-by: Krzysztof Wolski <krzysztof.k.wolski@gmail.com>
Co-authored-by: Tomasz Szymański <lime129@gmail.com>
Co-authored-by: Magdalena Markusik <magdalena.markusik@mirumee.com>
2020-12-02 12:35:02 +01:00

342 lines
8.8 KiB
TypeScript

import {
shippingChannelsErrorFragment,
shippingErrorFragment
} from "@saleor/fragments/errors";
import {
shippingMethodFragment,
shippingMethodWithZipCodesFragment,
shippingZoneDetailsFragment
} from "@saleor/fragments/shipping";
import { countryFragment } from "@saleor/fragments/taxes";
import makeMutation from "@saleor/hooks/makeMutation";
import gql from "graphql-tag";
import {
BulkDeleteShippingRate,
BulkDeleteShippingRateVariables
} from "./types/BulkDeleteShippingRate";
import {
BulkDeleteShippingZone,
BulkDeleteShippingZoneVariables
} from "./types/BulkDeleteShippingZone";
import {
CreateShippingRate,
CreateShippingRateVariables
} from "./types/CreateShippingRate";
import {
CreateShippingZone,
CreateShippingZoneVariables
} from "./types/CreateShippingZone";
import {
DeleteShippingRate,
DeleteShippingRateVariables
} from "./types/DeleteShippingRate";
import {
DeleteShippingZone,
DeleteShippingZoneVariables
} from "./types/DeleteShippingZone";
import {
ShippingMethodChannelListingUpdate,
ShippingMethodChannelListingUpdateVariables
} from "./types/ShippingMethodChannelListingUpdate";
import {
ShippingMethodZipCodeRangeAssign,
ShippingMethodZipCodeRangeAssignVariables
} from "./types/ShippingMethodZipCodeRangeAssign";
import {
ShippingMethodZipCodeRangeUnassign,
ShippingMethodZipCodeRangeUnassignVariables
} from "./types/ShippingMethodZipCodeRangeUnassign";
import {
ShippingPriceExcludeProduct,
ShippingPriceExcludeProductVariables
} from "./types/ShippingPriceExcludeProduct";
import {
ShippingPriceRemoveProductFromExclude,
ShippingPriceRemoveProductFromExcludeVariables
} from "./types/ShippingPriceRemoveProductFromExclude";
import {
UpdateDefaultWeightUnit,
UpdateDefaultWeightUnitVariables
} from "./types/UpdateDefaultWeightUnit";
import {
UpdateShippingRate,
UpdateShippingRateVariables
} from "./types/UpdateShippingRate";
import {
UpdateShippingZone,
UpdateShippingZoneVariables
} from "./types/UpdateShippingZone";
const deleteShippingZone = gql`
${shippingErrorFragment}
mutation DeleteShippingZone($id: ID!) {
shippingZoneDelete(id: $id) {
errors: shippingErrors {
...ShippingErrorFragment
}
}
}
`;
export const useShippingZoneDelete = makeMutation<
DeleteShippingZone,
DeleteShippingZoneVariables
>(deleteShippingZone);
const bulkDeleteShippingZone = gql`
${shippingErrorFragment}
mutation BulkDeleteShippingZone($ids: [ID]!) {
shippingZoneBulkDelete(ids: $ids) {
errors: shippingErrors {
...ShippingErrorFragment
}
}
}
`;
export const useShippingZoneBulkDelete = makeMutation<
BulkDeleteShippingZone,
BulkDeleteShippingZoneVariables
>(bulkDeleteShippingZone);
const updateDefaultWeightUnit = gql`
mutation UpdateDefaultWeightUnit($unit: WeightUnitsEnum) {
shopSettingsUpdate(input: { defaultWeightUnit: $unit }) {
errors {
field
message
}
shop {
defaultWeightUnit
}
}
}
`;
export const useDefaultWeightUnitUpdate = makeMutation<
UpdateDefaultWeightUnit,
UpdateDefaultWeightUnitVariables
>(updateDefaultWeightUnit);
const createShippingZone = gql`
${countryFragment}
${shippingErrorFragment}
mutation CreateShippingZone($input: ShippingZoneCreateInput!) {
shippingZoneCreate(input: $input) {
errors: shippingErrors {
...ShippingErrorFragment
}
shippingZone {
countries {
...CountryFragment
}
default
id
name
}
}
}
`;
export const useShippingZoneCreate = makeMutation<
CreateShippingZone,
CreateShippingZoneVariables
>(createShippingZone);
const updateShippingZone = gql`
${countryFragment}
${shippingErrorFragment}
mutation UpdateShippingZone($id: ID!, $input: ShippingZoneUpdateInput!) {
shippingZoneUpdate(id: $id, input: $input) {
errors: shippingErrors {
...ShippingErrorFragment
}
shippingZone {
countries {
...CountryFragment
}
default
id
name
}
}
}
`;
export const useShippingZoneUpdate = makeMutation<
UpdateShippingZone,
UpdateShippingZoneVariables
>(updateShippingZone);
const updateShippingRate = gql`
${shippingErrorFragment}
${shippingMethodFragment}
mutation UpdateShippingRate($id: ID!, $input: ShippingPriceInput!) {
shippingPriceUpdate(id: $id, input: $input) {
errors: shippingErrors {
...ShippingErrorFragment
}
shippingMethod {
...ShippingMethodFragment
}
}
}
`;
export const useShippingRateUpdate = makeMutation<
UpdateShippingRate,
UpdateShippingRateVariables
>(updateShippingRate);
const createShippingRate = gql`
${shippingErrorFragment}
${shippingMethodFragment}
${shippingZoneDetailsFragment}
mutation CreateShippingRate($input: ShippingPriceInput!) {
shippingPriceCreate(input: $input) {
errors: shippingErrors {
...ShippingErrorFragment
}
shippingZone {
...ShippingZoneDetailsFragment
}
shippingMethod {
...ShippingMethodFragment
}
}
}
`;
export const useShippingRateCreate = makeMutation<
CreateShippingRate,
CreateShippingRateVariables
>(createShippingRate);
const deleteShippingRate = gql`
${shippingErrorFragment}
${shippingZoneDetailsFragment}
mutation DeleteShippingRate($id: ID!) {
shippingPriceDelete(id: $id) {
errors: shippingErrors {
...ShippingErrorFragment
}
shippingZone {
...ShippingZoneDetailsFragment
}
}
}
`;
export const useShippingRateDelete = makeMutation<
DeleteShippingRate,
DeleteShippingRateVariables
>(deleteShippingRate);
const bulkDeleteShippingRate = gql`
${shippingErrorFragment}
mutation BulkDeleteShippingRate($ids: [ID]!) {
shippingPriceBulkDelete(ids: $ids) {
errors: shippingErrors {
...ShippingErrorFragment
}
}
}
`;
export const useShippingRateBulkDelete = makeMutation<
BulkDeleteShippingRate,
BulkDeleteShippingRateVariables
>(bulkDeleteShippingRate);
export const shippingMethodChannelListingUpdate = gql`
${shippingChannelsErrorFragment}
${shippingMethodFragment}
mutation ShippingMethodChannelListingUpdate(
$id: ID!
$input: ShippingMethodChannelListingInput!
) {
shippingMethodChannelListingUpdate(id: $id, input: $input) {
shippingMethod {
...ShippingMethodFragment
}
errors: shippingErrors {
...ShippingChannelsErrorFragment
}
}
}
`;
export const useShippingMethodChannelListingUpdate = makeMutation<
ShippingMethodChannelListingUpdate,
ShippingMethodChannelListingUpdateVariables
>(shippingMethodChannelListingUpdate);
export const shippingMethodZipCodeRangeAssign = gql`
${shippingChannelsErrorFragment}
${shippingMethodWithZipCodesFragment}
mutation ShippingMethodZipCodeRangeAssign(
$id: ID!
$input: ShippingZipCodeRulesCreateInput!
) {
shippingMethodZipCodeRulesCreate(shippingMethodId: $id, input: $input) {
errors: shippingErrors {
...ShippingChannelsErrorFragment
}
shippingMethod {
...ShippingMethodWithZipCodesFragment
}
}
}
`;
export const useShippingMethodZipCodeRangeAssign = makeMutation<
ShippingMethodZipCodeRangeAssign,
ShippingMethodZipCodeRangeAssignVariables
>(shippingMethodZipCodeRangeAssign);
export const shippingMethodZipCodeRulesDelete = gql`
${shippingChannelsErrorFragment}
${shippingMethodWithZipCodesFragment}
mutation ShippingMethodZipCodeRangeUnassign($id: ID!) {
shippingMethodZipCodeRulesDelete(id: $id) {
errors: shippingErrors {
...ShippingChannelsErrorFragment
}
shippingMethod {
...ShippingMethodWithZipCodesFragment
}
}
}
`;
export const useShippingMethodZipCodeRangeUnassign = makeMutation<
ShippingMethodZipCodeRangeUnassign,
ShippingMethodZipCodeRangeUnassignVariables
>(shippingMethodZipCodeRulesDelete);
export const shippingPriceExcludeProducts = gql`
${shippingErrorFragment}
mutation ShippingPriceExcludeProduct(
$id: ID!
$input: ShippingPriceExcludeProductsInput!
) {
shippingPriceExcludeProducts(id: $id, input: $input) {
errors: shippingErrors {
...ShippingErrorFragment
}
}
}
`;
export const useShippingPriceExcludeProduct = makeMutation<
ShippingPriceExcludeProduct,
ShippingPriceExcludeProductVariables
>(shippingPriceExcludeProducts);
export const shippingPriceRemoveProductsFromExclude = gql`
${shippingErrorFragment}
mutation ShippingPriceRemoveProductFromExclude($id: ID!, $products: [ID]!) {
shippingPriceRemoveProductFromExclude(id: $id, products: $products) {
errors: shippingErrors {
...ShippingErrorFragment
}
}
}
`;
export const useShippingPriceRemoveProductsFromExclude = makeMutation<
ShippingPriceRemoveProductFromExclude,
ShippingPriceRemoveProductFromExcludeVariables
>(shippingPriceRemoveProductsFromExclude);