feat(2FA): add user security settings page
This commit is contained in:
1 parent
d8006317c8
commit
1b78192253
3 files changed
+111
-1
No files matched your search
@@ -2,7 +2,7 @@ import { Column, Focusable, Row, Text, Tooltip, TooltipTrigger } from '@umami/re
|
||||
import Link from '@/components/common/Link';
|
||||
import { IconLabel } from '@/components/common/IconLabel';
|
||||
import { useMessages, useNavigation } from '@/components/hooks';
|
||||
import { ArrowLeft, Settings2, UserCircle, Users } from '@/components/icons';
|
||||
import { ArrowLeft, Settings2, ShieldCheck, UserCircle, Users } from '@/components/icons';
|
||||
|
||||
export function SettingsNav({
|
||||
isCollapsed,
|
||||
@@ -41,6 +41,12 @@ export function SettingsNav({
|
||||
path: renderUrl('/settings/teams'),
|
||||
icon: <Users />,
|
||||
},
|
||||
{
|
||||
id: 'security',
|
||||
label: t(labels.security),
|
||||
path: renderUrl('/settings/security'),
|
||||
icon: <ShieldCheck />,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
'use client';
|
||||
import { Column, Row, Switch, Text, Tooltip, TooltipTrigger } from '@umami/react-zen';
|
||||
import { useState } from 'react';
|
||||
import { Badge } from '@/components/common/Badge';
|
||||
import { PageBody } from '@/components/common/PageBody';
|
||||
import { PageHeader } from '@/components/common/PageHeader';
|
||||
import { Panel } from '@/components/common/Panel';
|
||||
import { useMessages, useTwoFactorStatusQuery } from '@/components/hooks';
|
||||
import { TwoFactorDisableModal } from '@/components/modals/TwoFactorDisableModal';
|
||||
import { TwoFactorSetupModal } from '@/components/modals/TwoFactorSetupModal';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
|
||||
export function UserSecurityPage() {
|
||||
const { t, labels, messages } = useMessages();
|
||||
const { data: status, isLoading } = useTwoFactorStatusQuery(true);
|
||||
const queryClient = useQueryClient();
|
||||
const [showSetup, setShowSetup] = useState(false);
|
||||
const [showDisable, setShowDisable] = useState(false);
|
||||
|
||||
const isEnabled = status?.isEnabled ?? false;
|
||||
const isRequired = status?.isRequired ?? false;
|
||||
|
||||
const handleToggle = (value: boolean) => {
|
||||
if (value) {
|
||||
setShowSetup(true);
|
||||
} else {
|
||||
setShowDisable(true);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSetupClose = () => {
|
||||
setShowSetup(false);
|
||||
queryClient.invalidateQueries({ queryKey: ['2fa-status'] });
|
||||
};
|
||||
|
||||
const handleDisableSuccess = () => {
|
||||
setShowDisable(false);
|
||||
queryClient.invalidateQueries({ queryKey: ['2fa-status'] });
|
||||
};
|
||||
|
||||
if (isLoading) return null;
|
||||
|
||||
return (
|
||||
<PageBody>
|
||||
<Column gap="6">
|
||||
<PageHeader title={t(labels.security)} />
|
||||
<Panel>
|
||||
<Column gap="4">
|
||||
<Row alignItems="center" gap="3">
|
||||
<Text weight="bold">{t(labels.twoFactorAuth)}</Text>
|
||||
{isEnabled ? (
|
||||
<Badge variant="good">{t(labels.twoFactorActive)}</Badge>
|
||||
) : (
|
||||
<Badge variant="gray">{t(labels.twoFactorStatusNotConfigured)}</Badge>
|
||||
)}
|
||||
</Row>
|
||||
|
||||
{isEnabled ? (
|
||||
<Text>{t(messages.twoFactorActiveDescription)}</Text>
|
||||
) : (
|
||||
<Text>{t(messages.twoFactorUserDescription)}</Text>
|
||||
)}
|
||||
|
||||
<TooltipTrigger isDisabled={!(isEnabled && isRequired)}>
|
||||
<Row alignItems="center" gap="3">
|
||||
<Switch
|
||||
isSelected={isEnabled}
|
||||
isDisabled={isEnabled && isRequired}
|
||||
onChange={handleToggle}
|
||||
/>
|
||||
<Text>{t(labels.twoFactorEnable)}</Text>
|
||||
</Row>
|
||||
<Tooltip>{t(messages.twoFactorRequiredMessage)}</Tooltip>
|
||||
</TooltipTrigger>
|
||||
|
||||
{isEnabled && isRequired && (
|
||||
<Text size="sm" color="muted">
|
||||
{t(messages.twoFactorRequiredMessage)}
|
||||
</Text>
|
||||
)}
|
||||
</Column>
|
||||
</Panel>
|
||||
</Column>
|
||||
|
||||
{showSetup && <TwoFactorSetupModal required={false} onClose={handleSetupClose} />}
|
||||
{showDisable && (
|
||||
<TwoFactorDisableModal
|
||||
onClose={() => setShowDisable(false)}
|
||||
onSuccess={handleDisableSuccess}
|
||||
/>
|
||||
)}
|
||||
</PageBody>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import type { Metadata } from 'next';
|
||||
import { UserSecurityPage } from './UserSecurityPage';
|
||||
|
||||
export default function () {
|
||||
return <UserSecurityPage />;
|
||||
}
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: 'Security',
|
||||
};
|
||||
Reference in new issue
Block a user