Update 'next' package version and refactor user account handling

This commit updates the 'next' package from version 14.2.0 to 14.2.1 across various modules. It also refactors the code for user account handling to make it controlled by an enableTeamAccounts flag in the featureFlagsConfig, essentially allowing the enabling or disabling of the 'team accounts' feature according to the specified flag.
This commit is contained in:
giancarlo
2024-04-15 17:46:11 +08:00
parent 81e662e63d
commit 8627cdaf1f
13 changed files with 78 additions and 74 deletions

View File

@@ -8,7 +8,6 @@ import featureFlagsConfig from '~/config/feature-flags.config';
import pathsConfig from '~/config/paths.config'; import pathsConfig from '~/config/paths.config';
const features = { const features = {
enableTeamAccounts: featureFlagsConfig.enableTeamAccounts,
enableTeamCreation: featureFlagsConfig.enableTeamCreation, enableTeamCreation: featureFlagsConfig.enableTeamCreation,
}; };

View File

@@ -2,8 +2,11 @@ import { use } from 'react';
import { cookies } from 'next/headers'; import { cookies } from 'next/headers';
import { If } from '@kit/ui/if';
import { Sidebar, SidebarContent, SidebarNavigation } from '@kit/ui/sidebar'; import { Sidebar, SidebarContent, SidebarNavigation } from '@kit/ui/sidebar';
import { AppLogo } from '~/components/app-logo';
import featuresFlagConfig from '~/config/feature-flags.config';
import { personalAccountSidebarConfig } from '~/config/personal-account-sidebar.config'; import { personalAccountSidebarConfig } from '~/config/personal-account-sidebar.config';
// home imports // home imports
@@ -18,7 +21,15 @@ export function HomeSidebar() {
return ( return (
<Sidebar collapsed={collapsed}> <Sidebar collapsed={collapsed}>
<SidebarContent className={'my-4'}> <SidebarContent className={'my-4'}>
<HomeSidebarAccountSelector collapsed={collapsed} accounts={accounts} /> <If
condition={featuresFlagConfig.enableTeamAccounts}
fallback={<AppLogo className={'py-2'} />}
>
<HomeSidebarAccountSelector
collapsed={collapsed}
accounts={accounts}
/>
</If>
</SidebarContent> </SidebarContent>
<SidebarContent className={`h-[calc(100%-160px)] overflow-y-auto`}> <SidebarContent className={`h-[calc(100%-160px)] overflow-y-auto`}>

View File

@@ -2,12 +2,14 @@ import { cache } from 'react';
import { getSupabaseServerComponentClient } from '@kit/supabase/server-component-client'; import { getSupabaseServerComponentClient } from '@kit/supabase/server-component-client';
import featureFlagsConfig from '~/config/feature-flags.config';
import { Database } from '~/lib/database.types'; import { Database } from '~/lib/database.types';
export const loadUserWorkspace = cache(async () => { export const loadUserWorkspace = cache(async () => {
const client = getSupabaseServerComponentClient(); const client = getSupabaseServerComponentClient();
const loadAccounts = featureFlagsConfig.enableTeamAccounts;
const accounts = await loadUserAccounts(client); const accounts = loadAccounts ? await loadUserAccounts(client) : [];
const { data } = await client.auth.getSession(); const { data } = await client.auth.getSession();
return { return {

View File

@@ -60,7 +60,7 @@
"i18next": "^23.11.1", "i18next": "^23.11.1",
"i18next-resources-to-backend": "^1.2.1", "i18next-resources-to-backend": "^1.2.1",
"lucide-react": "^0.367.0", "lucide-react": "^0.367.0",
"next": "14.2.0", "next": "14.2.1",
"next-sitemap": "^4.2.3", "next-sitemap": "^4.2.3",
"next-themes": "0.3.0", "next-themes": "0.3.0",
"react": "18.2.0", "react": "18.2.0",

View File

@@ -46,7 +46,7 @@
"@types/react": "^18.2.77", "@types/react": "^18.2.77",
"date-fns": "^3.6.0", "date-fns": "^3.6.0",
"lucide-react": "^0.367.0", "lucide-react": "^0.367.0",
"next": "14.2.0", "next": "14.2.1",
"react": "18.2.0", "react": "18.2.0",
"react-hook-form": "^7.51.3", "react-hook-form": "^7.51.3",
"react-i18next": "^14.1.0", "react-i18next": "^14.1.0",

View File

@@ -36,7 +36,7 @@
"@types/react": "^18.2.77", "@types/react": "^18.2.77",
"@types/react-dom": "^18.2.25", "@types/react-dom": "^18.2.25",
"lucide-react": "^0.367.0", "lucide-react": "^0.367.0",
"next": "14.2.0", "next": "14.2.1",
"next-themes": "0.3.0", "next-themes": "0.3.0",
"react": "18.2.0", "react": "18.2.0",
"react-dom": "18.2.0", "react-dom": "18.2.0",

View File

@@ -33,7 +33,6 @@ interface AccountSelectorProps {
}>; }>;
features: { features: {
enableTeamAccounts: boolean;
enableTeamCreation: boolean; enableTeamCreation: boolean;
}; };
@@ -50,7 +49,6 @@ export function AccountSelector({
selectedAccount, selectedAccount,
onAccountChange, onAccountChange,
features = { features = {
enableTeamAccounts: true,
enableTeamCreation: true, enableTeamCreation: true,
}, },
collapsed = false, collapsed = false,
@@ -80,10 +78,6 @@ export function AccountSelector({
); );
}; };
if (!features.enableTeamAccounts) {
return null;
}
const selected = accounts.find((account) => account.value === value); const selected = accounts.find((account) => account.value === value);
const pictureUrl = personalData.data?.picture_url; const pictureUrl = personalData.data?.picture_url;
@@ -176,66 +170,64 @@ export function AccountSelector({
<CommandSeparator /> <CommandSeparator />
<If condition={features.enableTeamAccounts}> <If condition={accounts.length > 0}>
<If condition={accounts.length > 0}> <CommandGroup
<CommandGroup heading={
heading={ <Trans
<Trans i18nKey={'teams:yourTeams'}
i18nKey={'teams:yourTeams'} values={{ teamsCount: accounts.length }}
values={{ teamsCount: accounts.length }} />
/> }
} >
> {(accounts ?? []).map((account) => (
{(accounts ?? []).map((account) => ( <CommandItem
<CommandItem data-test={'account-selector-team'}
data-test={'account-selector-team'} data-name={account.label}
data-name={account.label} data-slug={account.value}
data-slug={account.value} className={cn(
className={cn( 'group flex justify-between transition-colors',
'group flex justify-between transition-colors', {
{ ['bg-muted']: value === account.value,
['bg-muted']: value === account.value, },
}, )}
)} key={account.value}
key={account.value} value={account.value ?? ''}
value={account.value ?? ''} onSelect={(currentValue) => {
onSelect={(currentValue) => { setValue(currentValue === value ? '' : currentValue);
setValue(currentValue === value ? '' : currentValue); setOpen(false);
setOpen(false);
if (onAccountChange) { if (onAccountChange) {
onAccountChange(currentValue); onAccountChange(currentValue);
} }
}} }}
> >
<div className={'flex items-center'}> <div className={'flex items-center'}>
<Avatar <Avatar
className={cn( className={cn(
'mr-2 h-6 w-6 border border-transparent', 'mr-2 h-6 w-6 border border-transparent',
{ {
['border-border']: value === account.value, ['border-border']: value === account.value,
['group-hover:border-border ']: ['group-hover:border-border ']:
value !== account.value, value !== account.value,
}, },
)} )}
> >
<AvatarImage src={account.image ?? undefined} /> <AvatarImage src={account.image ?? undefined} />
<AvatarFallback> <AvatarFallback>
{account.label ? account.label[0] : ''} {account.label ? account.label[0] : ''}
</AvatarFallback> </AvatarFallback>
</Avatar> </Avatar>
<span className={'mr-2 max-w-[165px] truncate'}> <span className={'mr-2 max-w-[165px] truncate'}>
{account.label} {account.label}
</span> </span>
</div> </div>
<Icon item={account.value ?? ''} /> <Icon item={account.value ?? ''} />
</CommandItem> </CommandItem>
))} ))}
</CommandGroup> </CommandGroup>
</If>
</If> </If>
</CommandList> </CommandList>
</Command> </Command>

View File

@@ -40,7 +40,7 @@
"@tanstack/react-table": "^8.16.0", "@tanstack/react-table": "^8.16.0",
"@types/react": "^18.2.77", "@types/react": "^18.2.77",
"lucide-react": "^0.367.0", "lucide-react": "^0.367.0",
"next": "14.2.0", "next": "14.2.1",
"react": "18.2.0", "react": "18.2.0",
"react-hook-form": "^7.51.3", "react-hook-form": "^7.51.3",
"zod": "^3.22.4" "zod": "^3.22.4"

View File

@@ -32,7 +32,7 @@
"@tanstack/react-query": "5.29.0", "@tanstack/react-query": "5.29.0",
"@types/react": "^18.2.77", "@types/react": "^18.2.77",
"lucide-react": "^0.367.0", "lucide-react": "^0.367.0",
"next": "14.2.0", "next": "14.2.1",
"react-hook-form": "^7.51.3", "react-hook-form": "^7.51.3",
"react-i18next": "^14.1.0", "react-i18next": "^14.1.0",
"sonner": "^1.4.41", "sonner": "^1.4.41",

View File

@@ -37,7 +37,7 @@
"class-variance-authority": "^0.7.0", "class-variance-authority": "^0.7.0",
"date-fns": "^3.6.0", "date-fns": "^3.6.0",
"lucide-react": "^0.367.0", "lucide-react": "^0.367.0",
"next": "14.2.0", "next": "14.2.1",
"react": "18.2.0", "react": "18.2.0",
"react-dom": "18.2.0", "react-dom": "18.2.0",
"react-hook-form": "^7.51.3", "react-hook-form": "^7.51.3",

View File

@@ -28,7 +28,7 @@
"@kit/tailwind-config": "workspace:*", "@kit/tailwind-config": "workspace:*",
"@kit/tsconfig": "workspace:*", "@kit/tsconfig": "workspace:*",
"@supabase/supabase-js": "^2.42.3", "@supabase/supabase-js": "^2.42.3",
"next": "14.2.0", "next": "14.2.1",
"zod": "^3.22.4" "zod": "^3.22.4"
}, },
"eslintConfig": { "eslintConfig": {

View File

@@ -32,7 +32,7 @@
"@supabase/supabase-js": "^2.42.3", "@supabase/supabase-js": "^2.42.3",
"@tanstack/react-query": "5.29.0", "@tanstack/react-query": "5.29.0",
"@types/react": "^18.2.77", "@types/react": "^18.2.77",
"next": "14.2.0", "next": "14.2.1",
"react": "18.2.0", "react": "18.2.0",
"zod": "^3.22.4" "zod": "^3.22.4"
}, },

View File

@@ -59,7 +59,7 @@
"date-fns": "^3.6.0", "date-fns": "^3.6.0",
"eslint": "^8.57.0", "eslint": "^8.57.0",
"lucide-react": "^0.367.0", "lucide-react": "^0.367.0",
"next": "14.2.0", "next": "14.2.1",
"next-themes": "0.3.0", "next-themes": "0.3.0",
"prettier": "^3.2.5", "prettier": "^3.2.5",
"react-day-picker": "^8.10.0", "react-day-picker": "^8.10.0",