diff --git a/locale/defaultMessages.json b/locale/defaultMessages.json index e8ee128be..34a2ebe2f 100644 --- a/locale/defaultMessages.json +++ b/locale/defaultMessages.json @@ -1593,14 +1593,6 @@ "context": "button", "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": { "context": "button", "string": "Add" diff --git a/src/components/Form/Form.tsx b/src/components/Form/Form.tsx index 58802b200..2721f678a 100644 --- a/src/components/Form/Form.tsx +++ b/src/components/Form/Form.tsx @@ -1,14 +1,12 @@ import useForm, { UseFormResult } from "@saleor/hooks/useForm"; import React from "react"; -import LeaveScreenDialog from "../LeaveScreenDialog"; - export interface FormProps { children: (props: UseFormResult) => React.ReactNode; confirmLeave?: boolean; initial?: T; resetOnSubmit?: boolean; - onSubmit?: (data: T, nextAction: () => void) => void; + onSubmit?: (data: T) => void; } function Form(props: FormProps) { @@ -34,18 +32,7 @@ function Form(props: FormProps) { submit(); } - return ( -
- {children(renderProps)} - renderProps.askToLeave(null)} - open={!!renderProps.leaveModal} - confirmButtonState="default" - /> - - ); + return
{children(renderProps)}
; } Form.displayName = "Form"; diff --git a/src/components/LeaveScreenDialog/LeaveScreenDialog.tsx b/src/components/LeaveScreenDialog/LeaveScreenDialog.tsx deleted file mode 100644 index 5b9803442..000000000 --- a/src/components/LeaveScreenDialog/LeaveScreenDialog.tsx +++ /dev/null @@ -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 = ({ - confirmButtonState, - onClose, - onSaveChanges, - onRejectChanges, - open -}) => ( - - - - - - - - - - - - - - -); -LeaveScreenDialog.displayName = "LeaveScreenDialog"; -export default LeaveScreenDialog; diff --git a/src/components/LeaveScreenDialog/index.ts b/src/components/LeaveScreenDialog/index.ts deleted file mode 100644 index c6bfa632e..000000000 --- a/src/components/LeaveScreenDialog/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default } from "./LeaveScreenDialog"; -export * from "./LeaveScreenDialog"; diff --git a/src/hooks/useForm.ts b/src/hooks/useForm.ts index 9b18c77da..752030949 100644 --- a/src/hooks/useForm.ts +++ b/src/hooks/useForm.ts @@ -1,6 +1,6 @@ import { toggle } from "@saleor/utils/lists"; import isEqual from "lodash-es/isEqual"; -import { MutableRefObject, useRef, useState } from "react"; +import { useState } from "react"; import useStateFromProps from "./useStateFromProps"; @@ -14,9 +14,6 @@ export interface ChangeEvent { export type FormChange = (event: ChangeEvent, cb?: () => void) => void; export interface UseFormResult { - askToLeave: (action: () => void | null) => void; - leaveAction: MutableRefObject<() => void | null>; - leaveModal: boolean; change: FormChange; data: T; hasChanged: boolean; @@ -54,15 +51,13 @@ function handleRefresh( function useForm( initial: T, - onSubmit: (data: T, nextAction: () => void) => void + onSubmit: (data: T) => void ): UseFormResult { const [hasChanged, setChanged] = useState(false); const [data, setData] = useStateFromProps(initial, { mergeFunc: merge, onRefresh: newData => handleRefresh(data, newData, setChanged) }); - const [leaveModal, setLeaveModal] = useState(false); - const leaveAction = useRef<() => void>(null); function toggleValue(event: ChangeEvent, cb?: () => void) { const { name, value } = event.target; @@ -112,26 +107,17 @@ function useForm( } function submit() { - onSubmit(data, leaveAction.current); - setLeaveModal(false); + return onSubmit(data); } function triggerChange() { setChanged(true); } - function askToLeave(action: () => void | null) { - setLeaveModal(() => !!action); - leaveAction.current = action; - } - return { - askToLeave, change, data, hasChanged, - leaveAction, - leaveModal, reset, set, submit, diff --git a/src/products/components/ProductCreatePage/ProductCreatePage.tsx b/src/products/components/ProductCreatePage/ProductCreatePage.tsx index f0baedfb2..21464797b 100644 --- a/src/products/components/ProductCreatePage/ProductCreatePage.tsx +++ b/src/products/components/ProductCreatePage/ProductCreatePage.tsx @@ -5,7 +5,6 @@ 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 LeaveScreenDialog from "@saleor/components/LeaveScreenDialog"; import Metadata, { MetadataFormData } from "@saleor/components/Metadata"; import { MultiAutocompleteChoiceType } from "@saleor/components/MultiAutocompleteSelectField"; import PageHeader from "@saleor/components/PageHeader"; @@ -79,8 +78,6 @@ export interface ProductCreatePageSubmitData extends FormData { stocks: ProductStockInput[]; } -export type ProductCreatePageSubmitNextAction = "warehouse-configure"; - interface ProductCreatePageProps { errors: ProductErrorFragment[]; collections: SearchCollections_search_edges_node[]; @@ -101,16 +98,12 @@ interface ProductCreatePageProps { weightUnit: string; warehouses: SearchWarehouses_search_edges_node[]; taxTypes: TaxTypeFragment[]; - submitNextAction?: ProductCreatePageSubmitNextAction; fetchCategories: (data: string) => void; fetchCollections: (data: string) => void; fetchProductTypes: (data: string) => void; + onWarehouseConfigure: () => void; onBack?(); - onSubmit?( - data: ProductCreatePageSubmitData, - nextAction?: ProductCreatePageSubmitNextAction - ); - onSubmitSkip?(nextAction?: ProductCreatePageSubmitNextAction); + onSubmit?(data: ProductCreatePageSubmitData); } export const ProductCreatePage: React.FC = ({ @@ -133,7 +126,7 @@ export const ProductCreatePage: React.FC = ({ fetchProductTypes, weightUnit, onSubmit, - onSubmitSkip + onWarehouseConfigure }: ProductCreatePageProps) => { const intl = useIntl(); const localizeDate = useDateLocalize(); @@ -210,21 +203,12 @@ export const ProductCreatePage: React.FC = ({ value: taxType.taxCode })) || []; - const [modalWithAction, setModalWithAction] = React.useState< - ProductCreatePageSubmitNextAction - >(null); - - const handleSubmit = (data: FormData) => { - onSubmit( - { - ...data, - attributes, - stocks - }, - modalWithAction - ); - setModalWithAction(null); - }; + const handleSubmit = (data: FormData) => + onSubmit({ + ...data, + attributes, + stocks + }); return (
@@ -339,13 +323,7 @@ export const ProductCreatePage: React.FC = ({ triggerChange(); removeStock(id); }} - onWarehouseConfigure={() => { - if (disabled || !onSubmit || !hasChanged) { - onSubmitSkip("warehouse-configure"); - } else { - setModalWithAction("warehouse-configure"); - } - }} + onWarehouseConfigure={onWarehouseConfigure} /> @@ -434,17 +412,6 @@ export const ProductCreatePage: React.FC = ({ state={saveButtonBarState} disabled={disabled || !onSubmit || !hasChanged} /> - { - submit(); - }} - onRejectChanges={() => { - onSubmitSkip("warehouse-configure"); - }} - onClose={() => setModalWithAction(null)} - open={modalWithAction === "warehouse-configure"} - confirmButtonState={saveButtonBarState} - /> ); }} diff --git a/src/products/components/ProductUpdatePage/ProductUpdatePage.tsx b/src/products/components/ProductUpdatePage/ProductUpdatePage.tsx index b263bd57e..13e56879d 100644 --- a/src/products/components/ProductUpdatePage/ProductUpdatePage.tsx +++ b/src/products/components/ProductUpdatePage/ProductUpdatePage.tsx @@ -84,7 +84,7 @@ export interface ProductUpdatePageProps extends ListActions { onImageReorder?(event: { oldIndex: number; newIndex: number }); onImageUpload(file: File); onSeoClick?(); - onSubmit?(data: ProductUpdatePageSubmitData, nextAction?: () => void); + onSubmit?(data: ProductUpdatePageSubmitData); onVariantAdd?(); onSetDefaultVariant(); onWarehouseConfigure(); @@ -193,28 +193,22 @@ export const ProductUpdatePage: React.FC = ({ value: taxType.taxCode })) || []; - const handleSubmit = ( - data: ProductUpdatePageFormData, - nextAction: () => void - ) => { + const handleSubmit = (data: ProductUpdatePageFormData) => { const metadata = isMetadataModified ? data.metadata : undefined; const privateMetadata = isPrivateMetadataModified ? data.privateMetadata : undefined; if (product.productType.hasVariants) { - onSubmit( - { - ...data, - addStocks: [], - attributes, - metadata, - privateMetadata, - removeStocks: [], - updateStocks: [] - }, - nextAction - ); + onSubmit({ + ...data, + addStocks: [], + attributes, + metadata, + privateMetadata, + removeStocks: [], + updateStocks: [] + }); } else { const dataStocks = stocks.map(stock => stock.id); const variantStocks = product.variants[0]?.stocks.map( @@ -222,37 +216,25 @@ export const ProductUpdatePage: React.FC = ({ ); const stockDiff = diff(variantStocks, dataStocks); - onSubmit( - { - ...data, - addStocks: stocks.filter(stock => - stockDiff.added.some(addedStock => addedStock === stock.id) - ), - attributes, - metadata, - privateMetadata, - removeStocks: stockDiff.removed, - updateStocks: stocks.filter( - stock => - !stockDiff.added.some(addedStock => addedStock === stock.id) - ) - }, - nextAction - ); + onSubmit({ + ...data, + addStocks: stocks.filter(stock => + stockDiff.added.some(addedStock => addedStock === stock.id) + ), + attributes, + metadata, + privateMetadata, + removeStocks: stockDiff.removed, + updateStocks: stocks.filter( + stock => !stockDiff.added.some(addedStock => addedStock === stock.id) + ) + }); } }; return ( - {({ - change, - data, - hasChanged, - submit, - triggerChange, - toggleValue, - askToLeave - }) => { + {({ change, data, hasChanged, submit, triggerChange, toggleValue }) => { const handleCollectionSelect = createMultiAutocompleteSelectHandler( toggleValue, setSelectedCollections, @@ -390,13 +372,7 @@ export const ProductUpdatePage: React.FC = ({ triggerChange(); removeStock(id); }} - onWarehouseConfigure={() => { - if (disabled || !onSubmit || !hasChanged) { - onWarehouseConfigure(); - } else { - askToLeave(onWarehouseConfigure); - } - }} + onWarehouseConfigure={onWarehouseConfigure} /> )} diff --git a/src/products/components/ProductVariantCreatePage/ProductVariantCreatePage.tsx b/src/products/components/ProductVariantCreatePage/ProductVariantCreatePage.tsx index 7117a09bf..8c345e4f2 100644 --- a/src/products/components/ProductVariantCreatePage/ProductVariantCreatePage.tsx +++ b/src/products/components/ProductVariantCreatePage/ProductVariantCreatePage.tsx @@ -4,7 +4,6 @@ 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 LeaveScreenDialog from "@saleor/components/LeaveScreenDialog"; import Metadata, { MetadataFormData } from "@saleor/components/Metadata"; import PageHeader from "@saleor/components/PageHeader"; import SaveButtonBar from "@saleor/components/SaveButtonBar"; @@ -46,8 +45,6 @@ export interface ProductVariantCreatePageSubmitData stocks: ProductStockInput[]; } -export type ProductVariantCreatePageSubmitNextAction = "warehouse-configure"; - interface ProductVariantCreatePageProps { currencySymbol: string; disabled: boolean; @@ -58,15 +55,10 @@ interface ProductVariantCreatePageProps { warehouses: SearchWarehouses_search_edges_node[]; weightUnit: string; onBack: () => void; - onSubmit: ( - data: ProductVariantCreatePageSubmitData, - nextAction?: ProductVariantCreatePageSubmitNextAction - ) => void; - onSubmitSkip?: ( - nextAction?: ProductVariantCreatePageSubmitNextAction - ) => void; + onSubmit: (data: ProductVariantCreatePageSubmitData) => void; onVariantClick: (variantId: string) => void; onVariantReorder: ReorderAction; + onWarehouseConfigure: () => void; } const ProductVariantCreatePage: React.FC = ({ @@ -80,9 +72,9 @@ const ProductVariantCreatePage: React.FC = ({ weightUnit, onBack, onSubmit, - onSubmitSkip, onVariantClick, - onVariantReorder + onVariantReorder, + onWarehouseConfigure }) => { const intl = useIntl(); const attributeInput = React.useMemo( @@ -114,21 +106,12 @@ const ProductVariantCreatePage: React.FC = ({ weight: "" }; - const [modalWithAction, setModalWithAction] = React.useState< - ProductVariantCreatePageSubmitNextAction - >(null); - - const handleSubmit = (data: ProductVariantCreatePageFormData) => { - onSubmit( - { - ...data, - attributes, - stocks - }, - modalWithAction - ); - setModalWithAction(null); - }; + const handleSubmit = (data: ProductVariantCreatePageFormData) => + onSubmit({ + ...data, + attributes, + stocks + }); return ( @@ -207,13 +190,7 @@ const ProductVariantCreatePage: React.FC = ({ triggerChange(); removeStock(id); }} - onWarehouseConfigure={() => { - if (disabled || !onSubmit || !hasChanged) { - onSubmitSkip("warehouse-configure"); - } else { - setModalWithAction("warehouse-configure"); - } - }} + onWarehouseConfigure={onWarehouseConfigure} /> @@ -235,17 +212,6 @@ const ProductVariantCreatePage: React.FC = ({ onCancel={onBack} onSave={submit} /> - { - submit(); - }} - onRejectChanges={() => { - onSubmitSkip("warehouse-configure"); - }} - onClose={() => setModalWithAction(null)} - open={modalWithAction === "warehouse-configure"} - confirmButtonState={saveButtonBarState} - /> ); }} diff --git a/src/products/components/ProductVariantPage/ProductVariantPage.tsx b/src/products/components/ProductVariantPage/ProductVariantPage.tsx index a2eecb180..d875acf0d 100644 --- a/src/products/components/ProductVariantPage/ProductVariantPage.tsx +++ b/src/products/components/ProductVariantPage/ProductVariantPage.tsx @@ -4,7 +4,6 @@ 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 LeaveScreenDialog from "@saleor/components/LeaveScreenDialog"; import { MetadataFormData } from "@saleor/components/Metadata"; import Metadata from "@saleor/components/Metadata/Metadata"; import PageHeader from "@saleor/components/PageHeader"; @@ -54,8 +53,6 @@ export interface ProductVariantPageSubmitData removeStocks: string[]; } -export type ProductVariantPageSubmitNextAction = "warehouse-configure"; - interface ProductVariantPageProps { defaultWeightUnit: string; variant?: ProductVariant; @@ -69,14 +66,11 @@ interface ProductVariantPageProps { onAdd(); onBack(); onDelete(); - onSubmit( - data: ProductVariantPageSubmitData, - nextAction?: ProductVariantPageSubmitNextAction - ); - onSubmitSkip?(nextAction?: ProductVariantPageSubmitNextAction); + onSubmit(data: ProductVariantPageSubmitData); onImageSelect(id: string); onVariantClick(variantId: string); onSetDefaultVariant(); + onWarehouseConfigure(); } const ProductVariantPage: React.FC = ({ @@ -93,10 +87,10 @@ const ProductVariantPage: React.FC = ({ onDelete, onImageSelect, onSubmit, - onSubmitSkip, onVariantClick, onVariantReorder, - onSetDefaultVariant + onSetDefaultVariant, + onWarehouseConfigure }) => { const attributeInput = React.useMemo( () => getAttributeInputFromVariant(variant), @@ -146,10 +140,6 @@ const ProductVariantPage: React.FC = ({ weight: variant?.weight?.value.toString() || "" }; - const [modalWithAction, setModalWithAction] = React.useState< - ProductVariantPageSubmitNextAction - >(null); - const handleSubmit = (data: ProductVariantPageFormData) => { const dataStocks = stocks.map(stock => stock.id); const variantStocks = variant.stocks.map(stock => stock.warehouse.id); @@ -159,23 +149,19 @@ const ProductVariantPage: React.FC = ({ ? data.privateMetadata : undefined; - onSubmit( - { - ...data, - addStocks: stocks.filter(stock => - stockDiff.added.some(addedStock => addedStock === stock.id) - ), - attributes, - metadata, - privateMetadata, - removeStocks: stockDiff.removed, - updateStocks: stocks.filter( - stock => !stockDiff.added.some(addedStock => addedStock === stock.id) - ) - }, - modalWithAction - ); - setModalWithAction(null); + onSubmit({ + ...data, + addStocks: stocks.filter(stock => + stockDiff.added.some(addedStock => addedStock === stock.id) + ), + attributes, + metadata, + privateMetadata, + removeStocks: stockDiff.removed, + updateStocks: stocks.filter( + stock => !stockDiff.added.some(addedStock => addedStock === stock.id) + ) + }); }; return ( @@ -280,13 +266,7 @@ const ProductVariantPage: React.FC = ({ triggerChange(); removeStock(id); }} - onWarehouseConfigure={() => { - if (!onSubmit || !hasChanged) { - onSubmitSkip("warehouse-configure"); - } else { - setModalWithAction("warehouse-configure"); - } - }} + onWarehouseConfigure={onWarehouseConfigure} /> @@ -299,17 +279,6 @@ const ProductVariantPage: React.FC = ({ onDelete={onDelete} onSave={submit} /> - { - submit(); - }} - onRejectChanges={() => { - onSubmitSkip("warehouse-configure"); - }} - onClose={() => setModalWithAction(null)} - open={modalWithAction === "warehouse-configure"} - confirmButtonState={saveButtonBarState} - /> ); }} diff --git a/src/products/views/ProductCreate.tsx b/src/products/views/ProductCreate.tsx index 8bf072c74..168b21bc3 100644 --- a/src/products/views/ProductCreate.tsx +++ b/src/products/views/ProductCreate.tsx @@ -20,8 +20,7 @@ import { useIntl } from "react-intl"; import { decimal, weight } from "../../misc"; import ProductCreatePage, { - ProductCreatePageSubmitData, - ProductCreatePageSubmitNextAction + ProductCreatePageSubmitData } from "../components/ProductCreatePage"; import { useProductCreateMutation, @@ -73,7 +72,7 @@ export const ProductCreateView: React.FC = () => { ] = useProductSetAvailabilityForPurchase({ onCompleted: data => { const errors = data?.productSetAvailabilityForPurchase?.errors; - if (errors?.length === 0 && !submitNextAction) { + if (errors?.length === 0) { navigate(productUrl(data.productSetAvailabilityForPurchase.product.id)); } } @@ -92,12 +91,7 @@ export const ProductCreateView: React.FC = () => { } }); - const handleCreate = async ( - formData: ProductCreatePageSubmitData, - nextAction?: ProductCreatePageSubmitNextAction - ) => { - setSubmitNextAction(nextAction); - + const handleCreate = async (formData: ProductCreatePageSubmitData) => { const result = await productCreate({ variables: { input: { @@ -157,18 +151,6 @@ export const ProductCreateView: React.FC = () => { updatePrivateMetadata ); - const [submitNextAction, setSubmitNextAction] = React.useState< - ProductCreatePageSubmitNextAction - >(null); - const handleSubmitNextAction = ( - nextAction?: ProductCreatePageSubmitNextAction - ) => { - const action = nextAction || submitNextAction; - if (action === "warehouse-configure") { - navigate(warehouseListPath); - } - }; - return ( <> { edge => edge.node )} onBack={handleBack} - onSubmit={async (data, nextAction) => { - const errors = await handleSubmit(data, nextAction); - if (errors?.length === 0) { - handleSubmitNextAction(nextAction); - } else { - setSubmitNextAction(null); - } - }} - onSubmitSkip={handleSubmitNextAction} + onSubmit={handleSubmit} + onWarehouseConfigure={() => navigate(warehouseListPath)} saveButtonBarState={productCreateOpts.status} fetchMoreCategories={{ hasMore: searchCategoryOpts.data?.search.pageInfo.hasNextPage, diff --git a/src/products/views/ProductUpdate/ProductUpdate.tsx b/src/products/views/ProductUpdate/ProductUpdate.tsx index 6e1225941..ae12fe679 100644 --- a/src/products/views/ProductUpdate/ProductUpdate.tsx +++ b/src/products/views/ProductUpdate/ProductUpdate.tsx @@ -304,12 +304,7 @@ export const ProductUpdate: React.FC = ({ id, params }) => { onBack={handleBack} onDelete={() => openModal("remove")} onImageReorder={handleImageReorder} - onSubmit={async (data, nextAction) => { - const errors = await handleSubmit(data); - if (errors?.length === 0 && nextAction) { - nextAction(); - } - }} + onSubmit={handleSubmit} onWarehouseConfigure={() => navigate(warehouseListPath)} onVariantAdd={handleVariantAdd} onVariantsAdd={() => navigate(productVariantCreatorUrl(id))} diff --git a/src/products/views/ProductVariant.tsx b/src/products/views/ProductVariant.tsx index d5870eeda..acbc500c5 100644 --- a/src/products/views/ProductVariant.tsx +++ b/src/products/views/ProductVariant.tsx @@ -20,8 +20,7 @@ import { useIntl } from "react-intl"; import { decimal, weight } from "../../misc"; import ProductVariantDeleteDialog from "../components/ProductVariantDeleteDialog"; import ProductVariantPage, { - ProductVariantPageSubmitData, - ProductVariantPageSubmitNextAction + ProductVariantPageSubmitData } from "../components/ProductVariantPage"; import { useProductVariantReorderMutation, @@ -198,14 +197,6 @@ export const ProductVariant: React.FC = ({ variables => updatePrivateMetadata({ variables }) ); - const handleSubmitNextAction = ( - nextAction?: ProductVariantPageSubmitNextAction - ) => { - if (nextAction === "warehouse-configure") { - navigate(warehouseListPath); - } - }; - return ( <> @@ -225,13 +216,8 @@ export const ProductVariant: React.FC = ({ onBack={handleBack} onDelete={() => openModal("remove")} onImageSelect={handleImageSelect} - onSubmit={async (data, nextAction) => { - const errors = await handleSubmit(data); - if (errors?.length === 0) { - handleSubmitNextAction(nextAction); - } - }} - onSubmitSkip={handleSubmitNextAction} + onSubmit={handleSubmit} + onWarehouseConfigure={() => navigate(warehouseListPath)} onVariantClick={variantId => { navigate(productVariantEditUrl(productId, variantId)); }} diff --git a/src/products/views/ProductVariantCreate.tsx b/src/products/views/ProductVariantCreate.tsx index 23d4f9ea1..06c9faa3a 100644 --- a/src/products/views/ProductVariantCreate.tsx +++ b/src/products/views/ProductVariantCreate.tsx @@ -16,8 +16,7 @@ import { useIntl } from "react-intl"; import { decimal, weight } from "../../misc"; import ProductVariantCreatePage, { - ProductVariantCreatePageSubmitData, - ProductVariantCreatePageSubmitNextAction + ProductVariantCreatePageSubmitData } from "../components/ProductVariantCreatePage"; import { useProductVariantReorderMutation, @@ -57,14 +56,12 @@ export const ProductVariant: React.FC = ({ status: "success", text: intl.formatMessage(commonMessages.savedChanges) }); - if (!submitNextAction) { - navigate( - productVariantEditUrl( - productId, - data.productVariantCreate.productVariant.id - ) - ); - } + navigate( + productVariantEditUrl( + productId, + data.productVariantCreate.productVariant.id + ) + ); } } }); @@ -87,12 +84,7 @@ export const ProductVariant: React.FC = ({ ); const handleBack = () => navigate(productUrl(productId)); - const handleCreate = async ( - formData: ProductVariantCreatePageSubmitData, - nextAction?: ProductVariantCreatePageSubmitNextAction - ) => { - setSubmitNextAction(nextAction); - + const handleCreate = async (formData: ProductVariantCreatePageSubmitData) => { const result = await variantCreate({ variables: { input: { @@ -126,18 +118,6 @@ export const ProductVariant: React.FC = ({ const handleVariantClick = (id: string) => 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 = productLoading || variantCreateResult.loading || @@ -161,16 +141,9 @@ export const ProductVariant: React.FC = ({ })} product={data?.product} onBack={handleBack} - onSubmit={async (data, nextAction) => { - const errors = await handleSubmit(data, nextAction); - if (errors?.length === 0) { - handleSubmitNextAction(nextAction); - } else { - setSubmitNextAction(null); - } - }} - onSubmitSkip={handleSubmitNextAction} + onSubmit={handleSubmit} onVariantClick={handleVariantClick} + onWarehouseConfigure={() => navigate(warehouseListPath)} onVariantReorder={handleVariantReorder} saveButtonBarState={variantCreateResult.status} warehouses={ diff --git a/src/storybook/stories/products/ProductCreatePage.tsx b/src/storybook/stories/products/ProductCreatePage.tsx index babd8504a..df02a860f 100644 --- a/src/storybook/stories/products/ProductCreatePage.tsx +++ b/src/storybook/stories/products/ProductCreatePage.tsx @@ -35,6 +35,7 @@ storiesOf("Views / Products / Create product", module) onSubmit={() => undefined} saveButtonBarState="default" warehouses={warehouseList} + onWarehouseConfigure={() => undefined} taxTypes={taxTypes} weightUnit="kg" /> @@ -58,6 +59,7 @@ storiesOf("Views / Products / Create product", module) onSubmit={() => undefined} saveButtonBarState="default" warehouses={undefined} + onWarehouseConfigure={() => undefined} taxTypes={taxTypes} weightUnit="kg" /> @@ -87,6 +89,7 @@ storiesOf("Views / Products / Create product", module) onSubmit={() => undefined} saveButtonBarState="default" warehouses={warehouseList} + onWarehouseConfigure={() => undefined} taxTypes={taxTypes} weightUnit="kg" /> diff --git a/src/storybook/stories/products/ProductVariantCreatePage.tsx b/src/storybook/stories/products/ProductVariantCreatePage.tsx index d8578724d..d0fdbea77 100644 --- a/src/storybook/stories/products/ProductVariantCreatePage.tsx +++ b/src/storybook/stories/products/ProductVariantCreatePage.tsx @@ -26,6 +26,7 @@ storiesOf("Views / Products / Create product variant", module) onVariantReorder={() => undefined} saveButtonBarState="default" warehouses={warehouseList} + onWarehouseConfigure={() => undefined} /> )) .add("with errors", () => ( @@ -58,6 +59,7 @@ storiesOf("Views / Products / Create product variant", module) onVariantReorder={() => undefined} saveButtonBarState="default" warehouses={warehouseList} + onWarehouseConfigure={() => undefined} /> )) .add("when loading data", () => ( @@ -74,6 +76,7 @@ storiesOf("Views / Products / Create product variant", module) onVariantReorder={() => undefined} saveButtonBarState="default" warehouses={warehouseList} + onWarehouseConfigure={() => undefined} /> )) .add("add first variant", () => ( @@ -93,5 +96,6 @@ storiesOf("Views / Products / Create product variant", module) onVariantReorder={() => undefined} saveButtonBarState="default" warehouses={warehouseList} + onWarehouseConfigure={() => undefined} /> )); diff --git a/src/storybook/stories/products/ProductVariantPage.tsx b/src/storybook/stories/products/ProductVariantPage.tsx index 038c03372..a70095d78 100644 --- a/src/storybook/stories/products/ProductVariantPage.tsx +++ b/src/storybook/stories/products/ProductVariantPage.tsx @@ -28,6 +28,7 @@ storiesOf("Views / Products / Product variant details", module) onVariantReorder={() => undefined} saveButtonBarState="default" warehouses={warehouseList} + onWarehouseConfigure={() => undefined} /> )) .add("when loading data", () => ( @@ -47,6 +48,7 @@ storiesOf("Views / Products / Product variant details", module) onVariantReorder={() => undefined} saveButtonBarState="default" warehouses={warehouseList} + onWarehouseConfigure={() => undefined} /> )) .add("attribute errors", () => ( @@ -82,5 +84,6 @@ storiesOf("Views / Products / Product variant details", module) ...error }))} warehouses={warehouseList} + onWarehouseConfigure={() => undefined} /> )); diff --git a/src/utils/handlers/metadataCreateHandler.ts b/src/utils/handlers/metadataCreateHandler.ts index 73bb5a619..e24491b80 100644 --- a/src/utils/handlers/metadataCreateHandler.ts +++ b/src/utils/handlers/metadataCreateHandler.ts @@ -10,19 +10,16 @@ import { UpdatePrivateMetadataVariables } from "../metadata/types/UpdatePrivateMetadata"; -function createMetadataCreateHandler< - T extends MetadataFormData, - N extends string ->( - create: (data: T, nextAction?: N) => Promise, +function createMetadataCreateHandler( + create: (data: T) => Promise, setMetadata: MutationFunction, setPrivateMetadata: MutationFunction< UpdatePrivateMetadata, UpdatePrivateMetadataVariables > ) { - return async (data: T, nextAction?: N) => { - const id = await create(data, nextAction); + return async (data: T) => { + const id = await create(data); if (id === null) { return null;