Remove leave screen dialog
This commit is contained in:
parent
4b01781157
commit
bf18651f7d
17 changed files with 103 additions and 382 deletions
|
@ -1593,14 +1593,6 @@
|
||||||
"context": "button",
|
"context": "button",
|
||||||
"string": "{languageName} - {languageCode}"
|
"string": "{languageName} - {languageCode}"
|
||||||
},
|
},
|
||||||
"src_dot_components_dot_LeaveScreenDialog_dot_1295493095": {
|
|
||||||
"context": "leaving screen warning header",
|
|
||||||
"string": "You're leaving this screen"
|
|
||||||
},
|
|
||||||
"src_dot_components_dot_LeaveScreenDialog_dot_4066894204": {
|
|
||||||
"context": "leaving screen warning message",
|
|
||||||
"string": "Do you want to save previously made changes?"
|
|
||||||
},
|
|
||||||
"src_dot_components_dot_ListField_dot_3099331554": {
|
"src_dot_components_dot_ListField_dot_3099331554": {
|
||||||
"context": "button",
|
"context": "button",
|
||||||
"string": "Add"
|
"string": "Add"
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
import useForm, { UseFormResult } from "@saleor/hooks/useForm";
|
import useForm, { UseFormResult } from "@saleor/hooks/useForm";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
import LeaveScreenDialog from "../LeaveScreenDialog";
|
|
||||||
|
|
||||||
export interface FormProps<T> {
|
export interface FormProps<T> {
|
||||||
children: (props: UseFormResult<T>) => React.ReactNode;
|
children: (props: UseFormResult<T>) => React.ReactNode;
|
||||||
confirmLeave?: boolean;
|
confirmLeave?: boolean;
|
||||||
initial?: T;
|
initial?: T;
|
||||||
resetOnSubmit?: boolean;
|
resetOnSubmit?: boolean;
|
||||||
onSubmit?: (data: T, nextAction: () => void) => void;
|
onSubmit?: (data: T) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
function Form<T>(props: FormProps<T>) {
|
function Form<T>(props: FormProps<T>) {
|
||||||
|
@ -34,18 +32,7 @@ function Form<T>(props: FormProps<T>) {
|
||||||
submit();
|
submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return <form onSubmit={handleSubmit}>{children(renderProps)}</form>;
|
||||||
<form onSubmit={handleSubmit}>
|
|
||||||
{children(renderProps)}
|
|
||||||
<LeaveScreenDialog
|
|
||||||
onSaveChanges={renderProps.submit}
|
|
||||||
onRejectChanges={renderProps.leaveAction.current}
|
|
||||||
onClose={() => renderProps.askToLeave(null)}
|
|
||||||
open={!!renderProps.leaveModal}
|
|
||||||
confirmButtonState="default"
|
|
||||||
/>
|
|
||||||
</form>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
Form.displayName = "Form";
|
Form.displayName = "Form";
|
||||||
|
|
||||||
|
|
|
@ -1,56 +0,0 @@
|
||||||
import Button from "@material-ui/core/Button";
|
|
||||||
import Dialog from "@material-ui/core/Dialog";
|
|
||||||
import DialogActions from "@material-ui/core/DialogActions";
|
|
||||||
import DialogContent from "@material-ui/core/DialogContent";
|
|
||||||
import DialogTitle from "@material-ui/core/DialogTitle";
|
|
||||||
import { commonMessages } from "@saleor/intl";
|
|
||||||
import React from "react";
|
|
||||||
import { FormattedMessage } from "react-intl";
|
|
||||||
|
|
||||||
import ConfirmButton, { ConfirmButtonTransitionState } from "../ConfirmButton";
|
|
||||||
|
|
||||||
export interface LeaveScreenDialogProps {
|
|
||||||
confirmButtonState: ConfirmButtonTransitionState;
|
|
||||||
open: boolean;
|
|
||||||
onClose: () => void;
|
|
||||||
onSaveChanges: () => void;
|
|
||||||
onRejectChanges: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const LeaveScreenDialog: React.FC<LeaveScreenDialogProps> = ({
|
|
||||||
confirmButtonState,
|
|
||||||
onClose,
|
|
||||||
onSaveChanges,
|
|
||||||
onRejectChanges,
|
|
||||||
open
|
|
||||||
}) => (
|
|
||||||
<Dialog onClose={onClose} open={open} fullWidth maxWidth="sm">
|
|
||||||
<DialogTitle>
|
|
||||||
<FormattedMessage
|
|
||||||
defaultMessage="You're leaving this screen"
|
|
||||||
description="leaving screen warning header"
|
|
||||||
/>
|
|
||||||
</DialogTitle>
|
|
||||||
<DialogContent>
|
|
||||||
<FormattedMessage
|
|
||||||
defaultMessage="Do you want to save previously made changes?"
|
|
||||||
description="leaving screen warning message"
|
|
||||||
/>
|
|
||||||
</DialogContent>
|
|
||||||
<DialogActions>
|
|
||||||
<Button onClick={onRejectChanges}>
|
|
||||||
<FormattedMessage {...commonMessages.no} />
|
|
||||||
</Button>
|
|
||||||
<ConfirmButton
|
|
||||||
transitionState={confirmButtonState}
|
|
||||||
color="primary"
|
|
||||||
variant="contained"
|
|
||||||
onClick={onSaveChanges}
|
|
||||||
>
|
|
||||||
<FormattedMessage {...commonMessages.yes} />
|
|
||||||
</ConfirmButton>
|
|
||||||
</DialogActions>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
LeaveScreenDialog.displayName = "LeaveScreenDialog";
|
|
||||||
export default LeaveScreenDialog;
|
|
|
@ -1,2 +0,0 @@
|
||||||
export { default } from "./LeaveScreenDialog";
|
|
||||||
export * from "./LeaveScreenDialog";
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { toggle } from "@saleor/utils/lists";
|
import { toggle } from "@saleor/utils/lists";
|
||||||
import isEqual from "lodash-es/isEqual";
|
import isEqual from "lodash-es/isEqual";
|
||||||
import { MutableRefObject, useRef, useState } from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
import useStateFromProps from "./useStateFromProps";
|
import useStateFromProps from "./useStateFromProps";
|
||||||
|
|
||||||
|
@ -14,9 +14,6 @@ export interface ChangeEvent<TData = any> {
|
||||||
export type FormChange = (event: ChangeEvent, cb?: () => void) => void;
|
export type FormChange = (event: ChangeEvent, cb?: () => void) => void;
|
||||||
|
|
||||||
export interface UseFormResult<T> {
|
export interface UseFormResult<T> {
|
||||||
askToLeave: (action: () => void | null) => void;
|
|
||||||
leaveAction: MutableRefObject<() => void | null>;
|
|
||||||
leaveModal: boolean;
|
|
||||||
change: FormChange;
|
change: FormChange;
|
||||||
data: T;
|
data: T;
|
||||||
hasChanged: boolean;
|
hasChanged: boolean;
|
||||||
|
@ -54,15 +51,13 @@ function handleRefresh<T extends FormData>(
|
||||||
|
|
||||||
function useForm<T extends FormData>(
|
function useForm<T extends FormData>(
|
||||||
initial: T,
|
initial: T,
|
||||||
onSubmit: (data: T, nextAction: () => void) => void
|
onSubmit: (data: T) => void
|
||||||
): UseFormResult<T> {
|
): UseFormResult<T> {
|
||||||
const [hasChanged, setChanged] = useState(false);
|
const [hasChanged, setChanged] = useState(false);
|
||||||
const [data, setData] = useStateFromProps(initial, {
|
const [data, setData] = useStateFromProps(initial, {
|
||||||
mergeFunc: merge,
|
mergeFunc: merge,
|
||||||
onRefresh: newData => handleRefresh(data, newData, setChanged)
|
onRefresh: newData => handleRefresh(data, newData, setChanged)
|
||||||
});
|
});
|
||||||
const [leaveModal, setLeaveModal] = useState<boolean>(false);
|
|
||||||
const leaveAction = useRef<() => void>(null);
|
|
||||||
|
|
||||||
function toggleValue(event: ChangeEvent, cb?: () => void) {
|
function toggleValue(event: ChangeEvent, cb?: () => void) {
|
||||||
const { name, value } = event.target;
|
const { name, value } = event.target;
|
||||||
|
@ -112,26 +107,17 @@ function useForm<T extends FormData>(
|
||||||
}
|
}
|
||||||
|
|
||||||
function submit() {
|
function submit() {
|
||||||
onSubmit(data, leaveAction.current);
|
return onSubmit(data);
|
||||||
setLeaveModal(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function triggerChange() {
|
function triggerChange() {
|
||||||
setChanged(true);
|
setChanged(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function askToLeave(action: () => void | null) {
|
|
||||||
setLeaveModal(() => !!action);
|
|
||||||
leaveAction.current = action;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
askToLeave,
|
|
||||||
change,
|
change,
|
||||||
data,
|
data,
|
||||||
hasChanged,
|
hasChanged,
|
||||||
leaveAction,
|
|
||||||
leaveModal,
|
|
||||||
reset,
|
reset,
|
||||||
set,
|
set,
|
||||||
submit,
|
submit,
|
||||||
|
|
|
@ -5,7 +5,6 @@ import { ConfirmButtonTransitionState } from "@saleor/components/ConfirmButton";
|
||||||
import Container from "@saleor/components/Container";
|
import Container from "@saleor/components/Container";
|
||||||
import Form from "@saleor/components/Form";
|
import Form from "@saleor/components/Form";
|
||||||
import Grid from "@saleor/components/Grid";
|
import Grid from "@saleor/components/Grid";
|
||||||
import LeaveScreenDialog from "@saleor/components/LeaveScreenDialog";
|
|
||||||
import Metadata, { MetadataFormData } from "@saleor/components/Metadata";
|
import Metadata, { MetadataFormData } from "@saleor/components/Metadata";
|
||||||
import { MultiAutocompleteChoiceType } from "@saleor/components/MultiAutocompleteSelectField";
|
import { MultiAutocompleteChoiceType } from "@saleor/components/MultiAutocompleteSelectField";
|
||||||
import PageHeader from "@saleor/components/PageHeader";
|
import PageHeader from "@saleor/components/PageHeader";
|
||||||
|
@ -79,8 +78,6 @@ export interface ProductCreatePageSubmitData extends FormData {
|
||||||
stocks: ProductStockInput[];
|
stocks: ProductStockInput[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ProductCreatePageSubmitNextAction = "warehouse-configure";
|
|
||||||
|
|
||||||
interface ProductCreatePageProps {
|
interface ProductCreatePageProps {
|
||||||
errors: ProductErrorFragment[];
|
errors: ProductErrorFragment[];
|
||||||
collections: SearchCollections_search_edges_node[];
|
collections: SearchCollections_search_edges_node[];
|
||||||
|
@ -101,16 +98,12 @@ interface ProductCreatePageProps {
|
||||||
weightUnit: string;
|
weightUnit: string;
|
||||||
warehouses: SearchWarehouses_search_edges_node[];
|
warehouses: SearchWarehouses_search_edges_node[];
|
||||||
taxTypes: TaxTypeFragment[];
|
taxTypes: TaxTypeFragment[];
|
||||||
submitNextAction?: ProductCreatePageSubmitNextAction;
|
|
||||||
fetchCategories: (data: string) => void;
|
fetchCategories: (data: string) => void;
|
||||||
fetchCollections: (data: string) => void;
|
fetchCollections: (data: string) => void;
|
||||||
fetchProductTypes: (data: string) => void;
|
fetchProductTypes: (data: string) => void;
|
||||||
|
onWarehouseConfigure: () => void;
|
||||||
onBack?();
|
onBack?();
|
||||||
onSubmit?(
|
onSubmit?(data: ProductCreatePageSubmitData);
|
||||||
data: ProductCreatePageSubmitData,
|
|
||||||
nextAction?: ProductCreatePageSubmitNextAction
|
|
||||||
);
|
|
||||||
onSubmitSkip?(nextAction?: ProductCreatePageSubmitNextAction);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ProductCreatePage: React.FC<ProductCreatePageProps> = ({
|
export const ProductCreatePage: React.FC<ProductCreatePageProps> = ({
|
||||||
|
@ -133,7 +126,7 @@ export const ProductCreatePage: React.FC<ProductCreatePageProps> = ({
|
||||||
fetchProductTypes,
|
fetchProductTypes,
|
||||||
weightUnit,
|
weightUnit,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
onSubmitSkip
|
onWarehouseConfigure
|
||||||
}: ProductCreatePageProps) => {
|
}: ProductCreatePageProps) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const localizeDate = useDateLocalize();
|
const localizeDate = useDateLocalize();
|
||||||
|
@ -210,21 +203,12 @@ export const ProductCreatePage: React.FC<ProductCreatePageProps> = ({
|
||||||
value: taxType.taxCode
|
value: taxType.taxCode
|
||||||
})) || [];
|
})) || [];
|
||||||
|
|
||||||
const [modalWithAction, setModalWithAction] = React.useState<
|
const handleSubmit = (data: FormData) =>
|
||||||
ProductCreatePageSubmitNextAction
|
onSubmit({
|
||||||
>(null);
|
...data,
|
||||||
|
attributes,
|
||||||
const handleSubmit = (data: FormData) => {
|
stocks
|
||||||
onSubmit(
|
});
|
||||||
{
|
|
||||||
...data,
|
|
||||||
attributes,
|
|
||||||
stocks
|
|
||||||
},
|
|
||||||
modalWithAction
|
|
||||||
);
|
|
||||||
setModalWithAction(null);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form onSubmit={handleSubmit} initial={initialData} confirmLeave>
|
<Form onSubmit={handleSubmit} initial={initialData} confirmLeave>
|
||||||
|
@ -339,13 +323,7 @@ export const ProductCreatePage: React.FC<ProductCreatePageProps> = ({
|
||||||
triggerChange();
|
triggerChange();
|
||||||
removeStock(id);
|
removeStock(id);
|
||||||
}}
|
}}
|
||||||
onWarehouseConfigure={() => {
|
onWarehouseConfigure={onWarehouseConfigure}
|
||||||
if (disabled || !onSubmit || !hasChanged) {
|
|
||||||
onSubmitSkip("warehouse-configure");
|
|
||||||
} else {
|
|
||||||
setModalWithAction("warehouse-configure");
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
<CardSpacer />
|
<CardSpacer />
|
||||||
</>
|
</>
|
||||||
|
@ -434,17 +412,6 @@ export const ProductCreatePage: React.FC<ProductCreatePageProps> = ({
|
||||||
state={saveButtonBarState}
|
state={saveButtonBarState}
|
||||||
disabled={disabled || !onSubmit || !hasChanged}
|
disabled={disabled || !onSubmit || !hasChanged}
|
||||||
/>
|
/>
|
||||||
<LeaveScreenDialog
|
|
||||||
onSaveChanges={() => {
|
|
||||||
submit();
|
|
||||||
}}
|
|
||||||
onRejectChanges={() => {
|
|
||||||
onSubmitSkip("warehouse-configure");
|
|
||||||
}}
|
|
||||||
onClose={() => setModalWithAction(null)}
|
|
||||||
open={modalWithAction === "warehouse-configure"}
|
|
||||||
confirmButtonState={saveButtonBarState}
|
|
||||||
/>
|
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -84,7 +84,7 @@ export interface ProductUpdatePageProps extends ListActions {
|
||||||
onImageReorder?(event: { oldIndex: number; newIndex: number });
|
onImageReorder?(event: { oldIndex: number; newIndex: number });
|
||||||
onImageUpload(file: File);
|
onImageUpload(file: File);
|
||||||
onSeoClick?();
|
onSeoClick?();
|
||||||
onSubmit?(data: ProductUpdatePageSubmitData, nextAction?: () => void);
|
onSubmit?(data: ProductUpdatePageSubmitData);
|
||||||
onVariantAdd?();
|
onVariantAdd?();
|
||||||
onSetDefaultVariant();
|
onSetDefaultVariant();
|
||||||
onWarehouseConfigure();
|
onWarehouseConfigure();
|
||||||
|
@ -193,28 +193,22 @@ export const ProductUpdatePage: React.FC<ProductUpdatePageProps> = ({
|
||||||
value: taxType.taxCode
|
value: taxType.taxCode
|
||||||
})) || [];
|
})) || [];
|
||||||
|
|
||||||
const handleSubmit = (
|
const handleSubmit = (data: ProductUpdatePageFormData) => {
|
||||||
data: ProductUpdatePageFormData,
|
|
||||||
nextAction: () => void
|
|
||||||
) => {
|
|
||||||
const metadata = isMetadataModified ? data.metadata : undefined;
|
const metadata = isMetadataModified ? data.metadata : undefined;
|
||||||
const privateMetadata = isPrivateMetadataModified
|
const privateMetadata = isPrivateMetadataModified
|
||||||
? data.privateMetadata
|
? data.privateMetadata
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
if (product.productType.hasVariants) {
|
if (product.productType.hasVariants) {
|
||||||
onSubmit(
|
onSubmit({
|
||||||
{
|
...data,
|
||||||
...data,
|
addStocks: [],
|
||||||
addStocks: [],
|
attributes,
|
||||||
attributes,
|
metadata,
|
||||||
metadata,
|
privateMetadata,
|
||||||
privateMetadata,
|
removeStocks: [],
|
||||||
removeStocks: [],
|
updateStocks: []
|
||||||
updateStocks: []
|
});
|
||||||
},
|
|
||||||
nextAction
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
const dataStocks = stocks.map(stock => stock.id);
|
const dataStocks = stocks.map(stock => stock.id);
|
||||||
const variantStocks = product.variants[0]?.stocks.map(
|
const variantStocks = product.variants[0]?.stocks.map(
|
||||||
|
@ -222,37 +216,25 @@ export const ProductUpdatePage: React.FC<ProductUpdatePageProps> = ({
|
||||||
);
|
);
|
||||||
const stockDiff = diff(variantStocks, dataStocks);
|
const stockDiff = diff(variantStocks, dataStocks);
|
||||||
|
|
||||||
onSubmit(
|
onSubmit({
|
||||||
{
|
...data,
|
||||||
...data,
|
addStocks: stocks.filter(stock =>
|
||||||
addStocks: stocks.filter(stock =>
|
stockDiff.added.some(addedStock => addedStock === stock.id)
|
||||||
stockDiff.added.some(addedStock => addedStock === stock.id)
|
),
|
||||||
),
|
attributes,
|
||||||
attributes,
|
metadata,
|
||||||
metadata,
|
privateMetadata,
|
||||||
privateMetadata,
|
removeStocks: stockDiff.removed,
|
||||||
removeStocks: stockDiff.removed,
|
updateStocks: stocks.filter(
|
||||||
updateStocks: stocks.filter(
|
stock => !stockDiff.added.some(addedStock => addedStock === stock.id)
|
||||||
stock =>
|
)
|
||||||
!stockDiff.added.some(addedStock => addedStock === stock.id)
|
});
|
||||||
)
|
|
||||||
},
|
|
||||||
nextAction
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form onSubmit={handleSubmit} initial={initialData} confirmLeave>
|
<Form onSubmit={handleSubmit} initial={initialData} confirmLeave>
|
||||||
{({
|
{({ change, data, hasChanged, submit, triggerChange, toggleValue }) => {
|
||||||
change,
|
|
||||||
data,
|
|
||||||
hasChanged,
|
|
||||||
submit,
|
|
||||||
triggerChange,
|
|
||||||
toggleValue,
|
|
||||||
askToLeave
|
|
||||||
}) => {
|
|
||||||
const handleCollectionSelect = createMultiAutocompleteSelectHandler(
|
const handleCollectionSelect = createMultiAutocompleteSelectHandler(
|
||||||
toggleValue,
|
toggleValue,
|
||||||
setSelectedCollections,
|
setSelectedCollections,
|
||||||
|
@ -390,13 +372,7 @@ export const ProductUpdatePage: React.FC<ProductUpdatePageProps> = ({
|
||||||
triggerChange();
|
triggerChange();
|
||||||
removeStock(id);
|
removeStock(id);
|
||||||
}}
|
}}
|
||||||
onWarehouseConfigure={() => {
|
onWarehouseConfigure={onWarehouseConfigure}
|
||||||
if (disabled || !onSubmit || !hasChanged) {
|
|
||||||
onWarehouseConfigure();
|
|
||||||
} else {
|
|
||||||
askToLeave(onWarehouseConfigure);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import { ConfirmButtonTransitionState } from "@saleor/components/ConfirmButton";
|
||||||
import Container from "@saleor/components/Container";
|
import Container from "@saleor/components/Container";
|
||||||
import Form from "@saleor/components/Form";
|
import Form from "@saleor/components/Form";
|
||||||
import Grid from "@saleor/components/Grid";
|
import Grid from "@saleor/components/Grid";
|
||||||
import LeaveScreenDialog from "@saleor/components/LeaveScreenDialog";
|
|
||||||
import Metadata, { MetadataFormData } from "@saleor/components/Metadata";
|
import Metadata, { MetadataFormData } from "@saleor/components/Metadata";
|
||||||
import PageHeader from "@saleor/components/PageHeader";
|
import PageHeader from "@saleor/components/PageHeader";
|
||||||
import SaveButtonBar from "@saleor/components/SaveButtonBar";
|
import SaveButtonBar from "@saleor/components/SaveButtonBar";
|
||||||
|
@ -46,8 +45,6 @@ export interface ProductVariantCreatePageSubmitData
|
||||||
stocks: ProductStockInput[];
|
stocks: ProductStockInput[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ProductVariantCreatePageSubmitNextAction = "warehouse-configure";
|
|
||||||
|
|
||||||
interface ProductVariantCreatePageProps {
|
interface ProductVariantCreatePageProps {
|
||||||
currencySymbol: string;
|
currencySymbol: string;
|
||||||
disabled: boolean;
|
disabled: boolean;
|
||||||
|
@ -58,15 +55,10 @@ interface ProductVariantCreatePageProps {
|
||||||
warehouses: SearchWarehouses_search_edges_node[];
|
warehouses: SearchWarehouses_search_edges_node[];
|
||||||
weightUnit: string;
|
weightUnit: string;
|
||||||
onBack: () => void;
|
onBack: () => void;
|
||||||
onSubmit: (
|
onSubmit: (data: ProductVariantCreatePageSubmitData) => void;
|
||||||
data: ProductVariantCreatePageSubmitData,
|
|
||||||
nextAction?: ProductVariantCreatePageSubmitNextAction
|
|
||||||
) => void;
|
|
||||||
onSubmitSkip?: (
|
|
||||||
nextAction?: ProductVariantCreatePageSubmitNextAction
|
|
||||||
) => void;
|
|
||||||
onVariantClick: (variantId: string) => void;
|
onVariantClick: (variantId: string) => void;
|
||||||
onVariantReorder: ReorderAction;
|
onVariantReorder: ReorderAction;
|
||||||
|
onWarehouseConfigure: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ProductVariantCreatePage: React.FC<ProductVariantCreatePageProps> = ({
|
const ProductVariantCreatePage: React.FC<ProductVariantCreatePageProps> = ({
|
||||||
|
@ -80,9 +72,9 @@ const ProductVariantCreatePage: React.FC<ProductVariantCreatePageProps> = ({
|
||||||
weightUnit,
|
weightUnit,
|
||||||
onBack,
|
onBack,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
onSubmitSkip,
|
|
||||||
onVariantClick,
|
onVariantClick,
|
||||||
onVariantReorder
|
onVariantReorder,
|
||||||
|
onWarehouseConfigure
|
||||||
}) => {
|
}) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const attributeInput = React.useMemo(
|
const attributeInput = React.useMemo(
|
||||||
|
@ -114,21 +106,12 @@ const ProductVariantCreatePage: React.FC<ProductVariantCreatePageProps> = ({
|
||||||
weight: ""
|
weight: ""
|
||||||
};
|
};
|
||||||
|
|
||||||
const [modalWithAction, setModalWithAction] = React.useState<
|
const handleSubmit = (data: ProductVariantCreatePageFormData) =>
|
||||||
ProductVariantCreatePageSubmitNextAction
|
onSubmit({
|
||||||
>(null);
|
...data,
|
||||||
|
attributes,
|
||||||
const handleSubmit = (data: ProductVariantCreatePageFormData) => {
|
stocks
|
||||||
onSubmit(
|
});
|
||||||
{
|
|
||||||
...data,
|
|
||||||
attributes,
|
|
||||||
stocks
|
|
||||||
},
|
|
||||||
modalWithAction
|
|
||||||
);
|
|
||||||
setModalWithAction(null);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form initial={initialForm} onSubmit={handleSubmit}>
|
<Form initial={initialForm} onSubmit={handleSubmit}>
|
||||||
|
@ -207,13 +190,7 @@ const ProductVariantCreatePage: React.FC<ProductVariantCreatePageProps> = ({
|
||||||
triggerChange();
|
triggerChange();
|
||||||
removeStock(id);
|
removeStock(id);
|
||||||
}}
|
}}
|
||||||
onWarehouseConfigure={() => {
|
onWarehouseConfigure={onWarehouseConfigure}
|
||||||
if (disabled || !onSubmit || !hasChanged) {
|
|
||||||
onSubmitSkip("warehouse-configure");
|
|
||||||
} else {
|
|
||||||
setModalWithAction("warehouse-configure");
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
<CardSpacer />
|
<CardSpacer />
|
||||||
<Metadata data={data} onChange={changeMetadata} />
|
<Metadata data={data} onChange={changeMetadata} />
|
||||||
|
@ -235,17 +212,6 @@ const ProductVariantCreatePage: React.FC<ProductVariantCreatePageProps> = ({
|
||||||
onCancel={onBack}
|
onCancel={onBack}
|
||||||
onSave={submit}
|
onSave={submit}
|
||||||
/>
|
/>
|
||||||
<LeaveScreenDialog
|
|
||||||
onSaveChanges={() => {
|
|
||||||
submit();
|
|
||||||
}}
|
|
||||||
onRejectChanges={() => {
|
|
||||||
onSubmitSkip("warehouse-configure");
|
|
||||||
}}
|
|
||||||
onClose={() => setModalWithAction(null)}
|
|
||||||
open={modalWithAction === "warehouse-configure"}
|
|
||||||
confirmButtonState={saveButtonBarState}
|
|
||||||
/>
|
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import { ConfirmButtonTransitionState } from "@saleor/components/ConfirmButton";
|
||||||
import Container from "@saleor/components/Container";
|
import Container from "@saleor/components/Container";
|
||||||
import Form from "@saleor/components/Form";
|
import Form from "@saleor/components/Form";
|
||||||
import Grid from "@saleor/components/Grid";
|
import Grid from "@saleor/components/Grid";
|
||||||
import LeaveScreenDialog from "@saleor/components/LeaveScreenDialog";
|
|
||||||
import { MetadataFormData } from "@saleor/components/Metadata";
|
import { MetadataFormData } from "@saleor/components/Metadata";
|
||||||
import Metadata from "@saleor/components/Metadata/Metadata";
|
import Metadata from "@saleor/components/Metadata/Metadata";
|
||||||
import PageHeader from "@saleor/components/PageHeader";
|
import PageHeader from "@saleor/components/PageHeader";
|
||||||
|
@ -54,8 +53,6 @@ export interface ProductVariantPageSubmitData
|
||||||
removeStocks: string[];
|
removeStocks: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ProductVariantPageSubmitNextAction = "warehouse-configure";
|
|
||||||
|
|
||||||
interface ProductVariantPageProps {
|
interface ProductVariantPageProps {
|
||||||
defaultWeightUnit: string;
|
defaultWeightUnit: string;
|
||||||
variant?: ProductVariant;
|
variant?: ProductVariant;
|
||||||
|
@ -69,14 +66,11 @@ interface ProductVariantPageProps {
|
||||||
onAdd();
|
onAdd();
|
||||||
onBack();
|
onBack();
|
||||||
onDelete();
|
onDelete();
|
||||||
onSubmit(
|
onSubmit(data: ProductVariantPageSubmitData);
|
||||||
data: ProductVariantPageSubmitData,
|
|
||||||
nextAction?: ProductVariantPageSubmitNextAction
|
|
||||||
);
|
|
||||||
onSubmitSkip?(nextAction?: ProductVariantPageSubmitNextAction);
|
|
||||||
onImageSelect(id: string);
|
onImageSelect(id: string);
|
||||||
onVariantClick(variantId: string);
|
onVariantClick(variantId: string);
|
||||||
onSetDefaultVariant();
|
onSetDefaultVariant();
|
||||||
|
onWarehouseConfigure();
|
||||||
}
|
}
|
||||||
|
|
||||||
const ProductVariantPage: React.FC<ProductVariantPageProps> = ({
|
const ProductVariantPage: React.FC<ProductVariantPageProps> = ({
|
||||||
|
@ -93,10 +87,10 @@ const ProductVariantPage: React.FC<ProductVariantPageProps> = ({
|
||||||
onDelete,
|
onDelete,
|
||||||
onImageSelect,
|
onImageSelect,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
onSubmitSkip,
|
|
||||||
onVariantClick,
|
onVariantClick,
|
||||||
onVariantReorder,
|
onVariantReorder,
|
||||||
onSetDefaultVariant
|
onSetDefaultVariant,
|
||||||
|
onWarehouseConfigure
|
||||||
}) => {
|
}) => {
|
||||||
const attributeInput = React.useMemo(
|
const attributeInput = React.useMemo(
|
||||||
() => getAttributeInputFromVariant(variant),
|
() => getAttributeInputFromVariant(variant),
|
||||||
|
@ -146,10 +140,6 @@ const ProductVariantPage: React.FC<ProductVariantPageProps> = ({
|
||||||
weight: variant?.weight?.value.toString() || ""
|
weight: variant?.weight?.value.toString() || ""
|
||||||
};
|
};
|
||||||
|
|
||||||
const [modalWithAction, setModalWithAction] = React.useState<
|
|
||||||
ProductVariantPageSubmitNextAction
|
|
||||||
>(null);
|
|
||||||
|
|
||||||
const handleSubmit = (data: ProductVariantPageFormData) => {
|
const handleSubmit = (data: ProductVariantPageFormData) => {
|
||||||
const dataStocks = stocks.map(stock => stock.id);
|
const dataStocks = stocks.map(stock => stock.id);
|
||||||
const variantStocks = variant.stocks.map(stock => stock.warehouse.id);
|
const variantStocks = variant.stocks.map(stock => stock.warehouse.id);
|
||||||
|
@ -159,23 +149,19 @@ const ProductVariantPage: React.FC<ProductVariantPageProps> = ({
|
||||||
? data.privateMetadata
|
? data.privateMetadata
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
onSubmit(
|
onSubmit({
|
||||||
{
|
...data,
|
||||||
...data,
|
addStocks: stocks.filter(stock =>
|
||||||
addStocks: stocks.filter(stock =>
|
stockDiff.added.some(addedStock => addedStock === stock.id)
|
||||||
stockDiff.added.some(addedStock => addedStock === stock.id)
|
),
|
||||||
),
|
attributes,
|
||||||
attributes,
|
metadata,
|
||||||
metadata,
|
privateMetadata,
|
||||||
privateMetadata,
|
removeStocks: stockDiff.removed,
|
||||||
removeStocks: stockDiff.removed,
|
updateStocks: stocks.filter(
|
||||||
updateStocks: stocks.filter(
|
stock => !stockDiff.added.some(addedStock => addedStock === stock.id)
|
||||||
stock => !stockDiff.added.some(addedStock => addedStock === stock.id)
|
)
|
||||||
)
|
});
|
||||||
},
|
|
||||||
modalWithAction
|
|
||||||
);
|
|
||||||
setModalWithAction(null);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -280,13 +266,7 @@ const ProductVariantPage: React.FC<ProductVariantPageProps> = ({
|
||||||
triggerChange();
|
triggerChange();
|
||||||
removeStock(id);
|
removeStock(id);
|
||||||
}}
|
}}
|
||||||
onWarehouseConfigure={() => {
|
onWarehouseConfigure={onWarehouseConfigure}
|
||||||
if (!onSubmit || !hasChanged) {
|
|
||||||
onSubmitSkip("warehouse-configure");
|
|
||||||
} else {
|
|
||||||
setModalWithAction("warehouse-configure");
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
<CardSpacer />
|
<CardSpacer />
|
||||||
<Metadata data={data} onChange={changeMetadata} />
|
<Metadata data={data} onChange={changeMetadata} />
|
||||||
|
@ -299,17 +279,6 @@ const ProductVariantPage: React.FC<ProductVariantPageProps> = ({
|
||||||
onDelete={onDelete}
|
onDelete={onDelete}
|
||||||
onSave={submit}
|
onSave={submit}
|
||||||
/>
|
/>
|
||||||
<LeaveScreenDialog
|
|
||||||
onSaveChanges={() => {
|
|
||||||
submit();
|
|
||||||
}}
|
|
||||||
onRejectChanges={() => {
|
|
||||||
onSubmitSkip("warehouse-configure");
|
|
||||||
}}
|
|
||||||
onClose={() => setModalWithAction(null)}
|
|
||||||
open={modalWithAction === "warehouse-configure"}
|
|
||||||
confirmButtonState={saveButtonBarState}
|
|
||||||
/>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -20,8 +20,7 @@ import { useIntl } from "react-intl";
|
||||||
|
|
||||||
import { decimal, weight } from "../../misc";
|
import { decimal, weight } from "../../misc";
|
||||||
import ProductCreatePage, {
|
import ProductCreatePage, {
|
||||||
ProductCreatePageSubmitData,
|
ProductCreatePageSubmitData
|
||||||
ProductCreatePageSubmitNextAction
|
|
||||||
} from "../components/ProductCreatePage";
|
} from "../components/ProductCreatePage";
|
||||||
import {
|
import {
|
||||||
useProductCreateMutation,
|
useProductCreateMutation,
|
||||||
|
@ -73,7 +72,7 @@ export const ProductCreateView: React.FC = () => {
|
||||||
] = useProductSetAvailabilityForPurchase({
|
] = useProductSetAvailabilityForPurchase({
|
||||||
onCompleted: data => {
|
onCompleted: data => {
|
||||||
const errors = data?.productSetAvailabilityForPurchase?.errors;
|
const errors = data?.productSetAvailabilityForPurchase?.errors;
|
||||||
if (errors?.length === 0 && !submitNextAction) {
|
if (errors?.length === 0) {
|
||||||
navigate(productUrl(data.productSetAvailabilityForPurchase.product.id));
|
navigate(productUrl(data.productSetAvailabilityForPurchase.product.id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,12 +91,7 @@ export const ProductCreateView: React.FC = () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleCreate = async (
|
const handleCreate = async (formData: ProductCreatePageSubmitData) => {
|
||||||
formData: ProductCreatePageSubmitData,
|
|
||||||
nextAction?: ProductCreatePageSubmitNextAction
|
|
||||||
) => {
|
|
||||||
setSubmitNextAction(nextAction);
|
|
||||||
|
|
||||||
const result = await productCreate({
|
const result = await productCreate({
|
||||||
variables: {
|
variables: {
|
||||||
input: {
|
input: {
|
||||||
|
@ -157,18 +151,6 @@ export const ProductCreateView: React.FC = () => {
|
||||||
updatePrivateMetadata
|
updatePrivateMetadata
|
||||||
);
|
);
|
||||||
|
|
||||||
const [submitNextAction, setSubmitNextAction] = React.useState<
|
|
||||||
ProductCreatePageSubmitNextAction
|
|
||||||
>(null);
|
|
||||||
const handleSubmitNextAction = (
|
|
||||||
nextAction?: ProductCreatePageSubmitNextAction
|
|
||||||
) => {
|
|
||||||
const action = nextAction || submitNextAction;
|
|
||||||
if (action === "warehouse-configure") {
|
|
||||||
navigate(warehouseListPath);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<WindowTitle
|
<WindowTitle
|
||||||
|
@ -198,15 +180,8 @@ export const ProductCreateView: React.FC = () => {
|
||||||
edge => edge.node
|
edge => edge.node
|
||||||
)}
|
)}
|
||||||
onBack={handleBack}
|
onBack={handleBack}
|
||||||
onSubmit={async (data, nextAction) => {
|
onSubmit={handleSubmit}
|
||||||
const errors = await handleSubmit(data, nextAction);
|
onWarehouseConfigure={() => navigate(warehouseListPath)}
|
||||||
if (errors?.length === 0) {
|
|
||||||
handleSubmitNextAction(nextAction);
|
|
||||||
} else {
|
|
||||||
setSubmitNextAction(null);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
onSubmitSkip={handleSubmitNextAction}
|
|
||||||
saveButtonBarState={productCreateOpts.status}
|
saveButtonBarState={productCreateOpts.status}
|
||||||
fetchMoreCategories={{
|
fetchMoreCategories={{
|
||||||
hasMore: searchCategoryOpts.data?.search.pageInfo.hasNextPage,
|
hasMore: searchCategoryOpts.data?.search.pageInfo.hasNextPage,
|
||||||
|
|
|
@ -304,12 +304,7 @@ export const ProductUpdate: React.FC<ProductUpdateProps> = ({ id, params }) => {
|
||||||
onBack={handleBack}
|
onBack={handleBack}
|
||||||
onDelete={() => openModal("remove")}
|
onDelete={() => openModal("remove")}
|
||||||
onImageReorder={handleImageReorder}
|
onImageReorder={handleImageReorder}
|
||||||
onSubmit={async (data, nextAction) => {
|
onSubmit={handleSubmit}
|
||||||
const errors = await handleSubmit(data);
|
|
||||||
if (errors?.length === 0 && nextAction) {
|
|
||||||
nextAction();
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
onWarehouseConfigure={() => navigate(warehouseListPath)}
|
onWarehouseConfigure={() => navigate(warehouseListPath)}
|
||||||
onVariantAdd={handleVariantAdd}
|
onVariantAdd={handleVariantAdd}
|
||||||
onVariantsAdd={() => navigate(productVariantCreatorUrl(id))}
|
onVariantsAdd={() => navigate(productVariantCreatorUrl(id))}
|
||||||
|
|
|
@ -20,8 +20,7 @@ import { useIntl } from "react-intl";
|
||||||
import { decimal, weight } from "../../misc";
|
import { decimal, weight } from "../../misc";
|
||||||
import ProductVariantDeleteDialog from "../components/ProductVariantDeleteDialog";
|
import ProductVariantDeleteDialog from "../components/ProductVariantDeleteDialog";
|
||||||
import ProductVariantPage, {
|
import ProductVariantPage, {
|
||||||
ProductVariantPageSubmitData,
|
ProductVariantPageSubmitData
|
||||||
ProductVariantPageSubmitNextAction
|
|
||||||
} from "../components/ProductVariantPage";
|
} from "../components/ProductVariantPage";
|
||||||
import {
|
import {
|
||||||
useProductVariantReorderMutation,
|
useProductVariantReorderMutation,
|
||||||
|
@ -198,14 +197,6 @@ export const ProductVariant: React.FC<ProductUpdateProps> = ({
|
||||||
variables => updatePrivateMetadata({ variables })
|
variables => updatePrivateMetadata({ variables })
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleSubmitNextAction = (
|
|
||||||
nextAction?: ProductVariantPageSubmitNextAction
|
|
||||||
) => {
|
|
||||||
if (nextAction === "warehouse-configure") {
|
|
||||||
navigate(warehouseListPath);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<WindowTitle title={data?.productVariant?.name} />
|
<WindowTitle title={data?.productVariant?.name} />
|
||||||
|
@ -225,13 +216,8 @@ export const ProductVariant: React.FC<ProductUpdateProps> = ({
|
||||||
onBack={handleBack}
|
onBack={handleBack}
|
||||||
onDelete={() => openModal("remove")}
|
onDelete={() => openModal("remove")}
|
||||||
onImageSelect={handleImageSelect}
|
onImageSelect={handleImageSelect}
|
||||||
onSubmit={async (data, nextAction) => {
|
onSubmit={handleSubmit}
|
||||||
const errors = await handleSubmit(data);
|
onWarehouseConfigure={() => navigate(warehouseListPath)}
|
||||||
if (errors?.length === 0) {
|
|
||||||
handleSubmitNextAction(nextAction);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
onSubmitSkip={handleSubmitNextAction}
|
|
||||||
onVariantClick={variantId => {
|
onVariantClick={variantId => {
|
||||||
navigate(productVariantEditUrl(productId, variantId));
|
navigate(productVariantEditUrl(productId, variantId));
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -16,8 +16,7 @@ import { useIntl } from "react-intl";
|
||||||
|
|
||||||
import { decimal, weight } from "../../misc";
|
import { decimal, weight } from "../../misc";
|
||||||
import ProductVariantCreatePage, {
|
import ProductVariantCreatePage, {
|
||||||
ProductVariantCreatePageSubmitData,
|
ProductVariantCreatePageSubmitData
|
||||||
ProductVariantCreatePageSubmitNextAction
|
|
||||||
} from "../components/ProductVariantCreatePage";
|
} from "../components/ProductVariantCreatePage";
|
||||||
import {
|
import {
|
||||||
useProductVariantReorderMutation,
|
useProductVariantReorderMutation,
|
||||||
|
@ -57,14 +56,12 @@ export const ProductVariant: React.FC<ProductVariantCreateProps> = ({
|
||||||
status: "success",
|
status: "success",
|
||||||
text: intl.formatMessage(commonMessages.savedChanges)
|
text: intl.formatMessage(commonMessages.savedChanges)
|
||||||
});
|
});
|
||||||
if (!submitNextAction) {
|
navigate(
|
||||||
navigate(
|
productVariantEditUrl(
|
||||||
productVariantEditUrl(
|
productId,
|
||||||
productId,
|
data.productVariantCreate.productVariant.id
|
||||||
data.productVariantCreate.productVariant.id
|
)
|
||||||
)
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -87,12 +84,7 @@ export const ProductVariant: React.FC<ProductVariantCreateProps> = ({
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleBack = () => navigate(productUrl(productId));
|
const handleBack = () => navigate(productUrl(productId));
|
||||||
const handleCreate = async (
|
const handleCreate = async (formData: ProductVariantCreatePageSubmitData) => {
|
||||||
formData: ProductVariantCreatePageSubmitData,
|
|
||||||
nextAction?: ProductVariantCreatePageSubmitNextAction
|
|
||||||
) => {
|
|
||||||
setSubmitNextAction(nextAction);
|
|
||||||
|
|
||||||
const result = await variantCreate({
|
const result = await variantCreate({
|
||||||
variables: {
|
variables: {
|
||||||
input: {
|
input: {
|
||||||
|
@ -126,18 +118,6 @@ export const ProductVariant: React.FC<ProductVariantCreateProps> = ({
|
||||||
const handleVariantClick = (id: string) =>
|
const handleVariantClick = (id: string) =>
|
||||||
navigate(productVariantEditUrl(productId, id));
|
navigate(productVariantEditUrl(productId, id));
|
||||||
|
|
||||||
const [submitNextAction, setSubmitNextAction] = React.useState<
|
|
||||||
ProductVariantCreatePageSubmitNextAction
|
|
||||||
>(null);
|
|
||||||
const handleSubmitNextAction = (
|
|
||||||
nextAction?: ProductVariantCreatePageSubmitNextAction
|
|
||||||
) => {
|
|
||||||
const action = nextAction || submitNextAction;
|
|
||||||
if (action === "warehouse-configure") {
|
|
||||||
navigate(warehouseListPath);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const disableForm =
|
const disableForm =
|
||||||
productLoading ||
|
productLoading ||
|
||||||
variantCreateResult.loading ||
|
variantCreateResult.loading ||
|
||||||
|
@ -161,16 +141,9 @@ export const ProductVariant: React.FC<ProductVariantCreateProps> = ({
|
||||||
})}
|
})}
|
||||||
product={data?.product}
|
product={data?.product}
|
||||||
onBack={handleBack}
|
onBack={handleBack}
|
||||||
onSubmit={async (data, nextAction) => {
|
onSubmit={handleSubmit}
|
||||||
const errors = await handleSubmit(data, nextAction);
|
|
||||||
if (errors?.length === 0) {
|
|
||||||
handleSubmitNextAction(nextAction);
|
|
||||||
} else {
|
|
||||||
setSubmitNextAction(null);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
onSubmitSkip={handleSubmitNextAction}
|
|
||||||
onVariantClick={handleVariantClick}
|
onVariantClick={handleVariantClick}
|
||||||
|
onWarehouseConfigure={() => navigate(warehouseListPath)}
|
||||||
onVariantReorder={handleVariantReorder}
|
onVariantReorder={handleVariantReorder}
|
||||||
saveButtonBarState={variantCreateResult.status}
|
saveButtonBarState={variantCreateResult.status}
|
||||||
warehouses={
|
warehouses={
|
||||||
|
|
|
@ -35,6 +35,7 @@ storiesOf("Views / Products / Create product", module)
|
||||||
onSubmit={() => undefined}
|
onSubmit={() => undefined}
|
||||||
saveButtonBarState="default"
|
saveButtonBarState="default"
|
||||||
warehouses={warehouseList}
|
warehouses={warehouseList}
|
||||||
|
onWarehouseConfigure={() => undefined}
|
||||||
taxTypes={taxTypes}
|
taxTypes={taxTypes}
|
||||||
weightUnit="kg"
|
weightUnit="kg"
|
||||||
/>
|
/>
|
||||||
|
@ -58,6 +59,7 @@ storiesOf("Views / Products / Create product", module)
|
||||||
onSubmit={() => undefined}
|
onSubmit={() => undefined}
|
||||||
saveButtonBarState="default"
|
saveButtonBarState="default"
|
||||||
warehouses={undefined}
|
warehouses={undefined}
|
||||||
|
onWarehouseConfigure={() => undefined}
|
||||||
taxTypes={taxTypes}
|
taxTypes={taxTypes}
|
||||||
weightUnit="kg"
|
weightUnit="kg"
|
||||||
/>
|
/>
|
||||||
|
@ -87,6 +89,7 @@ storiesOf("Views / Products / Create product", module)
|
||||||
onSubmit={() => undefined}
|
onSubmit={() => undefined}
|
||||||
saveButtonBarState="default"
|
saveButtonBarState="default"
|
||||||
warehouses={warehouseList}
|
warehouses={warehouseList}
|
||||||
|
onWarehouseConfigure={() => undefined}
|
||||||
taxTypes={taxTypes}
|
taxTypes={taxTypes}
|
||||||
weightUnit="kg"
|
weightUnit="kg"
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -26,6 +26,7 @@ storiesOf("Views / Products / Create product variant", module)
|
||||||
onVariantReorder={() => undefined}
|
onVariantReorder={() => undefined}
|
||||||
saveButtonBarState="default"
|
saveButtonBarState="default"
|
||||||
warehouses={warehouseList}
|
warehouses={warehouseList}
|
||||||
|
onWarehouseConfigure={() => undefined}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.add("with errors", () => (
|
.add("with errors", () => (
|
||||||
|
@ -58,6 +59,7 @@ storiesOf("Views / Products / Create product variant", module)
|
||||||
onVariantReorder={() => undefined}
|
onVariantReorder={() => undefined}
|
||||||
saveButtonBarState="default"
|
saveButtonBarState="default"
|
||||||
warehouses={warehouseList}
|
warehouses={warehouseList}
|
||||||
|
onWarehouseConfigure={() => undefined}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.add("when loading data", () => (
|
.add("when loading data", () => (
|
||||||
|
@ -74,6 +76,7 @@ storiesOf("Views / Products / Create product variant", module)
|
||||||
onVariantReorder={() => undefined}
|
onVariantReorder={() => undefined}
|
||||||
saveButtonBarState="default"
|
saveButtonBarState="default"
|
||||||
warehouses={warehouseList}
|
warehouses={warehouseList}
|
||||||
|
onWarehouseConfigure={() => undefined}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.add("add first variant", () => (
|
.add("add first variant", () => (
|
||||||
|
@ -93,5 +96,6 @@ storiesOf("Views / Products / Create product variant", module)
|
||||||
onVariantReorder={() => undefined}
|
onVariantReorder={() => undefined}
|
||||||
saveButtonBarState="default"
|
saveButtonBarState="default"
|
||||||
warehouses={warehouseList}
|
warehouses={warehouseList}
|
||||||
|
onWarehouseConfigure={() => undefined}
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
|
|
@ -28,6 +28,7 @@ storiesOf("Views / Products / Product variant details", module)
|
||||||
onVariantReorder={() => undefined}
|
onVariantReorder={() => undefined}
|
||||||
saveButtonBarState="default"
|
saveButtonBarState="default"
|
||||||
warehouses={warehouseList}
|
warehouses={warehouseList}
|
||||||
|
onWarehouseConfigure={() => undefined}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.add("when loading data", () => (
|
.add("when loading data", () => (
|
||||||
|
@ -47,6 +48,7 @@ storiesOf("Views / Products / Product variant details", module)
|
||||||
onVariantReorder={() => undefined}
|
onVariantReorder={() => undefined}
|
||||||
saveButtonBarState="default"
|
saveButtonBarState="default"
|
||||||
warehouses={warehouseList}
|
warehouses={warehouseList}
|
||||||
|
onWarehouseConfigure={() => undefined}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
.add("attribute errors", () => (
|
.add("attribute errors", () => (
|
||||||
|
@ -82,5 +84,6 @@ storiesOf("Views / Products / Product variant details", module)
|
||||||
...error
|
...error
|
||||||
}))}
|
}))}
|
||||||
warehouses={warehouseList}
|
warehouses={warehouseList}
|
||||||
|
onWarehouseConfigure={() => undefined}
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
|
|
@ -10,19 +10,16 @@ import {
|
||||||
UpdatePrivateMetadataVariables
|
UpdatePrivateMetadataVariables
|
||||||
} from "../metadata/types/UpdatePrivateMetadata";
|
} from "../metadata/types/UpdatePrivateMetadata";
|
||||||
|
|
||||||
function createMetadataCreateHandler<
|
function createMetadataCreateHandler<T extends MetadataFormData>(
|
||||||
T extends MetadataFormData,
|
create: (data: T) => Promise<string>,
|
||||||
N extends string
|
|
||||||
>(
|
|
||||||
create: (data: T, nextAction?: N) => Promise<string>,
|
|
||||||
setMetadata: MutationFunction<UpdateMetadata, UpdateMetadataVariables>,
|
setMetadata: MutationFunction<UpdateMetadata, UpdateMetadataVariables>,
|
||||||
setPrivateMetadata: MutationFunction<
|
setPrivateMetadata: MutationFunction<
|
||||||
UpdatePrivateMetadata,
|
UpdatePrivateMetadata,
|
||||||
UpdatePrivateMetadataVariables
|
UpdatePrivateMetadataVariables
|
||||||
>
|
>
|
||||||
) {
|
) {
|
||||||
return async (data: T, nextAction?: N) => {
|
return async (data: T) => {
|
||||||
const id = await create(data, nextAction);
|
const id = await create(data);
|
||||||
|
|
||||||
if (id === null) {
|
if (id === null) {
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in a new issue