/*
Copyright (C) 2023-2026 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
For commercial licensing, please contact support@quantumnous.com
*/
import { Shield, Key, Trash2 } from 'lucide-react'
import { useTranslation } from 'react-i18next'
import { useDialogs } from '@/hooks/use-dialog'
import { Card, CardContent, CardHeader } from '@/components/ui/card'
import { Skeleton } from '@/components/ui/skeleton'
import { TitledCard } from '@/components/ui/titled-card'
import type { UserProfile } from '../types'
import { AccessTokenDialog } from './dialogs/access-token-dialog'
import { ChangePasswordDialog } from './dialogs/change-password-dialog'
import { DeleteAccountDialog } from './dialogs/delete-account-dialog'
// ============================================================================
// Profile Security Card Component
// ============================================================================
interface ProfileSecurityCardProps {
profile: UserProfile | null
loading: boolean
}
type DialogKey = 'password' | 'token' | 'delete'
export function ProfileSecurityCard({
profile,
loading,
}: ProfileSecurityCardProps) {
const { t } = useTranslation()
const dialogs = useDialogs()
if (loading) {
return (
{Array.from({ length: 3 }).map((_, i) => (
))}
)
}
if (!profile) return null
const securityActions = [
{
icon: Shield,
title: t('Change Password'),
description: t('Update your password to keep your account secure'),
action: () => dialogs.open('password'),
variant: 'default' as const,
},
{
icon: Key,
title: t('Access Token'),
description: t('Generate and manage your API access token'),
action: () => dialogs.open('token'),
variant: 'default' as const,
},
{
icon: Trash2,
title: t('Delete Account'),
description: t('Permanently delete your account and all data'),
action: () => dialogs.open('delete'),
variant: 'destructive' as const,
},
]
return (
<>
}
>
{securityActions.map((item) => (
))}
{/* Dialogs */}
open ? dialogs.open('password') : dialogs.close('password')
}
username={profile.username}
/>
open ? dialogs.open('token') : dialogs.close('token')
}
/>
open ? dialogs.open('delete') : dialogs.close('delete')
}
username={profile.username}
/>
>
)
}