-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Remove ts-strict-ignore and fix TypeScript errors [shipping] #6114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
0f018aa
c57d443
a80cc42
d156173
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,4 +1,3 @@ | ||||||
| // @ts-strict-ignore | ||||||
| import { Button } from "@dashboard/components/Button"; | ||||||
| import { DashboardCard } from "@dashboard/components/Card"; | ||||||
| import RadioGroupField from "@dashboard/components/RadioGroupField"; | ||||||
|
|
@@ -19,7 +18,9 @@ interface ShippingZonePostalCodesProps { | |||||
| initialExpanded?: boolean; | ||||||
| postalCodes: ShippingMethodTypeFragment["postalCodeRules"] | undefined; | ||||||
| onPostalCodeInclusionChange: (inclusion: PostalCodeRuleInclusionTypeEnum) => void; | ||||||
| onPostalCodeDelete: (code: ShippingMethodTypeFragment["postalCodeRules"][0]) => void; | ||||||
| onPostalCodeDelete: ( | ||||||
| code: NonNullable<ShippingMethodTypeFragment["postalCodeRules"]>[number], | ||||||
| ) => void; | ||||||
| onPostalCodeRangeAdd: () => void; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -59,15 +60,17 @@ const ShippingZonePostalCodes = ({ | |||||
| onPostalCodeRangeAdd, | ||||||
| }: ShippingZonePostalCodesProps) => { | ||||||
| const [expanded, setExpanded] = React.useState(initialExpanded); | ||||||
| const [inclusionType, setInclusionType] = React.useState(null); | ||||||
| const [inclusionType, setInclusionType] = React.useState<string | null>(null); | ||||||
| const intl = useIntl(); | ||||||
| const classes = useStyles({}); | ||||||
| const getInclusionType = () => { | ||||||
| if (inclusionType) { | ||||||
| return inclusionType; | ||||||
| } | ||||||
|
|
||||||
| return postalCodes[0]?.inclusionType || PostalCodeRuleInclusionTypeEnum.EXCLUDE; | ||||||
| return ( | ||||||
| (postalCodes && postalCodes[0]?.inclusionType) || PostalCodeRuleInclusionTypeEnum.EXCLUDE | ||||||
| ); | ||||||
| }; | ||||||
| const onInclusionRadioChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||||||
| const value = event.target.value; | ||||||
|
|
@@ -80,7 +83,15 @@ const ShippingZonePostalCodes = ({ | |||||
| onPostalCodeInclusionChange(postalType); | ||||||
| }; | ||||||
| const getPostalCodeRangeLabel = ( | ||||||
| postalCodeRange: ShippingMethodTypeFragment["postalCodeRules"][0], | ||||||
| postalCodeRange: | ||||||
| | { | ||||||
| __typename: "ShippingMethodPostalCodeRule"; | ||||||
| id: string; | ||||||
| inclusionType: PostalCodeRuleInclusionTypeEnum | null; | ||||||
| start: string | null; | ||||||
| end: string | null; | ||||||
| } | ||||||
| | undefined, | ||||||
| ) => { | ||||||
| if (!postalCodeRange?.start) { | ||||||
| return <Skeleton />; | ||||||
|
|
@@ -171,7 +182,7 @@ const ShippingZonePostalCodes = ({ | |||||
| <TableHead> | ||||||
| <TableRowLink> | ||||||
| <TableCell> | ||||||
| {postalCodes === undefined ? ( | ||||||
| {postalCodes == null ? ( | ||||||
|
||||||
| {postalCodes == null ? ( | |
| {postalCodes==null ? ( |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| // @ts-strict-ignore | ||
| import { ChannelShippingData } from "@dashboard/channels/utils"; | ||
| import { | ||
| CountryFragment, | ||
|
|
@@ -48,7 +47,7 @@ export const createChannelsChangeHandler = | |
| }; | ||
|
|
||
| const getPostalCodeRulesToAdd = (rules: ShippingMethodTypeFragment["postalCodeRules"]) => | ||
| rules | ||
| (rules || []) | ||
| .filter(code => !code.id || code.id === "0") | ||
| .map( | ||
| code => | ||
|
|
@@ -77,7 +76,7 @@ function getCreateShippingPriceRateVariables( | |
| name: data.name, | ||
| shippingZone: id, | ||
| type: ShippingMethodTypeEnum.PRICE, | ||
| description: getParsedDataForJsonStringField(data.description), | ||
| description: data.description ? getParsedDataForJsonStringField(data.description) : null, | ||
| taxClass: data.taxClassId, | ||
| }, | ||
| }; | ||
|
|
@@ -107,7 +106,7 @@ function getCreateShippingWeightRateVariables( | |
| name: data.name, | ||
| shippingZone: id, | ||
| type: ShippingMethodTypeEnum.WEIGHT, | ||
| description: getParsedDataForJsonStringField(data.description), | ||
| description: data.description ? getParsedDataForJsonStringField(data.description) : null, | ||
| taxClass: data.taxClassId, | ||
| }, | ||
| }; | ||
|
|
@@ -130,13 +129,14 @@ export function getUpdateShippingPriceRateVariables( | |
| addPostalCodeRules: postalCodeRules, | ||
| deletePostalCodeRules, | ||
| inclusionType: | ||
| addPostalCodeRules[0]?.inclusionType || PostalCodeRuleInclusionTypeEnum.EXCLUDE, | ||
| (addPostalCodeRules && addPostalCodeRules[0]?.inclusionType) || | ||
| PostalCodeRuleInclusionTypeEnum.EXCLUDE, | ||
| maximumDeliveryDays: parsedMaxDays, | ||
| minimumDeliveryDays: parsedMinDays, | ||
| name: data.name, | ||
| shippingZone: id, | ||
| type: ShippingMethodTypeEnum.PRICE, | ||
| description: getParsedDataForJsonStringField(data.description), | ||
| description: data.description ? getParsedDataForJsonStringField(data.description) : null, | ||
| taxClass: data.taxClassId, | ||
| }, | ||
| }; | ||
|
|
@@ -162,15 +162,16 @@ export function getUpdateShippingWeightRateVariables( | |
| addPostalCodeRules: postalCodeRules, | ||
| deletePostalCodeRules, | ||
| inclusionType: | ||
| addPostalCodeRules[0]?.inclusionType || PostalCodeRuleInclusionTypeEnum.EXCLUDE, | ||
| (addPostalCodeRules && addPostalCodeRules[0]?.inclusionType) || | ||
| PostalCodeRuleInclusionTypeEnum.EXCLUDE, | ||
| maximumDeliveryDays: parsedMaxDays, | ||
| maximumOrderWeight: isWeightSet ? parsedMaxValue : null, | ||
| minimumDeliveryDays: parsedMinDays, | ||
| minimumOrderWeight: isWeightSet ? parsedMinValue : null, | ||
| name: data.name, | ||
| shippingZone: id, | ||
| type: ShippingMethodTypeEnum.WEIGHT, | ||
| description: getParsedDataForJsonStringField(data.description), | ||
| description: data.description ? getParsedDataForJsonStringField(data.description) : null, | ||
| taxClass: data.taxClassId, | ||
| }, | ||
| }; | ||
|
|
@@ -221,12 +222,21 @@ export function useShippingRateCreator( | |
| const response = await createBaseShippingRate({ | ||
| variables: getVariables(data, shippingZoneId, postalCodes, inclusionType), | ||
| }); | ||
|
|
||
| if (!response.data?.shippingPriceCreate) { | ||
| throw new Error("Failed to create shipping rate"); | ||
| } | ||
|
Comment on lines
+226
to
+228
|
||
|
|
||
| const createErrors = response.data.shippingPriceCreate.errors; | ||
|
|
||
| if (createErrors.length > 0) { | ||
| return createErrors; | ||
| } | ||
|
|
||
| if (!response.data.shippingPriceCreate.shippingMethod) { | ||
| throw new Error("Failed to create shipping method"); | ||
| } | ||
|
Comment on lines
+236
to
+238
|
||
|
|
||
| const rateId = response.data.shippingPriceCreate.shippingMethod.id; | ||
| const errors = await extractMutationErrors( | ||
| updateShippingMethodChannelListing({ | ||
|
|
@@ -263,9 +273,9 @@ export function useShippingRateCreator( | |
| const called = createBaseShippingRateOpts.called || updateShippingMethodChannelListingOpts.called; | ||
| const loading = | ||
| createBaseShippingRateOpts.loading || updateShippingMethodChannelListingOpts.loading; | ||
| const errors = [...(createBaseShippingRateOpts.data?.shippingPriceCreate.errors || [])]; | ||
| const errors = [...(createBaseShippingRateOpts.data?.shippingPriceCreate?.errors || [])]; | ||
| const channelErrors = | ||
| updateShippingMethodChannelListingOpts.data?.shippingMethodChannelListingUpdate.errors || []; | ||
| updateShippingMethodChannelListingOpts.data?.shippingMethodChannelListingUpdate?.errors || []; | ||
|
|
||
| return { | ||
| channelErrors, | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,8 +1,11 @@ | ||||||
| // @ts-strict-ignore | ||||||
| import { createSortedShippingChannels } from "@dashboard/channels/utils"; | ||||||
| import ChannelsAvailabilityDialog from "@dashboard/components/ChannelsAvailabilityDialog"; | ||||||
| import { WindowTitle } from "@dashboard/components/WindowTitle"; | ||||||
| import { PostalCodeRuleInclusionTypeEnum, useShippingZoneChannelsQuery } from "@dashboard/graphql"; | ||||||
| import { | ||||||
| PostalCodeRuleInclusionTypeEnum, | ||||||
| ShippingMethodWithPostalCodesFragment, | ||||||
| useShippingZoneChannelsQuery, | ||||||
| } from "@dashboard/graphql"; | ||||||
| import useChannels from "@dashboard/hooks/useChannels"; | ||||||
| import useNavigator from "@dashboard/hooks/useNavigator"; | ||||||
| import { sectionNames } from "@dashboard/intl"; | ||||||
|
|
@@ -68,22 +71,24 @@ const RateCreate = ({ id, params }: RateCreateProps) => { | |||||
| }); | ||||||
| const { channelErrors, createShippingRate, errors, status } = useShippingRateCreator( | ||||||
| id, | ||||||
| params.type, | ||||||
| state.postalCodeRules, | ||||||
| state.inclusionType, | ||||||
| params.type!, | ||||||
| state.postalCodeRules || [], | ||||||
| state.inclusionType!, | ||||||
|
Comment on lines
+74
to
+76
|
||||||
| ); | ||||||
| const onPostalCodeAssign = (rule: MinMax) => { | ||||||
| if (state.postalCodeRules.filter(getPostalCodeRuleByMinMax(rule)).length > 0) { | ||||||
| const postalCodeRules = state.postalCodeRules || []; | ||||||
|
|
||||||
| if (postalCodeRules.filter(getPostalCodeRuleByMinMax(rule)).length > 0) { | ||||||
| closeModal(); | ||||||
|
|
||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| const newCode = getRuleObject(rule, state.inclusionType); | ||||||
| const newCode = getRuleObject(rule, state.inclusionType!); | ||||||
|
||||||
| const newCode = getRuleObject(rule, state.inclusionType!); | |
| const newCode = getRuleObject(rule, state.inclusionType ?? PostalCodeRuleInclusionTypeEnum.EXCLUDE); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -265,7 +265,10 @@ const RateUpdate = ({ id, rateId, params }: RateUpdateProps) => { | |||||
| } else { | ||||||
| dispatch({ | ||||||
| havePostalCodesChanged: true, | ||||||
| postalCodeRules: filterPostalCodes(state.postalCodeRules, code), | ||||||
| postalCodeRules: filterPostalCodes( | ||||||
| state.postalCodeRules!, | ||||||
| code as NonNullable<ShippingMethodWithPostalCodesFragment["postalCodeRules"]>[number], | ||||||
|
||||||
| code as NonNullable<ShippingMethodWithPostalCodesFragment["postalCodeRules"]>[number], | |
| code, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this mapping ensures
channelsis always defined, creating a new array of error objects with spread operations for every render is inefficient. SinceShippingChannelsErrorFragmentshould guaranteechannelsis defined (based on GraphQL schema), a type assertion would be more efficient. If the schema truly allows nullable channels, consider memoizing this transformation withuseMemo: