-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Separate concerns + prop-driven tabs
- Loading branch information
Joel Anton
committed
Feb 12, 2024
1 parent
b1f6a24
commit 336aaa5
Showing
3 changed files
with
53 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,30 @@ | ||
import React from 'react'; | ||
|
||
import { HeaderLayout } from './layout/HeaderLayout'; | ||
import PageContainer from '../../components/layout/components/PageContainer'; | ||
import PageHeader from '../../components/layout/components/PageHeader'; | ||
import { GetStartedTabs } from './components/get-started-tabs/GetStartedTabs'; | ||
import { useAuthContext } from '../../components/providers/AuthProvider'; | ||
import { Center, Loader } from '@mantine/core'; | ||
import { colors } from '@novu/design-system'; | ||
import { useTabSearchParams } from './components/get-started-tabs/useGetStartedTabs'; | ||
|
||
const PAGE_TITLE = 'Get started'; | ||
|
||
export function GetStartedPage() { | ||
const { currentOrganization } = useAuthContext(); | ||
const { currentTab, setTab } = useTabSearchParams(); | ||
|
||
return ( | ||
<PageContainer title={PAGE_TITLE}> | ||
<HeaderLayout> | ||
<PageHeader title={PAGE_TITLE} /> | ||
</HeaderLayout> | ||
<GetStartedTabs /> | ||
{currentOrganization ? ( | ||
<GetStartedTabs currentTab={currentTab} setTab={setTab} /> | ||
) : ( | ||
<Center> | ||
<Loader color={colors.error} size={32} /> | ||
</Center> | ||
)} | ||
</PageContainer> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
apps/web/src/pages/get-started/components/get-started-tabs/useGetStartedTabs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { URLSearchParamsInit, useSearchParams } from 'react-router-dom'; | ||
import { OnboardingUseCasesTabsEnum } from '../../consts/OnboardingUseCasesTabsEnum'; | ||
|
||
const TAB_SEARCH_PARAM_NAME = 'tab'; | ||
const DEFAULT_TAB: OnboardingUseCasesTabsEnum = OnboardingUseCasesTabsEnum.IN_APP; | ||
|
||
interface GetStartedTabSearchParams { | ||
[TAB_SEARCH_PARAM_NAME]: OnboardingUseCasesTabsEnum; | ||
} | ||
|
||
const DEFAULT_PARAMS: GetStartedTabSearchParams = { | ||
[TAB_SEARCH_PARAM_NAME]: DEFAULT_TAB, | ||
} satisfies URLSearchParamsInit; | ||
|
||
export const useTabSearchParams = () => { | ||
const [params, setParams] = useSearchParams(DEFAULT_PARAMS as unknown as URLSearchParamsInit); | ||
|
||
const setTab = (tab: OnboardingUseCasesTabsEnum) => { | ||
setParams({ [TAB_SEARCH_PARAM_NAME]: tab }); | ||
}; | ||
|
||
const currentTab = (params.get(TAB_SEARCH_PARAM_NAME) as OnboardingUseCasesTabsEnum) ?? DEFAULT_TAB; | ||
|
||
return { | ||
currentTab, | ||
setTab, | ||
}; | ||
}; |