diff --git a/src/auth/views/NewPassword.tsx b/src/auth/views/NewPassword.tsx index 95fa9a4df..7eefe2fac 100644 --- a/src/auth/views/NewPassword.tsx +++ b/src/auth/views/NewPassword.tsx @@ -24,7 +24,7 @@ const NewPassword: React.FC = ({ location }) => { data.setPassword.csrfToken, data.setPassword.user ); - navigate("/", true); + navigate("/", { replace: true }); } }; diff --git a/src/categories/views/CategoryList/CategoryList.tsx b/src/categories/views/CategoryList/CategoryList.tsx index 923232b01..410311242 100644 --- a/src/categories/views/CategoryList/CategoryList.tsx +++ b/src/categories/views/CategoryList/CategoryList.tsx @@ -132,7 +132,7 @@ export const CategoryList: React.FC = ({ params }) => { const handleCategoryBulkDelete = (data: CategoryBulkDelete) => { if (data.categoryBulkDelete.errors.length === 0) { - navigate(categoryListUrl(), true); + navigate(categoryListUrl(), { replace: true }); refetch(); reset(); } diff --git a/src/collections/views/CollectionDetails.tsx b/src/collections/views/CollectionDetails.tsx index 199bf888f..d4e4c5266 100644 --- a/src/collections/views/CollectionDetails.tsx +++ b/src/collections/views/CollectionDetails.tsx @@ -120,7 +120,7 @@ export const CollectionDetails: React.FC = ({ defaultMessage: "Added product to collection" }) }); - navigate(collectionUrl(id), true); + navigate(collectionUrl(id), { replace: true }); } } } diff --git a/src/customers/views/CustomerDetails.tsx b/src/customers/views/CustomerDetails.tsx index 8ea5080c7..a44f9e622 100644 --- a/src/customers/views/CustomerDetails.tsx +++ b/src/customers/views/CustomerDetails.tsx @@ -149,7 +149,9 @@ export const CustomerDetailsView: React.FC = ({ /> navigate(customerUrl(id), true)} + onClose={() => + navigate(customerUrl(id), { replace: true }) + } onConfirm={() => removeCustomer()} title={intl.formatMessage({ defaultMessage: "Delete Customer", diff --git a/src/discounts/views/SaleCreate/SaleCreate.tsx b/src/discounts/views/SaleCreate/SaleCreate.tsx index 3a536994b..ee310880e 100644 --- a/src/discounts/views/SaleCreate/SaleCreate.tsx +++ b/src/discounts/views/SaleCreate/SaleCreate.tsx @@ -74,7 +74,7 @@ export const SaleCreateView: React.FC = ({ params }) => { defaultMessage: "Successfully created sale" }) }); - navigate(saleUrl(data.saleCreate.sale.id), true); + navigate(saleUrl(data.saleCreate.sale.id), { replace: true }); } }; diff --git a/src/discounts/views/SaleDetails/SaleDetails.tsx b/src/discounts/views/SaleDetails/SaleDetails.tsx index f651f80b6..f4b24d19a 100644 --- a/src/discounts/views/SaleDetails/SaleDetails.tsx +++ b/src/discounts/views/SaleDetails/SaleDetails.tsx @@ -159,7 +159,7 @@ export const SaleDetails: React.FC = ({ id, params }) => { status: "success", text: intl.formatMessage(messages.saleDetailsSaleDeleteDialog) }); - navigate(saleListUrl(), true); + navigate(saleListUrl(), { replace: true }); } }; diff --git a/src/discounts/views/VoucherCreate/VoucherCreate.tsx b/src/discounts/views/VoucherCreate/VoucherCreate.tsx index 4143eb12b..90a58301e 100644 --- a/src/discounts/views/VoucherCreate/VoucherCreate.tsx +++ b/src/discounts/views/VoucherCreate/VoucherCreate.tsx @@ -79,7 +79,7 @@ export const VoucherCreateView: React.FC = ({ params }) => { defaultMessage: "Successfully created voucher" }) }); - navigate(voucherUrl(data.voucherCreate.voucher.id), true); + navigate(voucherUrl(data.voucherCreate.voucher.id), { replace: true }); } }; diff --git a/src/discounts/views/VoucherDetails/VoucherDetails.tsx b/src/discounts/views/VoucherDetails/VoucherDetails.tsx index f1d5ba90e..183ba56af 100644 --- a/src/discounts/views/VoucherDetails/VoucherDetails.tsx +++ b/src/discounts/views/VoucherDetails/VoucherDetails.tsx @@ -169,7 +169,7 @@ export const VoucherDetails: React.FC = ({ defaultMessage: "Deleted voucher" }) }); - navigate(voucherListUrl(), true); + navigate(voucherListUrl(), { replace: true }); } }; diff --git a/src/hooks/useNavigator.ts b/src/hooks/useNavigator.ts index e6f1c9f93..a29a993ad 100644 --- a/src/hooks/useNavigator.ts +++ b/src/hooks/useNavigator.ts @@ -2,8 +2,11 @@ import useRouter from "use-react-router"; export type UseNavigatorResult = ( url: string, - replace?: boolean, - preserveQs?: boolean + opts?: { + replace?: boolean; + preserveQs?: boolean; + resetScroll?: boolean; + } ) => void; function useNavigator(): UseNavigatorResult { const { @@ -11,15 +14,19 @@ function useNavigator(): UseNavigatorResult { history } = useRouter(); - return (url: string, replace = false, preserveQs = false) => { + return ( + url: string, + { replace = false, preserveQs = false, resetScroll = true } = {} + ) => { const targetUrl = preserveQs ? url + search : url; if (replace) { history.replace(targetUrl); } else { history.push(targetUrl); } - - window.scrollTo({ behavior: "smooth", top: 0 }); + if (resetScroll) { + window.scrollTo({ behavior: "smooth", top: 0 }); + } }; } diff --git a/src/hooks/usePaginationReset.ts b/src/hooks/usePaginationReset.ts index 4a237bc4d..97c5d4533 100644 --- a/src/hooks/usePaginationReset.ts +++ b/src/hooks/usePaginationReset.ts @@ -5,5 +5,5 @@ import useNavigator from "./useNavigator"; export const usePaginationReset = (url: string, rowNumber: number) => { const navigate = useNavigator(); - useEffect(() => navigate(url, true), [rowNumber]); + useEffect(() => navigate(url, { replace: true }), [rowNumber]); }; diff --git a/src/hooks/usePaginator.ts b/src/hooks/usePaginator.ts index 547ed3dfb..6b38480ff 100644 --- a/src/hooks/usePaginator.ts +++ b/src/hooks/usePaginator.ts @@ -52,7 +52,7 @@ function usePaginator() { after: pageInfo.endCursor, before: undefined }), - true + { replace: true } ); const loadPreviousPage = () => @@ -63,7 +63,7 @@ function usePaginator() { after: undefined, before: pageInfo.startCursor }), - true + { replace: true } ); const newPageInfo = pageInfo diff --git a/src/navigation/views/MenuDetails/index.tsx b/src/navigation/views/MenuDetails/index.tsx index 9343cd58d..fedf84942 100644 --- a/src/navigation/views/MenuDetails/index.tsx +++ b/src/navigation/views/MenuDetails/index.tsx @@ -77,7 +77,7 @@ const MenuDetails: React.FC = ({ id, params }) => { action: undefined, id: undefined }), - true + { replace: true } ); const handleItemClick = (id: string, type: MenuItemType) => { diff --git a/src/navigation/views/MenuDetails/successHandlers.ts b/src/navigation/views/MenuDetails/successHandlers.ts index 9c7204cba..fe7f4383b 100644 --- a/src/navigation/views/MenuDetails/successHandlers.ts +++ b/src/navigation/views/MenuDetails/successHandlers.ts @@ -56,7 +56,7 @@ export function handleDelete( status: "success", text: intl.formatMessage(commonMessages.savedChanges) }); - navigate(menuListUrl(), true); + navigate(menuListUrl(), { replace: true }); } } diff --git a/src/navigation/views/MenuList/MenuList.tsx b/src/navigation/views/MenuList/MenuList.tsx index 5b68e03cc..84b21c35d 100644 --- a/src/navigation/views/MenuList/MenuList.tsx +++ b/src/navigation/views/MenuList/MenuList.tsx @@ -66,7 +66,7 @@ const MenuList: React.FC = ({ params }) => { id: undefined, ids: undefined }), - true + { replace: true } ); const paginationState = createPaginationState(settings.rowNumber, params); diff --git a/src/orders/views/OrderFulfill/OrderFulfill.tsx b/src/orders/views/OrderFulfill/OrderFulfill.tsx index 1a9bdd025..6f39648e7 100644 --- a/src/orders/views/OrderFulfill/OrderFulfill.tsx +++ b/src/orders/views/OrderFulfill/OrderFulfill.tsx @@ -58,7 +58,7 @@ const OrderFulfill: React.FC = ({ orderId }) => { const [fulfillOrder, fulfillOrderOpts] = useOrderFulfill({ onCompleted: data => { if (data.orderFulfill.errors.length === 0) { - navigate(orderUrl(orderId), true); + navigate(orderUrl(orderId), { replace: true }); notify({ status: "success", text: intl.formatMessage({ diff --git a/src/orders/views/OrderRefund/OrderRefund.tsx b/src/orders/views/OrderRefund/OrderRefund.tsx index 15145b257..1208075b8 100644 --- a/src/orders/views/OrderRefund/OrderRefund.tsx +++ b/src/orders/views/OrderRefund/OrderRefund.tsx @@ -69,7 +69,7 @@ const OrderRefund: React.FC = ({ orderId }) => { const [refundOrder, refundOrderOpts] = useOrderRefundMutation({ onCompleted: data => { if (data.orderRefund.errors.length === 0) { - navigate(orderUrl(orderId), true); + navigate(orderUrl(orderId), { replace: true }); notify({ status: "success", text: intl.formatMessage({ @@ -86,7 +86,7 @@ const OrderRefund: React.FC = ({ orderId }) => { ] = useOrderFulfillmentRefundProductsMutation({ onCompleted: data => { if (data.orderFulfillmentRefundProducts.errors.length === 0) { - navigate(orderUrl(orderId), true); + navigate(orderUrl(orderId), { replace: true }); notify({ status: "success", text: intl.formatMessage({ diff --git a/src/pageTypes/views/PageTypeDetails.tsx b/src/pageTypes/views/PageTypeDetails.tsx index f75bd2893..d6787a316 100644 --- a/src/pageTypes/views/PageTypeDetails.tsx +++ b/src/pageTypes/views/PageTypeDetails.tsx @@ -74,7 +74,7 @@ export const PageTypeDetails: React.FC = ({ defaultMessage: "Page type deleted" }) }); - navigate(pageTypeListUrl(), true); + navigate(pageTypeListUrl(), { replace: true }); } } }); @@ -175,7 +175,7 @@ export const PageTypeDetails: React.FC = ({ return ; } - const closeModal = () => navigate(pageTypeUrl(id), true); + const closeModal = () => navigate(pageTypeUrl(id), { replace: true }); const handleSubmit = createMetadataUpdateHandler( data?.pageType, diff --git a/src/productTypes/views/ProductTypeUpdate/index.tsx b/src/productTypes/views/ProductTypeUpdate/index.tsx index e2a93dc8f..418c50881 100644 --- a/src/productTypes/views/ProductTypeUpdate/index.tsx +++ b/src/productTypes/views/ProductTypeUpdate/index.tsx @@ -175,7 +175,8 @@ export const ProductTypeUpdate: React.FC = ({ return ; } - const closeModal = () => navigate(productTypeUrl(id), true); + const closeModal = () => + navigate(productTypeUrl(id), { replace: true }); const handleAttributeAssignSuccess = (data: AssignProductAttribute) => { if (data.productAttributeAssign.errors.length === 0) { @@ -217,7 +218,7 @@ export const ProductTypeUpdate: React.FC = ({ defaultMessage: "Product type deleted" }) }); - navigate(productTypeListUrl(), true); + navigate(productTypeListUrl(), { replace: true }); } }; const handleSubmit = createMetadataUpdateHandler( diff --git a/src/products/views/ProductImage.tsx b/src/products/views/ProductImage.tsx index fa8ede1a1..2edb42a78 100644 --- a/src/products/views/ProductImage.tsx +++ b/src/products/views/ProductImage.tsx @@ -99,7 +99,9 @@ export const ProductImage: React.FC = ({ saveButtonBarState={updateResult.status} /> navigate(productImageUrl(productId, mediaId), true)} + onClose={() => + navigate(productImageUrl(productId, mediaId), { replace: true }) + } onConfirm={handleDelete} open={params.action === "remove"} title={intl.formatMessage({ diff --git a/src/products/views/ProductUpdate/ProductUpdate.tsx b/src/products/views/ProductUpdate/ProductUpdate.tsx index eec663d4c..addb99989 100644 --- a/src/products/views/ProductUpdate/ProductUpdate.tsx +++ b/src/products/views/ProductUpdate/ProductUpdate.tsx @@ -430,7 +430,8 @@ export const ProductUpdate: React.FC = ({ id, params }) => { productUrl(id, { action: "assign-attribute-value", id: attribute.id - }) + }), + { resetScroll: false } ); const disableFormSave = @@ -619,7 +620,7 @@ export const ProductUpdate: React.FC = ({ id, params }) => { fetchReferenceProducts={searchProducts} fetchMoreReferenceProducts={fetchMoreReferenceProducts} fetchMoreAttributeValues={fetchMoreAttributeValues} - onCloseDialog={() => navigate(productUrl(id))} + onCloseDialog={() => navigate(productUrl(id), { resetScroll: false })} onAttributeSelectBlur={searchAttributeReset} /> = ({ status: "success", text: intl.formatMessage(commonMessages.savedChanges) }); - navigate(shippingZonesListUrl(), true); + navigate(shippingZonesListUrl(), { replace: true }); } } }); diff --git a/src/translations/views/TranslationsAttributes.tsx b/src/translations/views/TranslationsAttributes.tsx index fc705fbad..1e7340bce 100644 --- a/src/translations/views/TranslationsAttributes.tsx +++ b/src/translations/views/TranslationsAttributes.tsx @@ -86,7 +86,7 @@ const TranslationsAttributes: React.FC = ({ stringifyQs({ activeField: field }), - true + { replace: true } ); const onAttributeUpdate = (data: UpdateAttributeTranslations) => { if (data.attributeTranslate.errors.length === 0) { @@ -95,7 +95,7 @@ const TranslationsAttributes: React.FC = ({ status: "success", text: intl.formatMessage(commonMessages.savedChanges) }); - navigate("?", true); + navigate("?", { replace: true }); } }; const onAttributeValueUpdate = (data: UpdateAttributeValueTranslations) => { @@ -105,11 +105,11 @@ const TranslationsAttributes: React.FC = ({ status: "success", text: intl.formatMessage(commonMessages.savedChanges) }); - navigate("?", true); + navigate("?", { replace: true }); } }; const onDiscard = () => { - navigate("?", true); + navigate("?", { replace: true }); }; return ( diff --git a/src/translations/views/TranslationsCategories.tsx b/src/translations/views/TranslationsCategories.tsx index 53ff1c99f..cf1cf767e 100644 --- a/src/translations/views/TranslationsCategories.tsx +++ b/src/translations/views/TranslationsCategories.tsx @@ -49,7 +49,7 @@ const TranslationsCategories: React.FC = ({ stringifyQs({ activeField: field }), - true + { replace: true } ); const onUpdate = (data: UpdateCategoryTranslations) => { if (data.categoryTranslate.errors.length === 0) { @@ -58,11 +58,11 @@ const TranslationsCategories: React.FC = ({ status: "success", text: intl.formatMessage(commonMessages.savedChanges) }); - navigate("?", true); + navigate("?", { replace: true }); } }; const onDiscard = () => { - navigate("?", true); + navigate("?", { replace: true }); }; return ( diff --git a/src/translations/views/TranslationsCollections.tsx b/src/translations/views/TranslationsCollections.tsx index 861985779..65c96f944 100644 --- a/src/translations/views/TranslationsCollections.tsx +++ b/src/translations/views/TranslationsCollections.tsx @@ -49,7 +49,7 @@ const TranslationsCollections: React.FC = ({ stringifyQs({ activeField: field }), - true + { replace: true } ); const onUpdate = (data: UpdateCollectionTranslations) => { if (data.collectionTranslate.errors.length === 0) { @@ -58,11 +58,11 @@ const TranslationsCollections: React.FC = ({ status: "success", text: intl.formatMessage(commonMessages.savedChanges) }); - navigate("?", true); + navigate("?", { replace: true }); } }; const onDiscard = () => { - navigate("?", true); + navigate("?", { replace: true }); }; const translation = collectionTranslations?.data?.translation; diff --git a/src/translations/views/TranslationsEntities.tsx b/src/translations/views/TranslationsEntities.tsx index 2a46de47e..3747186f9 100644 --- a/src/translations/views/TranslationsEntities.tsx +++ b/src/translations/views/TranslationsEntities.tsx @@ -50,7 +50,7 @@ const TranslationsEntities: React.FC = ({ stringifyQs({ tab: TranslatableEntities.categories }), - true + { replace: true } ); } diff --git a/src/translations/views/TranslationsPages.tsx b/src/translations/views/TranslationsPages.tsx index d0444556c..4b35d4157 100644 --- a/src/translations/views/TranslationsPages.tsx +++ b/src/translations/views/TranslationsPages.tsx @@ -51,7 +51,7 @@ const TranslationsPages: React.FC = ({ stringifyQs({ activeField: field }), - true + { replace: true } ); const onUpdate = (errors: unknown[]) => { @@ -61,12 +61,12 @@ const TranslationsPages: React.FC = ({ status: "success", text: intl.formatMessage(commonMessages.savedChanges) }); - navigate("?", true); + navigate("?", { replace: true }); } }; const onDiscard = () => { - navigate("?", true); + navigate("?", { replace: true }); }; return ( diff --git a/src/translations/views/TranslationsProductVariants.tsx b/src/translations/views/TranslationsProductVariants.tsx index c6f8159e1..f1e09c6a1 100644 --- a/src/translations/views/TranslationsProductVariants.tsx +++ b/src/translations/views/TranslationsProductVariants.tsx @@ -54,7 +54,7 @@ const TranslationsProductVariants: React.FC = stringifyQs({ activeField: field }), - true + { replace: true } ); const onUpdate = (errors: unknown[]) => { @@ -64,12 +64,12 @@ const TranslationsProductVariants: React.FC = status: "success", text: intl.formatMessage(commonMessages.savedChanges) }); - navigate("?", true); + navigate("?", { replace: true }); } }; const onDiscard = () => { - navigate("?", true); + navigate("?", { replace: true }); }; return ( diff --git a/src/translations/views/TranslationsProducts.tsx b/src/translations/views/TranslationsProducts.tsx index a6beb7065..e937b2aeb 100644 --- a/src/translations/views/TranslationsProducts.tsx +++ b/src/translations/views/TranslationsProducts.tsx @@ -52,7 +52,7 @@ const TranslationsProducts: React.FC = ({ stringifyQs({ activeField: field }), - true + { replace: true } ); const onUpdate = (errors: unknown[]) => { @@ -62,12 +62,12 @@ const TranslationsProducts: React.FC = ({ status: "success", text: intl.formatMessage(commonMessages.savedChanges) }); - navigate("?", true); + navigate("?", { replace: true }); } }; const onDiscard = () => { - navigate("?", true); + navigate("?", { replace: true }); }; return ( diff --git a/src/translations/views/TranslationsSales.tsx b/src/translations/views/TranslationsSales.tsx index ce9289e89..21f9db5f2 100644 --- a/src/translations/views/TranslationsSales.tsx +++ b/src/translations/views/TranslationsSales.tsx @@ -48,7 +48,7 @@ const TranslationsSales: React.FC = ({ stringifyQs({ activeField: field }), - true + { replace: true } ); const onUpdate = (data: UpdateSaleTranslations) => { if (data.saleTranslate.errors.length === 0) { @@ -57,11 +57,11 @@ const TranslationsSales: React.FC = ({ status: "success", text: intl.formatMessage(commonMessages.savedChanges) }); - navigate("?", true); + navigate("?", { replace: true }); } }; const onDiscard = () => { - navigate("?", true); + navigate("?", { replace: true }); }; return ( diff --git a/src/translations/views/TranslationsShippingMethod.tsx b/src/translations/views/TranslationsShippingMethod.tsx index 8a367853f..e20f5acb0 100644 --- a/src/translations/views/TranslationsShippingMethod.tsx +++ b/src/translations/views/TranslationsShippingMethod.tsx @@ -48,7 +48,7 @@ const TranslationsShippingMethod: React.FC = ({ stringifyQs({ activeField: field }), - true + { replace: true } ); const onUpdate = (data: UpdateShippingMethodTranslations) => { if (data.shippingPriceTranslate.errors.length === 0) { @@ -57,11 +57,11 @@ const TranslationsShippingMethod: React.FC = ({ status: "success", text: intl.formatMessage(commonMessages.savedChanges) }); - navigate("?", true); + navigate("?", { replace: true }); } }; const onDiscard = () => { - navigate("?", true); + navigate("?", { replace: true }); }; return ( diff --git a/src/translations/views/TranslationsVouchers.tsx b/src/translations/views/TranslationsVouchers.tsx index d37a80c49..ac94da3b3 100644 --- a/src/translations/views/TranslationsVouchers.tsx +++ b/src/translations/views/TranslationsVouchers.tsx @@ -49,7 +49,7 @@ const TranslationsVouchers: React.FC = ({ stringifyQs({ activeField: field }), - true + { replace: true } ); const onUpdate = (data: UpdateVoucherTranslations) => { if (data.voucherTranslate.errors.length === 0) { @@ -58,11 +58,11 @@ const TranslationsVouchers: React.FC = ({ status: "success", text: intl.formatMessage(commonMessages.savedChanges) }); - navigate("?", true); + navigate("?", { replace: true }); } }; const onDiscard = () => { - navigate("?", true); + navigate("?", { replace: true }); }; return ( diff --git a/src/utils/handlers/dialogActionHandlers.ts b/src/utils/handlers/dialogActionHandlers.ts index 86254d6c5..f2618763c 100644 --- a/src/utils/handlers/dialogActionHandlers.ts +++ b/src/utils/handlers/dialogActionHandlers.ts @@ -28,7 +28,7 @@ function createDialogActionHandlers< id: undefined, ids: undefined }), - true + { replace: true } ); const open = (action: TAction, newParams?: TParams) => navigate( diff --git a/src/utils/handlers/sortHandler.ts b/src/utils/handlers/sortHandler.ts index d331194c4..7c0a4c69a 100644 --- a/src/utils/handlers/sortHandler.ts +++ b/src/utils/handlers/sortHandler.ts @@ -18,7 +18,7 @@ function createSortHandler( ...getSortUrlVariables(field, params), ...DEFAULT_INITIAL_PAGINATION_DATA }), - true + { replace: true } ); }