B2B-30: hide 'create team' button from not super_admins
This commit is contained in:
@@ -24,6 +24,7 @@ import { cn } from '@kit/ui/utils';
|
||||
|
||||
import { CreateTeamAccountDialog } from '../../../team-accounts/src/components/create-team-account-dialog';
|
||||
import { usePersonalAccountData } from '../hooks/use-personal-account-data';
|
||||
import { useUserWorkspace } from '../hooks/use-user-workspace';
|
||||
|
||||
interface AccountSelectorProps {
|
||||
accounts: Array<{
|
||||
@@ -63,6 +64,7 @@ export function AccountSelector({
|
||||
const [isCreatingAccount, setIsCreatingAccount] = useState<boolean>(false);
|
||||
const { t } = useTranslation('teams');
|
||||
const personalData = usePersonalAccountData(userId);
|
||||
const { user } = useUserWorkspace();
|
||||
|
||||
const value = useMemo(() => {
|
||||
return selectedAccount ?? PERSONAL_ACCOUNT_SLUG;
|
||||
@@ -89,6 +91,16 @@ export function AccountSelector({
|
||||
<PersonIcon className="h-5 w-5" />
|
||||
);
|
||||
|
||||
const isSuperAdmin = useMemo(() => {
|
||||
const factors = user?.factors ?? [];
|
||||
const hasAdminRole = user?.app_metadata.role === 'super-admin';
|
||||
const hasTotpFactor = factors.some(
|
||||
(factor) => factor.factor_type === 'totp' && factor.status === 'verified',
|
||||
);
|
||||
|
||||
return hasAdminRole && hasTotpFactor;
|
||||
}, [user]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
@@ -172,7 +184,6 @@ export function AccountSelector({
|
||||
>
|
||||
<Command>
|
||||
<CommandInput placeholder={t('searchAccount')} className="h-9" />
|
||||
|
||||
<CommandList>
|
||||
<CommandGroup>
|
||||
<CommandItem
|
||||
@@ -251,7 +262,7 @@ export function AccountSelector({
|
||||
|
||||
<Separator />
|
||||
|
||||
<If condition={features.enableTeamCreation}>
|
||||
<If condition={features.enableTeamCreation && isSuperAdmin}>
|
||||
<div className={'p-1'}>
|
||||
<Button
|
||||
data-test={'create-team-account-trigger'}
|
||||
@@ -274,7 +285,7 @@ export function AccountSelector({
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
|
||||
<If condition={features.enableTeamCreation}>
|
||||
<If condition={features.enableTeamCreation && isSuperAdmin}>
|
||||
<CreateTeamAccountDialog
|
||||
isOpen={isCreatingAccount}
|
||||
setIsOpen={setIsCreatingAccount}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"tsx": true,
|
||||
"tailwind": {
|
||||
"config": "./tailwind.config.ts",
|
||||
"css": "../../apps/web/styles/globals.css",
|
||||
"css": "../../styles/globals.css",
|
||||
"baseColor": "slate",
|
||||
"cssVariables": true,
|
||||
"prefix": ""
|
||||
|
||||
Reference in New Issue
Block a user