Skip to content

Commit

Permalink
Merge pull request #2107 from holium/fix-cypress-next-router
Browse files Browse the repository at this point in the history
Move to next/navigation
  • Loading branch information
gdbroman authored Nov 8, 2023
2 parents 27aaeac + 57c677b commit a0d4967
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 37 deletions.
29 changes: 0 additions & 29 deletions .github/workflows/cypress.yml

This file was deleted.

23 changes: 15 additions & 8 deletions hosting-holium-com/src/util/useNavigation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useMemo } from 'react';
import { useRouter } from 'next/router';
import { usePathname, useRouter } from 'next/navigation';

import { capitalizeFirstLetter } from '@holium/design-system/util';
import {
Expand All @@ -21,18 +21,19 @@ export const accountPageUrl: Record<string, OnboardingPage> = {

export const useNavigation = () => {
const router = useRouter();
const pathname = usePathname();

const currentAccountSection = useMemo(() => {
const isAccountSection = router.pathname.split('/')[1] === 'account';
const isAccountSection = pathname.split('/')[1] === 'account';
if (!isAccountSection) return null;

const path = router.pathname.split('/')[2] ?? SidebarSection.Hosting;
const path = pathname.split('/')[2] ?? SidebarSection.Hosting;
const eachWordCapitalized = path
.split('-')
.map((word) => capitalizeFirstLetter(word))
.join(' ');
return eachWordCapitalized as SidebarSection;
}, [router.pathname]);
}, [pathname]);

const goToPage = useCallback(
(
Expand All @@ -45,17 +46,23 @@ export const useNavigation = () => {
product_type?: ThirdEarthProductType;
}
) => {
const path =
page + (params ? `?${new URLSearchParams(params).toString()}` : '');
return router.push(path);
try {
const path =
page + (params ? `?${new URLSearchParams(params).toString()}` : '');
router.push(path);
return Promise.resolve(true);
} catch (e) {
console.error(e);
return Promise.resolve(false);
}
},
[router]
);

const logout = useCallback(() => {
goToPage('/login');
OnboardingStorage.reset();
}, [router]);
}, [goToPage]);

return { currentAccountSection, goToPage, logout };
};

1 comment on commit a0d4967

@vercel
Copy link

@vercel vercel bot commented on a0d4967 Nov 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

hosting-holium-com – ./hosting-holium-com

hosting.holium.com
realm-onboarding.vercel.app
hosting-holium-com-holium.vercel.app
hosting-holium-com-git-master-holium.vercel.app

Please sign in to comment.