Fix strict null checks in warehouses (#2945)
* Fix strict nulls in warehouse details * Fix strict null check in warehouse list * Fix stcit null checks in warehouse create view * Fix overlapping label in textfields * Improve labels in warehouse details * Improve function description
This commit is contained in:
parent
53806abc10
commit
931467a73a
17 changed files with 110 additions and 97 deletions
|
@ -137,10 +137,6 @@
|
||||||
"+xTpT1": {
|
"+xTpT1": {
|
||||||
"string": "Attributes"
|
"string": "Attributes"
|
||||||
},
|
},
|
||||||
"//iaFx": {
|
|
||||||
"context": "WarehouseSettings title",
|
|
||||||
"string": "Settings"
|
|
||||||
},
|
|
||||||
"//k1GX": {
|
"//k1GX": {
|
||||||
"context": "expired on label",
|
"context": "expired on label",
|
||||||
"string": "Expired on {date}"
|
"string": "Expired on {date}"
|
||||||
|
@ -1441,6 +1437,10 @@
|
||||||
"context": "bulk issue menu item",
|
"context": "bulk issue menu item",
|
||||||
"string": "Bulk Issue"
|
"string": "Bulk Issue"
|
||||||
},
|
},
|
||||||
|
"9kzIFd": {
|
||||||
|
"context": "WarehouseSettings stock title",
|
||||||
|
"string": "Stock settings"
|
||||||
|
},
|
||||||
"9mGA/Q": {
|
"9mGA/Q": {
|
||||||
"context": "button linking to dashboard",
|
"context": "button linking to dashboard",
|
||||||
"string": "Dashboard"
|
"string": "Dashboard"
|
||||||
|
|
|
@ -4,10 +4,10 @@ import { createContext, useContext, useMemo } from "react";
|
||||||
import { Pagination } from "../types";
|
import { Pagination } from "../types";
|
||||||
|
|
||||||
export interface PageInfo {
|
export interface PageInfo {
|
||||||
endCursor: string;
|
endCursor: string | null;
|
||||||
hasNextPage: boolean;
|
hasNextPage: boolean;
|
||||||
hasPreviousPage: boolean;
|
hasPreviousPage: boolean;
|
||||||
startCursor: string;
|
startCursor: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PaginationState {
|
export interface PaginationState {
|
||||||
|
@ -37,7 +37,7 @@ export function createPaginationState(
|
||||||
}
|
}
|
||||||
|
|
||||||
interface UsePaginatorArgs {
|
interface UsePaginatorArgs {
|
||||||
pageInfo: PageInfo;
|
pageInfo: PageInfo | undefined;
|
||||||
paginationState: PaginationState;
|
paginationState: PaginationState;
|
||||||
queryString: Pagination;
|
queryString: Pagination;
|
||||||
}
|
}
|
||||||
|
@ -99,12 +99,7 @@ function usePaginator({
|
||||||
|
|
||||||
export default usePaginator;
|
export default usePaginator;
|
||||||
|
|
||||||
export interface PaginatorContextValuesCommon {
|
export type PaginatorContextValuesCommon = Partial<PageInfo>;
|
||||||
hasNextPage?: boolean;
|
|
||||||
hasPreviousPage?: boolean;
|
|
||||||
endCursor?: string | null;
|
|
||||||
startCursor?: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type PaginatorContextValues = PaginatorContextValuesCommon &
|
export type PaginatorContextValues = PaginatorContextValuesCommon &
|
||||||
(
|
(
|
||||||
|
|
|
@ -43,11 +43,11 @@ export type RequireOnlyOne<T, Keys extends keyof T = keyof T> = Pick<
|
||||||
}[Keys];
|
}[Keys];
|
||||||
|
|
||||||
export function renderCollection<T>(
|
export function renderCollection<T>(
|
||||||
collection: T[],
|
collection: T[] | undefined,
|
||||||
renderItem: (
|
renderItem: (
|
||||||
item: T | undefined,
|
item: T | undefined,
|
||||||
index: number | undefined,
|
index: number | undefined,
|
||||||
collection: T[],
|
collection: T[] | undefined,
|
||||||
) => any,
|
) => any,
|
||||||
renderEmpty?: (collection: T[]) => any,
|
renderEmpty?: (collection: T[]) => any,
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { ActiveTab, Pagination, Search, Sort } from "@dashboard/types";
|
||||||
|
|
||||||
import { GetFilterQueryParam, getFilterQueryParams } from "../filters";
|
import { GetFilterQueryParam, getFilterQueryParams } from "../filters";
|
||||||
|
|
||||||
type RequiredParams = ActiveTab & Search & Sort & Pagination;
|
type RequiredParams = ActiveTab & Search & Sort<any> & Pagination;
|
||||||
type CreateUrl = (params: RequiredParams) => string;
|
type CreateUrl = (params: RequiredParams) => string;
|
||||||
type CreateFilterHandlers<TFilterKeys extends string> = [
|
type CreateFilterHandlers<TFilterKeys extends string> = [
|
||||||
(filter: IFilter<TFilterKeys>) => void,
|
(filter: IFilter<TFilterKeys>) => void,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { LimitInfoFragment, RefreshLimitsQuery } from "@dashboard/graphql";
|
import { LimitInfoFragment, RefreshLimitsQuery } from "@dashboard/graphql";
|
||||||
|
|
||||||
export function hasLimits(
|
export function hasLimits(
|
||||||
limits: RefreshLimitsQuery["shop"]["limits"],
|
limits: RefreshLimitsQuery["shop"]["limits"] | undefined,
|
||||||
key: keyof LimitInfoFragment,
|
key: keyof LimitInfoFragment,
|
||||||
): boolean {
|
): boolean {
|
||||||
if (limits === undefined) {
|
if (limits === undefined) {
|
||||||
|
@ -10,14 +10,24 @@ export function hasLimits(
|
||||||
|
|
||||||
return limits.allowedUsage[key] !== null;
|
return limits.allowedUsage[key] !== null;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Returns whether or not limit has been reached.
|
||||||
|
* If limits are undefined, returns false.
|
||||||
|
* */
|
||||||
export function isLimitReached(
|
export function isLimitReached(
|
||||||
limits: RefreshLimitsQuery["shop"]["limits"],
|
limits: RefreshLimitsQuery["shop"]["limits"] | undefined,
|
||||||
key: keyof LimitInfoFragment,
|
key: keyof LimitInfoFragment,
|
||||||
): boolean {
|
): boolean {
|
||||||
if (!hasLimits(limits, key)) {
|
if (!hasLimits(limits, key)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return limits.currentUsage[key] >= limits.allowedUsage[key];
|
const currentUsage = limits?.currentUsage[key];
|
||||||
|
const allowedUsage = limits?.allowedUsage[key];
|
||||||
|
|
||||||
|
if (!currentUsage || !allowedUsage) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return currentUsage >= allowedUsage!;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ interface Edge<T> {
|
||||||
node: T;
|
node: T;
|
||||||
}
|
}
|
||||||
interface Connection<T> {
|
interface Connection<T> {
|
||||||
edges: Array<Edge<T>> | undefined;
|
edges: Array<Edge<T>> | undefined | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mapEdgesToItems<T>(
|
export function mapEdgesToItems<T>(
|
||||||
|
|
|
@ -17,7 +17,7 @@ const props: WarehouseCreatePageProps = {
|
||||||
})),
|
})),
|
||||||
disabled: false,
|
disabled: false,
|
||||||
errors: [],
|
errors: [],
|
||||||
onSubmit: () => undefined,
|
onSubmit: async () => undefined,
|
||||||
saveButtonBarState: "default",
|
saveButtonBarState: "default",
|
||||||
};
|
};
|
||||||
storiesOf("Warehouses / Create warehouse", module)
|
storiesOf("Warehouses / Create warehouse", module)
|
||||||
|
|
|
@ -19,7 +19,7 @@ const props: WarehouseDetailsPageProps = {
|
||||||
disabled: false,
|
disabled: false,
|
||||||
errors: [],
|
errors: [],
|
||||||
onDelete: () => undefined,
|
onDelete: () => undefined,
|
||||||
onSubmit: () => undefined,
|
onSubmit: async () => undefined,
|
||||||
saveButtonBarState: "default",
|
saveButtonBarState: "default",
|
||||||
warehouse,
|
warehouse,
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,7 +9,6 @@ import PageHeader from "@dashboard/components/PageHeader";
|
||||||
import Savebar from "@dashboard/components/Savebar";
|
import Savebar from "@dashboard/components/Savebar";
|
||||||
import { AddressTypeInput } from "@dashboard/customers/types";
|
import { AddressTypeInput } from "@dashboard/customers/types";
|
||||||
import {
|
import {
|
||||||
CountryCode,
|
|
||||||
CountryWithCodeFragment,
|
CountryWithCodeFragment,
|
||||||
WarehouseClickAndCollectOptionEnum,
|
WarehouseClickAndCollectOptionEnum,
|
||||||
WarehouseDetailsFragment,
|
WarehouseDetailsFragment,
|
||||||
|
@ -20,7 +19,6 @@ import { SubmitPromise } from "@dashboard/hooks/useForm";
|
||||||
import useNavigator from "@dashboard/hooks/useNavigator";
|
import useNavigator from "@dashboard/hooks/useNavigator";
|
||||||
import useStateFromProps from "@dashboard/hooks/useStateFromProps";
|
import useStateFromProps from "@dashboard/hooks/useStateFromProps";
|
||||||
import { sectionNames } from "@dashboard/intl";
|
import { sectionNames } from "@dashboard/intl";
|
||||||
import { findValueInEnum, maybe } from "@dashboard/misc";
|
|
||||||
import createSingleAutocompleteSelectHandler from "@dashboard/utils/handlers/singleAutocompleteSelectChangeHandler";
|
import createSingleAutocompleteSelectHandler from "@dashboard/utils/handlers/singleAutocompleteSelectChangeHandler";
|
||||||
import { mapCountriesToChoices, mapEdgesToItems } from "@dashboard/utils/maps";
|
import { mapCountriesToChoices, mapEdgesToItems } from "@dashboard/utils/maps";
|
||||||
import { warehouseListUrl } from "@dashboard/warehouses/urls";
|
import { warehouseListUrl } from "@dashboard/warehouses/urls";
|
||||||
|
@ -41,7 +39,7 @@ export interface WarehouseDetailsPageProps {
|
||||||
disabled: boolean;
|
disabled: boolean;
|
||||||
errors: WarehouseErrorFragment[];
|
errors: WarehouseErrorFragment[];
|
||||||
saveButtonBarState: ConfirmButtonTransitionState;
|
saveButtonBarState: ConfirmButtonTransitionState;
|
||||||
warehouse: WarehouseDetailsFragment;
|
warehouse: WarehouseDetailsFragment | undefined;
|
||||||
onDelete: () => void;
|
onDelete: () => void;
|
||||||
onSubmit: (data: WarehouseDetailsPageFormData) => SubmitPromise;
|
onSubmit: (data: WarehouseDetailsPageFormData) => SubmitPromise;
|
||||||
}
|
}
|
||||||
|
@ -68,21 +66,19 @@ const WarehouseDetailsPage: React.FC<WarehouseDetailsPageProps> = ({
|
||||||
} = useAddressValidation(onSubmit);
|
} = useAddressValidation(onSubmit);
|
||||||
|
|
||||||
const initialForm: WarehouseDetailsPageFormData = {
|
const initialForm: WarehouseDetailsPageFormData = {
|
||||||
city: maybe(() => warehouse.address.city, ""),
|
city: warehouse?.address.city ?? "",
|
||||||
companyName: maybe(() => warehouse.address.companyName, ""),
|
companyName: warehouse?.address.companyName ?? "",
|
||||||
country: maybe(() =>
|
country: warehouse?.address.country.code ?? "",
|
||||||
findValueInEnum(warehouse.address.country.code, CountryCode),
|
|
||||||
),
|
|
||||||
isPrivate: !!warehouse?.isPrivate,
|
isPrivate: !!warehouse?.isPrivate,
|
||||||
clickAndCollectOption:
|
clickAndCollectOption:
|
||||||
warehouse?.clickAndCollectOption ||
|
warehouse?.clickAndCollectOption ||
|
||||||
WarehouseClickAndCollectOptionEnum.DISABLED,
|
WarehouseClickAndCollectOptionEnum.DISABLED,
|
||||||
countryArea: maybe(() => warehouse.address.countryArea, ""),
|
countryArea: warehouse?.address.countryArea ?? "",
|
||||||
name: maybe(() => warehouse.name, ""),
|
name: warehouse?.name ?? "",
|
||||||
phone: maybe(() => warehouse.address.phone, ""),
|
phone: warehouse?.address.phone ?? "",
|
||||||
postalCode: maybe(() => warehouse.address.postalCode, ""),
|
postalCode: warehouse?.address.postalCode ?? "",
|
||||||
streetAddress1: maybe(() => warehouse.address.streetAddress1, ""),
|
streetAddress1: warehouse?.address.streetAddress1 ?? "",
|
||||||
streetAddress2: maybe(() => warehouse.address.streetAddress2, ""),
|
streetAddress2: warehouse?.address.streetAddress2 ?? "",
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -133,7 +129,7 @@ const WarehouseDetailsPage: React.FC<WarehouseDetailsPageProps> = ({
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<WarehouseSettings
|
<WarehouseSettings
|
||||||
zones={mapEdgesToItems(warehouse?.shippingZones)}
|
zones={mapEdgesToItems(warehouse?.shippingZones) ?? []}
|
||||||
data={data}
|
data={data}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
onChange={change}
|
onChange={change}
|
||||||
|
@ -142,7 +138,7 @@ const WarehouseDetailsPage: React.FC<WarehouseDetailsPageProps> = ({
|
||||||
</div>
|
</div>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Savebar
|
<Savebar
|
||||||
disabled={isSaveDisabled}
|
disabled={!!isSaveDisabled}
|
||||||
onCancel={() => navigate(warehouseListUrl())}
|
onCancel={() => navigate(warehouseListUrl())}
|
||||||
onDelete={onDelete}
|
onDelete={onDelete}
|
||||||
onSubmit={submit}
|
onSubmit={submit}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import TableCellHeader from "@dashboard/components/TableCellHeader";
|
||||||
import { TablePaginationWithContext } from "@dashboard/components/TablePagination";
|
import { TablePaginationWithContext } from "@dashboard/components/TablePagination";
|
||||||
import TableRowLink from "@dashboard/components/TableRowLink";
|
import TableRowLink from "@dashboard/components/TableRowLink";
|
||||||
import { WarehouseWithShippingFragment } from "@dashboard/graphql";
|
import { WarehouseWithShippingFragment } from "@dashboard/graphql";
|
||||||
import { maybe, renderCollection, stopPropagation } from "@dashboard/misc";
|
import { renderCollection, stopPropagation } from "@dashboard/misc";
|
||||||
import { ListProps, SortPage } from "@dashboard/types";
|
import { ListProps, SortPage } from "@dashboard/types";
|
||||||
import { mapEdgesToItems } from "@dashboard/utils/maps";
|
import { mapEdgesToItems } from "@dashboard/utils/maps";
|
||||||
import { getArrowDirection } from "@dashboard/utils/sort";
|
import { getArrowDirection } from "@dashboard/utils/sort";
|
||||||
|
@ -64,8 +64,8 @@ const useStyles = makeStyles(
|
||||||
interface WarehouseListProps
|
interface WarehouseListProps
|
||||||
extends ListProps,
|
extends ListProps,
|
||||||
SortPage<WarehouseListUrlSortField> {
|
SortPage<WarehouseListUrlSortField> {
|
||||||
warehouses: WarehouseWithShippingFragment[];
|
warehouses: WarehouseWithShippingFragment[] | undefined;
|
||||||
onRemove: (id: string) => void;
|
onRemove: (id: string | undefined) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const numberOfColumns = 3;
|
const numberOfColumns = 3;
|
||||||
|
@ -90,7 +90,7 @@ const WarehouseList: React.FC<WarehouseListProps> = props => {
|
||||||
<TableCellHeader
|
<TableCellHeader
|
||||||
direction={
|
direction={
|
||||||
sort.sort === WarehouseListUrlSortField.name
|
sort.sort === WarehouseListUrlSortField.name
|
||||||
? getArrowDirection(sort.asc)
|
? getArrowDirection(!!sort.asc)
|
||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
arrowPosition="right"
|
arrowPosition="right"
|
||||||
|
@ -136,7 +136,7 @@ const WarehouseList: React.FC<WarehouseListProps> = props => {
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<TableCell className={classes.colName} data-test-id="name">
|
<TableCell className={classes.colName} data-test-id="name">
|
||||||
{maybe<React.ReactNode>(() => warehouse.name, <Skeleton />)}
|
{warehouse?.name ?? <Skeleton />}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className={classes.colZones} data-test-id="zones">
|
<TableCell className={classes.colZones} data-test-id="zones">
|
||||||
{warehouse?.shippingZones === undefined ? (
|
{warehouse?.shippingZones === undefined ? (
|
||||||
|
@ -160,7 +160,7 @@ const WarehouseList: React.FC<WarehouseListProps> = props => {
|
||||||
<IconButton
|
<IconButton
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={stopPropagation(() => onRemove(warehouse.id))}
|
onClick={stopPropagation(() => onRemove(warehouse?.id))}
|
||||||
>
|
>
|
||||||
<DeleteIcon />
|
<DeleteIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|
|
@ -32,8 +32,8 @@ export interface WarehouseListPageProps
|
||||||
SearchPageProps,
|
SearchPageProps,
|
||||||
SortPage<WarehouseListUrlSortField>,
|
SortPage<WarehouseListUrlSortField>,
|
||||||
TabPageProps {
|
TabPageProps {
|
||||||
limits: RefreshLimitsQuery["shop"]["limits"];
|
limits: RefreshLimitsQuery["shop"]["limits"] | undefined;
|
||||||
warehouses: WarehouseWithShippingFragment[];
|
warehouses: WarehouseWithShippingFragment[] | undefined;
|
||||||
onRemove: (id: string) => void;
|
onRemove: (id: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,18 +66,19 @@ export const WarehouseListPage: React.FC<WarehouseListPageProps> = ({
|
||||||
<PageHeader
|
<PageHeader
|
||||||
title={intl.formatMessage(sectionNames.warehouses)}
|
title={intl.formatMessage(sectionNames.warehouses)}
|
||||||
limitText={
|
limitText={
|
||||||
hasLimits(limits, "warehouses") &&
|
hasLimits(limits, "warehouses")
|
||||||
intl.formatMessage(
|
? intl.formatMessage(
|
||||||
{
|
{
|
||||||
id: "YkOzse",
|
id: "YkOzse",
|
||||||
defaultMessage: "{count}/{max} warehouses used",
|
defaultMessage: "{count}/{max} warehouses used",
|
||||||
description: "used warehouses counter",
|
description: "used warehouses counter",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
count: limits.currentUsage.warehouses,
|
count: limits?.currentUsage.warehouses,
|
||||||
max: limits.allowedUsage.warehouses,
|
max: limits?.allowedUsage.warehouses,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
: undefined
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import CardSpacer from "@dashboard/components/CardSpacer";
|
|
||||||
import CardTitle from "@dashboard/components/CardTitle";
|
import CardTitle from "@dashboard/components/CardTitle";
|
||||||
import { FormSpacer } from "@dashboard/components/FormSpacer";
|
import { FormSpacer } from "@dashboard/components/FormSpacer";
|
||||||
import Link from "@dashboard/components/Link";
|
import Link from "@dashboard/components/Link";
|
||||||
|
@ -9,6 +8,7 @@ import {
|
||||||
WarehouseClickAndCollectOptionEnum,
|
WarehouseClickAndCollectOptionEnum,
|
||||||
WarehouseWithShippingFragment,
|
WarehouseWithShippingFragment,
|
||||||
} from "@dashboard/graphql";
|
} from "@dashboard/graphql";
|
||||||
|
import { sectionNames } from "@dashboard/intl";
|
||||||
import { renderCollection } from "@dashboard/misc";
|
import { renderCollection } from "@dashboard/misc";
|
||||||
import { shippingZoneUrl } from "@dashboard/shipping/urls";
|
import { shippingZoneUrl } from "@dashboard/shipping/urls";
|
||||||
import { RelayToFlat } from "@dashboard/types";
|
import { RelayToFlat } from "@dashboard/types";
|
||||||
|
@ -146,9 +146,7 @@ const WarehouseSettings: React.FC<WarehouseSettingsProps> = ({
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
<CardTitle
|
<CardTitle title={<FormattedMessage {...sectionNames.shippingZones} />} />
|
||||||
title={<FormattedMessage {...messages.warehouseSettingsTitle} />}
|
|
||||||
/>
|
|
||||||
<CardContent>
|
<CardContent>
|
||||||
{renderCollection(
|
{renderCollection(
|
||||||
zones,
|
zones,
|
||||||
|
@ -172,8 +170,10 @@ const WarehouseSettings: React.FC<WarehouseSettingsProps> = ({
|
||||||
)}
|
)}
|
||||||
</CardContent>
|
</CardContent>
|
||||||
<Divider />
|
<Divider />
|
||||||
|
<CardTitle
|
||||||
|
title={<FormattedMessage {...messages.warehouseSettingsStockTitle} />}
|
||||||
|
/>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<CardSpacer />
|
|
||||||
<RadioGroupField
|
<RadioGroupField
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
choices={isPrivateChoices}
|
choices={isPrivateChoices}
|
||||||
|
@ -184,12 +184,15 @@ const WarehouseSettings: React.FC<WarehouseSettingsProps> = ({
|
||||||
/>
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
<Divider />
|
<Divider />
|
||||||
<CardContent>
|
<CardTitle
|
||||||
<Typography color="textSecondary" variant="h6">
|
title={
|
||||||
|
<>
|
||||||
<FormattedMessage {...messages.warehouseSettingsPickupTitle} />
|
<FormattedMessage {...messages.warehouseSettingsPickupTitle} />
|
||||||
<PreviewPill className={classes.preview} />
|
<PreviewPill className={classes.preview} />
|
||||||
</Typography>
|
</>
|
||||||
<CardSpacer />
|
}
|
||||||
|
/>
|
||||||
|
<CardContent>
|
||||||
<RadioGroupField
|
<RadioGroupField
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
choices={
|
choices={
|
||||||
|
|
|
@ -54,10 +54,10 @@ const messages = defineMessages({
|
||||||
"If selected customer will be able to choose this warehouse as pickup point. Ordered products can be shipped here from a different warehouse",
|
"If selected customer will be able to choose this warehouse as pickup point. Ordered products can be shipped here from a different warehouse",
|
||||||
description: "WarehouseSettings all warehouses description",
|
description: "WarehouseSettings all warehouses description",
|
||||||
},
|
},
|
||||||
warehouseSettingsTitle: {
|
warehouseSettingsStockTitle: {
|
||||||
id: "//iaFx",
|
id: "9kzIFd",
|
||||||
defaultMessage: "Settings",
|
defaultMessage: "Stock settings",
|
||||||
description: "WarehouseSettings title",
|
description: "WarehouseSettings stock title",
|
||||||
},
|
},
|
||||||
warehouseSettingsPickupTitle: {
|
warehouseSettingsPickupTitle: {
|
||||||
id: "MIC9W7",
|
id: "MIC9W7",
|
||||||
|
|
|
@ -23,8 +23,11 @@ const WarehouseCreate: React.FC = () => {
|
||||||
const shop = useShop();
|
const shop = useShop();
|
||||||
const [createWarehouse, createWarehouseOpts] = useWarehouseCreateMutation({
|
const [createWarehouse, createWarehouseOpts] = useWarehouseCreateMutation({
|
||||||
onCompleted: data => {
|
onCompleted: data => {
|
||||||
if (data.createWarehouse.errors.length === 0) {
|
if (data?.createWarehouse?.errors.length === 0) {
|
||||||
navigate(warehouseUrl(data.createWarehouse.warehouse.id));
|
const warehouse = data?.createWarehouse?.warehouse;
|
||||||
|
if (warehouse?.id) {
|
||||||
|
navigate(warehouseUrl(warehouse.id));
|
||||||
|
}
|
||||||
notify({
|
notify({
|
||||||
status: "success",
|
status: "success",
|
||||||
text: intl.formatMessage(commonMessages.savedChanges),
|
text: intl.formatMessage(commonMessages.savedChanges),
|
||||||
|
@ -68,7 +71,7 @@ const WarehouseCreate: React.FC = () => {
|
||||||
<WarehouseCreatePage
|
<WarehouseCreatePage
|
||||||
countries={shop?.countries || []}
|
countries={shop?.countries || []}
|
||||||
disabled={createWarehouseOpts.loading}
|
disabled={createWarehouseOpts.loading}
|
||||||
errors={createWarehouseOpts.data?.createWarehouse.errors || []}
|
errors={createWarehouseOpts.data?.createWarehouse?.errors || []}
|
||||||
saveButtonBarState={createWarehouseTransitionState}
|
saveButtonBarState={createWarehouseTransitionState}
|
||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -45,7 +45,7 @@ const WarehouseDetails: React.FC<WarehouseDetailsProps> = ({ id, params }) => {
|
||||||
});
|
});
|
||||||
const [updateWarehouse, updateWarehouseOpts] = useWarehouseUpdateMutation({
|
const [updateWarehouse, updateWarehouseOpts] = useWarehouseUpdateMutation({
|
||||||
onCompleted: data => {
|
onCompleted: data => {
|
||||||
if (data.updateWarehouse.errors.length === 0) {
|
if (data?.updateWarehouse?.errors.length === 0) {
|
||||||
notify({
|
notify({
|
||||||
status: "success",
|
status: "success",
|
||||||
text: intl.formatMessage(commonMessages.savedChanges),
|
text: intl.formatMessage(commonMessages.savedChanges),
|
||||||
|
@ -57,7 +57,7 @@ const WarehouseDetails: React.FC<WarehouseDetailsProps> = ({ id, params }) => {
|
||||||
|
|
||||||
const [deleteWarehouse, deleteWarehouseOpts] = useWarehouseDeleteMutation({
|
const [deleteWarehouse, deleteWarehouseOpts] = useWarehouseDeleteMutation({
|
||||||
onCompleted: data => {
|
onCompleted: data => {
|
||||||
if (data.deleteWarehouse.errors.length === 0) {
|
if (data?.deleteWarehouse?.errors.length === 0) {
|
||||||
notify({
|
notify({
|
||||||
status: "success",
|
status: "success",
|
||||||
text: intl.formatMessage(commonMessages.savedChanges),
|
text: intl.formatMessage(commonMessages.savedChanges),
|
||||||
|
@ -105,11 +105,11 @@ const WarehouseDetails: React.FC<WarehouseDetailsProps> = ({ id, params }) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<WindowTitle title={data?.warehouse?.name} />
|
<WindowTitle title={getStringOrPlaceholder(data?.warehouse?.name)} />
|
||||||
<WarehouseDetailsPage
|
<WarehouseDetailsPage
|
||||||
countries={shop?.countries || []}
|
countries={shop?.countries || []}
|
||||||
disabled={loading || updateWarehouseOpts.loading}
|
disabled={loading || updateWarehouseOpts.loading}
|
||||||
errors={updateWarehouseOpts.data?.updateWarehouse.errors || []}
|
errors={updateWarehouseOpts.data?.updateWarehouse?.errors || []}
|
||||||
saveButtonBarState={updateWarehouseTransitionState}
|
saveButtonBarState={updateWarehouseTransitionState}
|
||||||
warehouse={data?.warehouse}
|
warehouse={data?.warehouse}
|
||||||
onDelete={() => openModal("delete")}
|
onDelete={() => openModal("delete")}
|
||||||
|
|
|
@ -78,7 +78,7 @@ const WarehouseList: React.FC<WarehouseListProps> = ({ params }) => {
|
||||||
});
|
});
|
||||||
const [deleteWarehouse, deleteWarehouseOpts] = useWarehouseDeleteMutation({
|
const [deleteWarehouse, deleteWarehouseOpts] = useWarehouseDeleteMutation({
|
||||||
onCompleted: data => {
|
onCompleted: data => {
|
||||||
if (data.deleteWarehouse.errors.length === 0) {
|
if (data?.deleteWarehouse?.errors.length === 0) {
|
||||||
notify({
|
notify({
|
||||||
status: "success",
|
status: "success",
|
||||||
text: intl.formatMessage(commonMessages.savedChanges),
|
text: intl.formatMessage(commonMessages.savedChanges),
|
||||||
|
@ -96,7 +96,7 @@ const WarehouseList: React.FC<WarehouseListProps> = ({ params }) => {
|
||||||
|
|
||||||
const [, resetFilters, handleSearchChange] = createFilterHandlers({
|
const [, resetFilters, handleSearchChange] = createFilterHandlers({
|
||||||
createUrl: warehouseListUrl,
|
createUrl: warehouseListUrl,
|
||||||
getFilterQueryParam: () => undefined,
|
getFilterQueryParam: async () => undefined,
|
||||||
navigate,
|
navigate,
|
||||||
params,
|
params,
|
||||||
});
|
});
|
||||||
|
@ -125,7 +125,7 @@ const WarehouseList: React.FC<WarehouseListProps> = ({ params }) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const paginationValues = usePaginator({
|
const paginationValues = usePaginator({
|
||||||
pageInfo: maybe(() => data.warehouses.pageInfo),
|
pageInfo: data?.warehouses?.pageInfo,
|
||||||
paginationState,
|
paginationState,
|
||||||
queryString: params,
|
queryString: params,
|
||||||
});
|
});
|
||||||
|
@ -155,19 +155,24 @@ const WarehouseList: React.FC<WarehouseListProps> = ({ params }) => {
|
||||||
onUpdateListSettings={updateListSettings}
|
onUpdateListSettings={updateListSettings}
|
||||||
sort={getSortParams(params)}
|
sort={getSortParams(params)}
|
||||||
/>
|
/>
|
||||||
|
{!!params.id && (
|
||||||
<WarehouseDeleteDialog
|
<WarehouseDeleteDialog
|
||||||
confirmButtonState={deleteTransitionState}
|
confirmButtonState={deleteTransitionState}
|
||||||
name={mapEdgesToItems(data?.warehouses)?.find(getById(params.id))?.name}
|
name={
|
||||||
|
mapEdgesToItems(data?.warehouses)?.find(getById(params.id))?.name ??
|
||||||
|
""
|
||||||
|
}
|
||||||
open={params.action === "delete"}
|
open={params.action === "delete"}
|
||||||
onClose={closeModal}
|
onClose={closeModal}
|
||||||
onConfirm={() =>
|
onConfirm={() =>
|
||||||
deleteWarehouse({
|
deleteWarehouse({
|
||||||
variables: {
|
variables: {
|
||||||
id: params.id,
|
id: params.id!,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
<SaveFilterTabDialog
|
<SaveFilterTabDialog
|
||||||
open={params.action === "save-search"}
|
open={params.action === "save-search"}
|
||||||
confirmButtonState="default"
|
confirmButtonState="default"
|
||||||
|
|
|
@ -9,7 +9,7 @@ export function getSortQueryField(
|
||||||
case WarehouseListUrlSortField.name:
|
case WarehouseListUrlSortField.name:
|
||||||
return WarehouseSortField.NAME;
|
return WarehouseSortField.NAME;
|
||||||
default:
|
default:
|
||||||
return undefined;
|
throw new Error("Invalid sort field");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue