Skip to content

Commit

Permalink
Merge pull request #876 from mirumee/zip-codes/update-schema-and-refa…
Browse files Browse the repository at this point in the history
…ctor

Update schema and refactor zip code exclusion
  • Loading branch information
dominik-zeglen authored Nov 30, 2020
2 parents a9bfc72 + fb9f268 commit de10abf
Show file tree
Hide file tree
Showing 25 changed files with 380 additions and 277 deletions.
27 changes: 16 additions & 11 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2556,8 +2556,8 @@ type Mutation {
shopSettingsTranslate(input: ShopSettingsTranslationInput!, languageCode: LanguageCodeEnum!): ShopSettingsTranslate
shopAddressUpdate(input: AddressInput): ShopAddressUpdate
shippingMethodChannelListingUpdate(id: ID!, input: ShippingMethodChannelListingInput!): ShippingMethodChannelListingUpdate
shippingMethodZipCodeCreate(input: ShippingZipCodeCreateInput!): ShippingZipCodeCreate
shippingMethodZipCodeDelete(id: ID!): ShippingZipCodeDelete
shippingMethodZipCodeRulesCreate(input: ShippingZipCodeRulesCreateInput!, shippingMethodId: ID!): ShippingZipCodeRulesCreate
shippingMethodZipCodeRulesDelete(id: ID!): ShippingZipCodeRulesDelete
shippingPriceCreate(input: ShippingPriceInput!): ShippingPriceCreate
shippingPriceDelete(id: ID!): ShippingPriceDelete
shippingPriceBulkDelete(ids: [ID]!): ShippingPriceBulkDelete
Expand Down Expand Up @@ -4584,7 +4584,7 @@ type ShippingMethod implements Node & ObjectWithMetadata {
price: Money
maximumOrderPrice: Money
minimumOrderPrice: Money
zipCodes: [ShippingMethodZipCode]
zipCodeRules: [ShippingMethodZipCodeRule]
}

type ShippingMethodChannelListing implements Node {
Expand Down Expand Up @@ -4631,7 +4631,7 @@ enum ShippingMethodTypeEnum {
WEIGHT
}

type ShippingMethodZipCode implements Node {
type ShippingMethodZipCodeRule implements Node {
start: String
end: String
id: ID!
Expand Down Expand Up @@ -4678,22 +4678,27 @@ type ShippingPriceUpdate {
shippingErrors: [ShippingError!]!
}

type ShippingZipCodeCreate {
type ShippingZipCodeRulesCreate {
errors: [Error!]! @deprecated(reason: "Use typed errors with error codes. This field will be removed after 2020-07-31.")
shippingMethodZipCode: ShippingMethodZipCode
zipCodeRules: [ShippingMethodZipCodeRule]
shippingMethod: ShippingMethod
shippingErrors: [ShippingError!]!
}

input ShippingZipCodeCreateInput {
shippingMethod: ID!
input ShippingZipCodeRulesCreateInput {
zipCodeRules: [ShippingZipCodeRulesCreateInputRange]!
}

input ShippingZipCodeRulesCreateInputRange {
start: String!
end: String!
end: String
}

type ShippingZipCodeDelete {
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!]!
shippingMethodZipCode: ShippingMethodZipCode
shippingMethodZipCodeRule: ShippingMethodZipCodeRule
}

type ShippingZone implements Node & ObjectWithMetadata {
Expand Down
19 changes: 13 additions & 6 deletions src/fragments/shipping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,22 @@ export const shippingZoneFragment = gql`
name
}
`;

export const shippingMethodWithZipCodesFragment = gql`
fragment ShippingMethodWithZipCodesFragment on ShippingMethod {
id
zipCodeRules {
id
start
end
}
}
`;
export const shippingMethodFragment = gql`
${fragmentMoney}
${shippingMethodWithZipCodesFragment}
fragment ShippingMethodFragment on ShippingMethod {
id
...ShippingMethodWithZipCodesFragment
minimumOrderWeight {
unit
value
Expand Down Expand Up @@ -42,11 +54,6 @@ export const shippingMethodFragment = gql`
...Money
}
}
zipCodes {
id
start
end
}
}
`;
export const shippingZoneDetailsFragment = gql`
Expand Down
16 changes: 8 additions & 8 deletions src/fragments/types/ShippingMethodFragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import { WeightUnitsEnum, ShippingMethodTypeEnum } from "./../../types/globalTyp
// GraphQL fragment: ShippingMethodFragment
// ====================================================

export interface ShippingMethodFragment_zipCodeRules {
__typename: "ShippingMethodZipCodeRule";
id: string;
start: string | null;
end: string | null;
}

export interface ShippingMethodFragment_minimumOrderWeight {
__typename: "Weight";
unit: WeightUnitsEnum;
Expand Down Expand Up @@ -54,20 +61,13 @@ export interface ShippingMethodFragment_channelListings {
maximumOrderPrice: ShippingMethodFragment_channelListings_maximumOrderPrice | null;
}

export interface ShippingMethodFragment_zipCodes {
__typename: "ShippingMethodZipCode";
id: string;
start: string | null;
end: string | null;
}

export interface ShippingMethodFragment {
__typename: "ShippingMethod";
id: string;
zipCodeRules: (ShippingMethodFragment_zipCodeRules | null)[] | null;
minimumOrderWeight: ShippingMethodFragment_minimumOrderWeight | null;
maximumOrderWeight: ShippingMethodFragment_maximumOrderWeight | null;
name: string;
type: ShippingMethodTypeEnum | null;
channelListings: ShippingMethodFragment_channelListings[] | null;
zipCodes: (ShippingMethodFragment_zipCodes | null)[] | null;
}
20 changes: 20 additions & 0 deletions src/fragments/types/ShippingMethodWithZipCodesFragment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* tslint:disable */
/* eslint-disable */
// This file was automatically generated and should not be edited.

// ====================================================
// GraphQL fragment: ShippingMethodWithZipCodesFragment
// ====================================================

export interface ShippingMethodWithZipCodesFragment_zipCodeRules {
__typename: "ShippingMethodZipCodeRule";
id: string;
start: string | null;
end: string | null;
}

export interface ShippingMethodWithZipCodesFragment {
__typename: "ShippingMethod";
id: string;
zipCodeRules: (ShippingMethodWithZipCodesFragment_zipCodeRules | null)[] | null;
}
16 changes: 8 additions & 8 deletions src/fragments/types/ShippingZoneDetailsFragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ export interface ShippingZoneDetailsFragment_countries {
country: string;
}

export interface ShippingZoneDetailsFragment_shippingMethods_zipCodeRules {
__typename: "ShippingMethodZipCodeRule";
id: string;
start: string | null;
end: string | null;
}

export interface ShippingZoneDetailsFragment_shippingMethods_minimumOrderWeight {
__typename: "Weight";
unit: WeightUnitsEnum;
Expand Down Expand Up @@ -60,22 +67,15 @@ export interface ShippingZoneDetailsFragment_shippingMethods_channelListings {
maximumOrderPrice: ShippingZoneDetailsFragment_shippingMethods_channelListings_maximumOrderPrice | null;
}

export interface ShippingZoneDetailsFragment_shippingMethods_zipCodes {
__typename: "ShippingMethodZipCode";
id: string;
start: string | null;
end: string | null;
}

export interface ShippingZoneDetailsFragment_shippingMethods {
__typename: "ShippingMethod";
id: string;
zipCodeRules: (ShippingZoneDetailsFragment_shippingMethods_zipCodeRules | null)[] | null;
minimumOrderWeight: ShippingZoneDetailsFragment_shippingMethods_minimumOrderWeight | null;
maximumOrderWeight: ShippingZoneDetailsFragment_shippingMethods_maximumOrderWeight | null;
name: string;
type: ShippingMethodTypeEnum | null;
channelListings: ShippingZoneDetailsFragment_shippingMethods_channelListings[] | null;
zipCodes: (ShippingZoneDetailsFragment_shippingMethods_zipCodes | null)[] | null;
}

export interface ShippingZoneDetailsFragment_warehouses {
Expand Down
15 changes: 9 additions & 6 deletions src/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,18 @@ export function getMutationState(
interface SaleorMutationResult {
errors?: UserError[];
}
export function getMutationErrors<
TData extends Record<string, SaleorMutationResult>
>(data: TData): UserError[] {
return Object.values(data).reduce(
(acc: UserError[], mut) => [...acc, ...maybe(() => mut.errors, [])],
[]
);
}
export function getMutationStatus<
TData extends Record<string, SaleorMutationResult | any>
>(opts: MutationResult<TData>): ConfirmButtonTransitionState {
const errors = opts.data
? Object.values(opts.data).reduce(
(acc: UserError[], mut) => [...acc, ...maybe(() => mut.errors, [])],
[]
)
: [];
const errors = opts.data ? getMutationErrors(opts.data) : [];

return getMutationState(opts.called, opts.loading, errors);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ const props: ShippingZoneRatesPageProps = {
variant: ShippingMethodTypeEnum.PRICE,
zipCodes: [
{
__typename: "ShippingMethodZipCode",
__typename: "ShippingMethodZipCodeRule",
end: "51-200",
id: "1",
start: "51-220"
},
{
__typename: "ShippingMethodZipCode",
__typename: "ShippingMethodZipCodeRule",
end: "31-101",
id: "1",
start: "44-205"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ShippingChannelsErrorFragment } from "@saleor/fragments/types/ShippingC
import { ShippingErrorFragment } from "@saleor/fragments/types/ShippingErrorFragment";
import {
ShippingMethodFragment,
ShippingMethodFragment_zipCodes
ShippingMethodFragment_zipCodeRules
} from "@saleor/fragments/types/ShippingMethodFragment";
import { validatePrice } from "@saleor/products/utils/validation";
import OrderValue from "@saleor/shipping/components/OrderValue";
Expand Down Expand Up @@ -44,7 +44,7 @@ export interface ShippingZoneRatesPageProps {
disabled: boolean;
hasChannelChanged?: boolean;
rate: ShippingMethodFragment | null;
zipCodes?: ShippingMethodFragment_zipCodes[];
zipCodes?: ShippingMethodFragment_zipCodeRules[];
channelErrors: ShippingChannelsErrorFragment[];
errors: ShippingErrorFragment[];
saveButtonBarState: ConfirmButtonTransitionState;
Expand Down Expand Up @@ -164,7 +164,7 @@ export const ShippingZoneRatesPage: React.FC<ShippingZoneRatesPageProps> = ({
onZipCodeDelete={onZipCodeUnassign}
onZipCodeInclusionChange={() => undefined}
onZipCodeRangeAdd={onZipCodeAssign}
zipCodes={rateExists ? rate?.zipCodes : zipCodes}
zipCodes={rateExists ? rate?.zipCodeRules : zipCodes}
/>
</div>
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ConfirmButton, {
} from "@saleor/components/ConfirmButton";
import Form from "@saleor/components/Form";
import Grid from "@saleor/components/Grid";
import { buttonMessages } from "@saleor/intl";
import { buttonMessages, commonMessages } from "@saleor/intl";
import { DialogProps, MinMax } from "@saleor/types";
import React from "react";
import { FormattedMessage, useIntl } from "react-intl";
Expand Down Expand Up @@ -77,6 +77,7 @@ const ShippingZoneZipCodeRangeDialog: React.FC<ShippingZoneZipCodeRangeDialogPro
description: "range input label"
})}
name="max"
helperText={intl.formatMessage(commonMessages.optionalField)}
value={data.max}
onChange={change}
/>
Expand All @@ -87,7 +88,7 @@ const ShippingZoneZipCodeRangeDialog: React.FC<ShippingZoneZipCodeRangeDialogPro
<FormattedMessage {...buttonMessages.back} />
</Button>
<ConfirmButton
disabled={!hasChanged}
disabled={!hasChanged || !data.min}
transitionState={confirmButtonState}
type="submit"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import CardTitle from "@saleor/components/CardTitle";
import RadioGroupField from "@saleor/components/RadioGroupField";
import ResponsiveTable from "@saleor/components/ResponsiveTable";
import Skeleton from "@saleor/components/Skeleton";
import { ShippingMethodFragment_zipCodes } from "@saleor/fragments/types/ShippingMethodFragment";
import { ShippingMethodFragment_zipCodeRules } from "@saleor/fragments/types/ShippingMethodFragment";
import { FormChange } from "@saleor/hooks/useForm";
import ArrowDropdown from "@saleor/icons/ArrowDropdown";
import { renderCollection } from "@saleor/misc";
Expand All @@ -30,7 +30,7 @@ export interface ShippingZoneZipCodesProps {
data: Record<"includeZipCodes", ZipCodeInclusion>;
disabled: boolean;
initialExpanded?: boolean;
zipCodes: ShippingMethodFragment_zipCodes[] | undefined;
zipCodes: ShippingMethodFragment_zipCodeRules[] | undefined;
onZipCodeInclusionChange: FormChange;
onZipCodeDelete: (id: string) => void;
onZipCodeRangeAdd: () => void;
Expand Down
Loading

0 comments on commit de10abf

Please sign in to comment.