
* 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>
196 lines
6.8 KiB
TypeScript
196 lines
6.8 KiB
TypeScript
import { ChannelShippingData } from "@saleor/channels/utils";
|
|
import AppHeader from "@saleor/components/AppHeader";
|
|
import CardSpacer from "@saleor/components/CardSpacer";
|
|
import ChannelsAvailability from "@saleor/components/ChannelsAvailability";
|
|
import { ConfirmButtonTransitionState } from "@saleor/components/ConfirmButton";
|
|
import Container from "@saleor/components/Container";
|
|
import Form from "@saleor/components/Form";
|
|
import Grid from "@saleor/components/Grid";
|
|
import PageHeader from "@saleor/components/PageHeader";
|
|
import SaveButtonBar from "@saleor/components/SaveButtonBar";
|
|
import { ShippingChannelsErrorFragment } from "@saleor/fragments/types/ShippingChannelsErrorFragment";
|
|
import { ShippingErrorFragment } from "@saleor/fragments/types/ShippingErrorFragment";
|
|
import { validatePrice } from "@saleor/products/utils/validation";
|
|
import OrderValue from "@saleor/shipping/components/OrderValue";
|
|
import OrderWeight from "@saleor/shipping/components/OrderWeight";
|
|
import PricingCard from "@saleor/shipping/components/PricingCard";
|
|
import ShippingMethodProducts from "@saleor/shipping/components/ShippingMethodProducts";
|
|
import ShippingZoneInfo from "@saleor/shipping/components/ShippingZoneInfo";
|
|
import { createChannelsChangeHandler } from "@saleor/shipping/handlers";
|
|
import { ShippingZone_shippingZone_shippingMethods } from "@saleor/shipping/types/ShippingZone";
|
|
import { ListActions, ListProps } from "@saleor/types";
|
|
import { ShippingMethodTypeEnum } from "@saleor/types/globalTypes";
|
|
import React from "react";
|
|
import { FormattedMessage } from "react-intl";
|
|
|
|
import ShippingZoneZipCodes, {
|
|
ZipCodeInclusion
|
|
} from "../ShippingZoneZipCodes";
|
|
|
|
export interface FormData {
|
|
channelListings: ChannelShippingData[];
|
|
includeZipCodes: ZipCodeInclusion;
|
|
name: string;
|
|
noLimits: boolean;
|
|
minValue: string;
|
|
maxValue: string;
|
|
type: ShippingMethodTypeEnum;
|
|
}
|
|
|
|
export interface ShippingZoneRatesPageProps
|
|
extends Pick<ListProps, Exclude<keyof ListProps, "onRowClick">>,
|
|
ListActions {
|
|
allChannelsCount?: number;
|
|
shippingChannels: ChannelShippingData[];
|
|
disabled: boolean;
|
|
hasChannelChanged?: boolean;
|
|
rate: ShippingZone_shippingZone_shippingMethods;
|
|
channelErrors: ShippingChannelsErrorFragment[];
|
|
errors: ShippingErrorFragment[];
|
|
saveButtonBarState: ConfirmButtonTransitionState;
|
|
onBack: () => void;
|
|
onDelete?: () => void;
|
|
onSubmit: (data: FormData) => void;
|
|
onZipCodeAssign: () => void;
|
|
onZipCodeUnassign: (id: string) => void;
|
|
onChannelsChange: (data: ChannelShippingData[]) => void;
|
|
openChannelsModal: () => void;
|
|
onProductAssign: () => void;
|
|
onProductUnassign: (ids: string[]) => void;
|
|
variant: ShippingMethodTypeEnum;
|
|
}
|
|
|
|
export const ShippingZoneRatesPage: React.FC<ShippingZoneRatesPageProps> = ({
|
|
allChannelsCount,
|
|
shippingChannels,
|
|
channelErrors,
|
|
disabled,
|
|
errors,
|
|
hasChannelChanged,
|
|
onBack,
|
|
onDelete,
|
|
onSubmit,
|
|
onChannelsChange,
|
|
onZipCodeAssign,
|
|
onZipCodeUnassign,
|
|
onProductAssign,
|
|
onProductUnassign,
|
|
openChannelsModal,
|
|
rate,
|
|
saveButtonBarState,
|
|
variant,
|
|
...listProps
|
|
}) => {
|
|
const isPriceVariant = variant === ShippingMethodTypeEnum.PRICE;
|
|
const initialForm: FormData = {
|
|
channelListings: shippingChannels,
|
|
includeZipCodes: ZipCodeInclusion.Exclude,
|
|
maxValue: rate?.maximumOrderWeight?.value.toString() || "",
|
|
minValue: rate?.minimumOrderWeight?.value.toString() || "",
|
|
name: rate?.name || "",
|
|
noLimits: false,
|
|
type: rate?.type || null
|
|
};
|
|
|
|
return (
|
|
<Form initial={initialForm} onSubmit={onSubmit}>
|
|
{({ change, data, hasChanged, submit, triggerChange }) => {
|
|
const handleChannelsChange = createChannelsChangeHandler(
|
|
shippingChannels,
|
|
onChannelsChange,
|
|
triggerChange
|
|
);
|
|
const formDisabled = data.channelListings?.some(channel =>
|
|
validatePrice(channel.price)
|
|
);
|
|
|
|
return (
|
|
<Container>
|
|
<AppHeader onBack={onBack}>
|
|
<FormattedMessage defaultMessage="Shipping" />
|
|
</AppHeader>
|
|
<PageHeader title={rate?.name} />
|
|
<Grid>
|
|
<div>
|
|
<ShippingZoneInfo
|
|
data={data}
|
|
disabled={disabled}
|
|
errors={errors}
|
|
onChange={change}
|
|
/>
|
|
<CardSpacer />
|
|
{isPriceVariant ? (
|
|
<OrderValue
|
|
channels={data.channelListings}
|
|
errors={channelErrors}
|
|
noLimits={data.noLimits}
|
|
disabled={disabled}
|
|
onChange={change}
|
|
onChannelsChange={handleChannelsChange}
|
|
/>
|
|
) : (
|
|
<OrderWeight
|
|
noLimits={data.noLimits}
|
|
disabled={disabled}
|
|
minValue={data.minValue}
|
|
maxValue={data.maxValue}
|
|
onChange={change}
|
|
errors={errors}
|
|
/>
|
|
)}
|
|
<CardSpacer />
|
|
<PricingCard
|
|
channels={data.channelListings}
|
|
onChange={handleChannelsChange}
|
|
disabled={disabled}
|
|
errors={channelErrors}
|
|
/>
|
|
<CardSpacer />
|
|
<ShippingZoneZipCodes
|
|
data={data}
|
|
disabled={disabled}
|
|
onZipCodeDelete={onZipCodeUnassign}
|
|
onZipCodeInclusionChange={() => undefined}
|
|
onZipCodeRangeAdd={onZipCodeAssign}
|
|
zipCodes={rate?.zipCodeRules}
|
|
/>
|
|
<CardSpacer />
|
|
<ShippingMethodProducts
|
|
products={rate?.excludedProducts?.edges.map(
|
|
edge => edge.node
|
|
)}
|
|
onProductAssign={onProductAssign}
|
|
onProductUnassign={onProductUnassign}
|
|
disabled={disabled}
|
|
{...listProps}
|
|
/>
|
|
</div>
|
|
<div>
|
|
<ChannelsAvailability
|
|
allChannelsCount={allChannelsCount}
|
|
selectedChannelsCount={shippingChannels?.length}
|
|
channelsList={data.channelListings.map(channel => ({
|
|
id: channel.id,
|
|
name: channel.name
|
|
}))}
|
|
openModal={openChannelsModal}
|
|
/>
|
|
</div>
|
|
</Grid>
|
|
<SaveButtonBar
|
|
disabled={
|
|
disabled || formDisabled || (!hasChanged && !hasChannelChanged)
|
|
}
|
|
onCancel={onBack}
|
|
onDelete={onDelete}
|
|
onSave={submit}
|
|
state={saveButtonBarState}
|
|
/>
|
|
</Container>
|
|
);
|
|
}}
|
|
</Form>
|
|
);
|
|
};
|
|
|
|
export default ShippingZoneRatesPage;
|