Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | 1x 1x 1x 1x 1x 1x 16x 16x 4x 4x 12x 12x 12x 16x 16x 16x 16x 16x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 12x 12x 16x 16x 16x 16x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 12x 12x 1x 12x 12x 12x 12x 12x 12x 12x 12x 12x 2x 2x 12x 10x 10x 47x 47x 37x 37x 47x 47x 47x 10x 10x 10x 12x 12x 12x 12x 6x 6x 6x 6x 21x 6x 6x 3x 3x 3x 3x 3x 3x 6x 6x 6x 4x 4x 4x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 20x 16x 16x 16x 4x 12x 12x 12x 1x 5x 5x 2x 2x 5x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x 5x 5x 5x | 'use client';
import { useState, useMemo } from 'react';
import { ChevronDown, ChevronUp, Shield, CheckCircle, Award } from 'lucide-react';
import { VerificationBadge } from './VerificationBadge';
import {
getLevelColors,
getLevelName,
LEVEL_ORDER,
DISPLAY_TIER_COLORS,
DISPLAY_TIER_NAMES,
DISPLAY_TIER_DESCRIPTIONS,
DISPLAY_TIER_ORDER,
type DisplayTier,
} from '@/lib/verification/colors';
import { getLevelIcon } from '@/lib/verification/icons';
import type { UserBadge, VerificationLevel } from '@/types/database';
/**
* Composite badge type for the 3-tier display hierarchy
*/
interface CompositeBadge {
id: DisplayTier;
name: string;
description: string;
icon: typeof Shield;
colors: {
bg: string;
text: string;
border: string;
icon: string;
};
verified: boolean;
}
interface VerificationBadgesProps {
badges: UserBadge[];
collapsible?: boolean;
maxVisible?: number;
showLevelHeaders?: boolean;
/** Show simplified composite badges (3-tier: Account, Identity, Proof-of-Work) */
showCompositeBadges?: boolean;
}
/**
* Display tier icons
*/
const TIER_ICONS: Record<DisplayTier, typeof Shield> = {
account_verified: CheckCircle,
identity_verified: Shield,
proof_of_work_verified: Award,
};
/**
* Compute 3-tier composite badges from individual verifications
*
* Level 1 (Blue) - Account Verified: ANY of email, phone, or Google/Apple OAuth
* Level 2 (Gold) - Identity Verified: Aadhaar + PAN verified
* Level 3 (Green) - Proof-of-Work Verified: Professional or reputation badges present
*/
function computeCompositeBadges(badges: UserBadge[] | undefined | null): CompositeBadge[] {
if (!badges || badges.length === 0) {
return [];
}
const badgeCodes = new Set(badges.map((b) => b.badge_code));
const badgeLevels = new Set(badges.map((b) => b.level));
const compositeBadges: CompositeBadge[] = [];
// Level 1: Account Verified - ANY one of email, phone, or OAuth
const hasEmailVerified = badgeCodes.has('email_verified') || badgeCodes.has('email');
const hasPhoneVerified = badgeCodes.has('phone_verified') || badgeCodes.has('phone');
const hasGoogleConnected = badgeCodes.has('google_connected') || badgeCodes.has('google');
const accountVerified = hasEmailVerified || hasPhoneVerified || hasGoogleConnected;
if (accountVerified) {
const colors = DISPLAY_TIER_COLORS.account_verified;
compositeBadges.push({
id: 'account_verified',
name: DISPLAY_TIER_NAMES.account_verified,
description: DISPLAY_TIER_DESCRIPTIONS.account_verified,
icon: TIER_ICONS.account_verified,
colors,
verified: true,
});
}
// Level 2: Identity Verified - Aadhaar + PAN
const hasAadhaar = badgeCodes.has('aadhaar');
const hasPan = badgeCodes.has('pan');
const identityVerified = hasAadhaar && hasPan;
if (identityVerified) {
const colors = DISPLAY_TIER_COLORS.identity_verified;
compositeBadges.push({
id: 'identity_verified',
name: DISPLAY_TIER_NAMES.identity_verified,
description: DISPLAY_TIER_DESCRIPTIONS.identity_verified,
icon: TIER_ICONS.identity_verified,
colors,
verified: true,
});
}
// Level 3: Proof-of-Work Verified - Any professional or reputation badge
const hasProofOfWork = badgeLevels.has('professional') || badgeLevels.has('reputation');
if (hasProofOfWork) {
const colors = DISPLAY_TIER_COLORS.proof_of_work_verified;
compositeBadges.push({
id: 'proof_of_work_verified',
name: DISPLAY_TIER_NAMES.proof_of_work_verified,
description: DISPLAY_TIER_DESCRIPTIONS.proof_of_work_verified,
icon: TIER_ICONS.proof_of_work_verified,
colors,
verified: true,
});
}
return compositeBadges;
}
export function VerificationBadges({
badges,
collapsible = true,
maxVisible = 3,
showLevelHeaders = true,
showCompositeBadges = true,
}: VerificationBadgesProps) {
const [isExpanded, setIsExpanded] = useState(false);
// Compute composite badges
const compositeBadges = useMemo(() => computeCompositeBadges(badges), [badges]);
if (!badges || badges.length === 0) {
return null;
}
// If showing composite badges and we have some, display them
if (showCompositeBadges && compositeBadges.length > 0) {
return (
<div className="flex flex-wrap gap-2">
{compositeBadges.map((badge) => {
const Icon = badge.icon;
return (
<div
key={badge.id}
className={`inline-flex items-center gap-1.5 rounded-full border px-3 py-1.5 ${badge.colors.bg} ${badge.colors.text} ${badge.colors.border}`}
title={badge.description}
>
<Icon className={`h-4 w-4 ${badge.colors.icon}`} />
<span className="text-sm font-medium">{badge.name}</span>
</div>
);
})}
</div>
);
}
// Fallback to individual badges if no composite badges qualify
// Group badges by level
const badgesByLevel = badges.reduce(
(acc, badge) => {
const level = badge.level as VerificationLevel;
if (!acc[level]) {
acc[level] = [];
}
acc[level].push(badge);
return acc;
},
{} as Record<VerificationLevel, UserBadge[]>
);
// Sort levels by order
const sortedLevels = LEVEL_ORDER.filter((level) => badgesByLevel[level]?.length > 0);
// For collapsible mode, show limited badges
const shouldCollapse = collapsible && badges.length > maxVisible && !isExpanded;
const visibleBadges = shouldCollapse ? badges.slice(0, maxVisible) : badges;
const hiddenCount = badges.length - maxVisible;
// Simple flat display when collapsed
if (shouldCollapse || !showLevelHeaders) {
return (
<div className="space-y-3">
<div className="flex flex-wrap gap-2">
{visibleBadges.map((badge) => (
<VerificationBadge key={badge.badge_code} badge={badge} size="sm" />
))}
{shouldCollapse && hiddenCount > 0 && (
<button
onClick={() => setIsExpanded(true)}
className="inline-flex items-center gap-1 rounded-full border bg-muted px-2 py-1 text-xs font-medium text-muted-foreground transition-colors hover:bg-muted/80"
>
<span>+{hiddenCount} more</span>
<ChevronDown className="h-3 w-3" />
</button>
)}
</div>
</div>
);
}
// Grouped display with level headers
return (
<div className="space-y-4">
{sortedLevels.map((level) => {
const levelBadges = badgesByLevel[level];
const colors = getLevelColors(level);
const LevelIcon = getLevelIcon(level);
return (
<div key={level} className={`rounded-lg border ${colors.border} overflow-hidden`}>
<div className={`px-3 py-2 ${colors.headerBg} flex items-center gap-2`}>
<LevelIcon className={`h-4 w-4 ${colors.icon}`} />
<span className={`text-sm font-medium ${colors.text}`}>{getLevelName(level)}</span>
<span className="text-xs text-muted-foreground">({levelBadges.length})</span>
</div>
<div className="flex flex-wrap gap-2 p-3">
{levelBadges.map((badge) => (
<VerificationBadge key={badge.badge_code} badge={badge} size="sm" />
))}
</div>
</div>
);
})}
{collapsible && badges.length > maxVisible && (
<button
onClick={() => setIsExpanded(!isExpanded)}
className="flex w-full items-center justify-center gap-1 py-2 text-sm text-muted-foreground transition-colors hover:text-foreground"
>
{isExpanded ? (
<>
<ChevronUp className="h-4 w-4" />
Show less
</>
) : (
<>
<ChevronDown className="h-4 w-4" />
Show all {badges.length} verifications
</>
)}
</button>
)}
</div>
);
}
/**
* Compact badge display for profile header (shows 3-tier composite badges)
*/
export function HighestVerificationBadge({ badges }: { badges: UserBadge[] }) {
// Compute composite badges
const compositeBadges = useMemo(() => computeCompositeBadges(badges), [badges]);
if (!badges || badges.length === 0) {
return null;
}
// If we have composite badges, show them (ordered by tier)
if (compositeBadges.length > 0) {
return (
<div className="flex flex-wrap gap-2">
{compositeBadges.map((badge) => {
const Icon = badge.icon;
return (
<div
key={badge.id}
className={`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 ${badge.colors.bg} ${badge.colors.text} ${badge.colors.border}`}
title={badge.description}
>
<Icon className={`h-3.5 w-3.5 ${badge.colors.icon}`} />
<span className="text-xs font-medium">{badge.name}</span>
</div>
);
})}
</div>
);
}
// Fallback: Show highest level badge if no composite badges qualify
const levelPriority: Record<VerificationLevel, number> = {
reputation: 4,
professional: 3,
government: 2,
account: 1,
};
const sortedBadges = [...badges].sort((a, b) => {
return (
levelPriority[b.level as VerificationLevel] - levelPriority[a.level as VerificationLevel]
);
});
const highestBadge = sortedBadges[0];
const colors = getLevelColors(highestBadge.level);
return (
<div
className={`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 ${colors.bg} ${colors.text} ${colors.border} `}
title={`${badges.length} verification${badges.length > 1 ? 's' : ''}`}
>
<Shield className={`h-3.5 w-3.5 ${colors.icon}`} />
<span className="text-xs font-medium">Verified</span>
{badges.length > 1 && <span className="text-xs opacity-75">+{badges.length - 1}</span>}
</div>
);
}
|