diff --git a/packages/ui/components/sections/Navbar.tsx b/packages/ui/components/sections/Navbar.tsx index 7275c16069..08dc8b1e13 100644 --- a/packages/ui/components/sections/Navbar.tsx +++ b/packages/ui/components/sections/Navbar.tsx @@ -1,6 +1,6 @@ import { Container, createStyles, Flex, Group, rem, UnstyledButton, useMantineTheme } from '@mantine/core' import Image from 'next/image' -import { useRouter } from 'next/router' +import { type NextRouter, useRouter } from 'next/router' import { useTranslation } from 'next-i18next' import { navbarEvent } from '@weareinreach/analytics/events' @@ -120,10 +120,29 @@ const EditModeBar = () => { deletedNotification() }, }) + const getExitEditPathname = (): NextRouter['pathname'] => { + switch (router.pathname) { + case '/org/[slug]/edit': { + return '/org/[slug]' + } + case '/org/[slug]/[orgLocationId]/edit': { + return '/org/[slug]/[orgLocationId]' + } + case '/org/[slug]/[orgLocationId]/edit/[orgServiceId]': { + return '/org/[slug]/[orgLocationId]' + } + default: { + return router.pathname + } + } + } return ( - + router.replace({ pathname: getExitEditPathname(), query: router.query })} + > {t('exit.edit-mode')}