Add warehouse search
This commit is contained in:
parent
93d1d74230
commit
fbc809879f
5 changed files with 39 additions and 22 deletions
|
@ -105,7 +105,7 @@ const ShippingZoneAddWarehouseDialog: React.FC<ShippingZoneAddWarehouseDialogPro
|
||||||
/>
|
/>
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
<Form errors={errors} initial={initialForm} onSubmit={handleSubmit}>
|
<Form errors={errors} initial={initialForm} onSubmit={handleSubmit}>
|
||||||
{({ change, data, errors: formErrors, submit }) => {
|
{({ change, data, errors: formErrors }) => {
|
||||||
const handleCountrySelect = createSingleAutocompleteSelectHandler(
|
const handleCountrySelect = createSingleAutocompleteSelectHandler(
|
||||||
change,
|
change,
|
||||||
setCountryDisplayName,
|
setCountryDisplayName,
|
||||||
|
|
|
@ -15,6 +15,7 @@ import createMultiAutocompleteSelectHandler from "@saleor/utils/handlers/multiAu
|
||||||
import { MultiAutocompleteChoiceType } from "@saleor/components/MultiAutocompleteSelectField";
|
import { MultiAutocompleteChoiceType } from "@saleor/components/MultiAutocompleteSelectField";
|
||||||
import useStateFromProps from "@saleor/hooks/useStateFromProps";
|
import useStateFromProps from "@saleor/hooks/useStateFromProps";
|
||||||
import { maybe } from "../../../misc";
|
import { maybe } from "../../../misc";
|
||||||
|
import { FetchMoreProps, SearchProps } from "../../../types";
|
||||||
import { ShippingMethodTypeEnum } from "../../../types/globalTypes";
|
import { ShippingMethodTypeEnum } from "../../../types/globalTypes";
|
||||||
import {
|
import {
|
||||||
ShippingZoneDetailsFragment,
|
ShippingZoneDetailsFragment,
|
||||||
|
@ -29,7 +30,9 @@ export interface FormData {
|
||||||
warehouses: string[];
|
warehouses: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ShippingZoneDetailsPageProps {
|
export interface ShippingZoneDetailsPageProps
|
||||||
|
extends FetchMoreProps,
|
||||||
|
SearchProps {
|
||||||
disabled: boolean;
|
disabled: boolean;
|
||||||
errors: ShippingErrorFragment[];
|
errors: ShippingErrorFragment[];
|
||||||
saveButtonBarState: ConfirmButtonTransitionState;
|
saveButtonBarState: ConfirmButtonTransitionState;
|
||||||
|
@ -60,13 +63,17 @@ function warehouseToChoice(
|
||||||
const ShippingZoneDetailsPage: React.FC<ShippingZoneDetailsPageProps> = ({
|
const ShippingZoneDetailsPage: React.FC<ShippingZoneDetailsPageProps> = ({
|
||||||
disabled,
|
disabled,
|
||||||
errors,
|
errors,
|
||||||
|
hasMore,
|
||||||
|
loading,
|
||||||
onBack,
|
onBack,
|
||||||
onCountryAdd,
|
onCountryAdd,
|
||||||
onCountryRemove,
|
onCountryRemove,
|
||||||
onDelete,
|
onDelete,
|
||||||
|
onFetchMore,
|
||||||
onPriceRateAdd,
|
onPriceRateAdd,
|
||||||
onPriceRateEdit,
|
onPriceRateEdit,
|
||||||
onRateRemove,
|
onRateRemove,
|
||||||
|
onSearchChange,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
onWarehouseAdd,
|
onWarehouseAdd,
|
||||||
onWeightRateAdd,
|
onWeightRateAdd,
|
||||||
|
@ -140,10 +147,8 @@ const ShippingZoneDetailsPage: React.FC<ShippingZoneDetailsPageProps> = ({
|
||||||
onRateAdd={onPriceRateAdd}
|
onRateAdd={onPriceRateAdd}
|
||||||
onRateEdit={onPriceRateEdit}
|
onRateEdit={onPriceRateEdit}
|
||||||
onRateRemove={onRateRemove}
|
onRateRemove={onRateRemove}
|
||||||
rates={maybe(() =>
|
rates={shippingZone?.shippingMethods?.filter(
|
||||||
shippingZone.shippingMethods.filter(
|
method => method.type === ShippingMethodTypeEnum.PRICE
|
||||||
method => method.type === ShippingMethodTypeEnum.PRICE
|
|
||||||
)
|
|
||||||
)}
|
)}
|
||||||
variant="price"
|
variant="price"
|
||||||
/>
|
/>
|
||||||
|
@ -153,10 +158,8 @@ const ShippingZoneDetailsPage: React.FC<ShippingZoneDetailsPageProps> = ({
|
||||||
onRateAdd={onWeightRateAdd}
|
onRateAdd={onWeightRateAdd}
|
||||||
onRateEdit={onWeightRateEdit}
|
onRateEdit={onWeightRateEdit}
|
||||||
onRateRemove={onRateRemove}
|
onRateRemove={onRateRemove}
|
||||||
rates={maybe(() =>
|
rates={shippingZone?.shippingMethods?.filter(
|
||||||
shippingZone.shippingMethods.filter(
|
method => method.type === ShippingMethodTypeEnum.WEIGHT
|
||||||
method => method.type === ShippingMethodTypeEnum.WEIGHT
|
|
||||||
)
|
|
||||||
)}
|
)}
|
||||||
variant="weight"
|
variant="weight"
|
||||||
/>
|
/>
|
||||||
|
@ -165,12 +168,13 @@ const ShippingZoneDetailsPage: React.FC<ShippingZoneDetailsPageProps> = ({
|
||||||
<ShippingZoneWarehouses
|
<ShippingZoneWarehouses
|
||||||
data={data}
|
data={data}
|
||||||
displayValue={warehouseDisplayValues}
|
displayValue={warehouseDisplayValues}
|
||||||
hasMore={false}
|
hasMore={hasMore}
|
||||||
loading={false}
|
loading={loading}
|
||||||
warehouses={warehouseChoices}
|
|
||||||
onChange={handleWarehouseChange}
|
onChange={handleWarehouseChange}
|
||||||
onFetchMore={() => undefined}
|
onFetchMore={onFetchMore}
|
||||||
|
onSearchChange={onSearchChange}
|
||||||
onWarehouseAdd={onWarehouseAdd}
|
onWarehouseAdd={onWarehouseAdd}
|
||||||
|
warehouses={warehouseChoices}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
|
@ -4,7 +4,7 @@ import React from "react";
|
||||||
import { useIntl } from "react-intl";
|
import { useIntl } from "react-intl";
|
||||||
|
|
||||||
import CardTitle from "@saleor/components/CardTitle";
|
import CardTitle from "@saleor/components/CardTitle";
|
||||||
import { FetchMoreProps } from "@saleor/types";
|
import { FetchMoreProps, SearchProps } from "@saleor/types";
|
||||||
import { FormChange } from "@saleor/hooks/useForm";
|
import { FormChange } from "@saleor/hooks/useForm";
|
||||||
import MultiAutocompleteSelectField, {
|
import MultiAutocompleteSelectField, {
|
||||||
MultiAutocompleteChoiceType
|
MultiAutocompleteChoiceType
|
||||||
|
@ -13,7 +13,7 @@ import MultiAutocompleteSelectField, {
|
||||||
interface ShippingZoneWarehousesFormData {
|
interface ShippingZoneWarehousesFormData {
|
||||||
warehouses: string[];
|
warehouses: string[];
|
||||||
}
|
}
|
||||||
interface ShippingZonewWarehousesProps extends FetchMoreProps {
|
interface ShippingZonewWarehousesProps extends FetchMoreProps, SearchProps {
|
||||||
data: ShippingZoneWarehousesFormData;
|
data: ShippingZoneWarehousesFormData;
|
||||||
displayValue: MultiAutocompleteChoiceType[];
|
displayValue: MultiAutocompleteChoiceType[];
|
||||||
warehouses: MultiAutocompleteChoiceType[];
|
warehouses: MultiAutocompleteChoiceType[];
|
||||||
|
@ -30,6 +30,7 @@ export const ShippingZoneWarehouses: React.FC<ShippingZonewWarehousesProps> = pr
|
||||||
warehouses,
|
warehouses,
|
||||||
onChange,
|
onChange,
|
||||||
onFetchMore,
|
onFetchMore,
|
||||||
|
onSearchChange,
|
||||||
onWarehouseAdd
|
onWarehouseAdd
|
||||||
} = props;
|
} = props;
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
@ -53,8 +54,12 @@ export const ShippingZoneWarehouses: React.FC<ShippingZonewWarehousesProps> = pr
|
||||||
}}
|
}}
|
||||||
choices={warehouses}
|
choices={warehouses}
|
||||||
displayValues={displayValue}
|
displayValues={displayValue}
|
||||||
fetchChoices={() => undefined}
|
fetchChoices={onSearchChange}
|
||||||
hasMore={hasMore}
|
hasMore={hasMore}
|
||||||
|
helperText={intl.formatMessage({
|
||||||
|
defaultMessage:
|
||||||
|
"Select warehouse from which you will ship products for this shipping zone. This warehouse address will also be used to calculate taxes."
|
||||||
|
})}
|
||||||
label={intl.formatMessage({
|
label={intl.formatMessage({
|
||||||
defaultMessage: "Warehouse"
|
defaultMessage: "Warehouse"
|
||||||
})}
|
})}
|
||||||
|
|
|
@ -57,9 +57,11 @@ const ShippingZoneDetails: React.FC<ShippingZoneDetailsProps> = ({
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const shop = useShop();
|
const shop = useShop();
|
||||||
|
|
||||||
const { result: searchWarehousesOpts } = useWarehouseSearch({
|
const { result: searchWarehousesOpts, loadMore, search } = useWarehouseSearch(
|
||||||
variables: DEFAULT_INITIAL_SEARCH_DATA
|
{
|
||||||
});
|
variables: DEFAULT_INITIAL_SEARCH_DATA
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const [assignToWarehouse] = useAassignShippingZoneToWarehouse({});
|
const [assignToWarehouse] = useAassignShippingZoneToWarehouse({});
|
||||||
|
|
||||||
|
@ -208,6 +210,10 @@ const ShippingZoneDetails: React.FC<ShippingZoneDetailsProps> = ({
|
||||||
warehouses={
|
warehouses={
|
||||||
searchWarehousesOpts.data?.search.edges.map(edge => edge.node) || []
|
searchWarehousesOpts.data?.search.edges.map(edge => edge.node) || []
|
||||||
}
|
}
|
||||||
|
hasMore={searchWarehousesOpts.data?.search.pageInfo.hasNextPage}
|
||||||
|
loading={searchWarehousesOpts.loading}
|
||||||
|
onFetchMore={loadMore}
|
||||||
|
onSearchChange={search}
|
||||||
/>
|
/>
|
||||||
<ShippingZoneRateDialog
|
<ShippingZoneRateDialog
|
||||||
action="edit"
|
action="edit"
|
||||||
|
|
|
@ -88,10 +88,12 @@ export interface PageListProps<TColumns extends string = string>
|
||||||
onAdd: () => void;
|
onAdd: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SearchPageProps {
|
export interface SearchProps {
|
||||||
initialSearch: string;
|
|
||||||
onSearchChange: (value: string) => void;
|
onSearchChange: (value: string) => void;
|
||||||
}
|
}
|
||||||
|
export interface SearchPageProps extends SearchProps {
|
||||||
|
initialSearch: string;
|
||||||
|
}
|
||||||
export interface FilterPageProps<TKeys extends string, TOpts extends object>
|
export interface FilterPageProps<TKeys extends string, TOpts extends object>
|
||||||
extends FilterProps<TKeys>,
|
extends FilterProps<TKeys>,
|
||||||
SearchPageProps,
|
SearchPageProps,
|
||||||
|
|
Loading…
Reference in a new issue