import { useEffect, useState } from "react" import { Link, useParams } from "react-router-dom" import { ArrowLeft, Clock3, ClipboardList, Mail, Phone, Shield, User, UsersRound, X, } from "lucide-react" import { toast } from "sonner" import { Badge } from "../../components/ui/badge" import { Button } from "../../components/ui/button" import { Card, CardContent, CardHeader, CardTitle } from "../../components/ui/card" import { Avatar, AvatarFallback } from "../../components/ui/avatar" import { Separator } from "../../components/ui/separator" import { cn } from "../../lib/utils" import { notifyApiError } from "../../lib/apiErrors" import { formatTeamRoleLabel } from "../../lib/teamRoles" import { DisplayValue, NOT_ASSIGNED_LABEL, UnassignedLabel, displayValue, isUnassignedLabel } from "../../lib/displayValue" import { getTeamMemberById, updateTeamMemberStatus } from "../../api/team.api" import type { TeamMemberDetail } from "../../types/team.types" import { ActivityLogListPanel } from "../user-log/components/ActivityLogListPanel" function formatStatusLabel(status: string): string { const value = status.trim() if (!value) return NOT_ASSIGNED_LABEL return value .split("_") .map((part) => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase()) .join(" ") } function formatDate(dateStr: string | null | undefined): string { if (!dateStr?.trim()) return NOT_ASSIGNED_LABEL const date = new Date(dateStr) if (Number.isNaN(date.getTime())) return dateStr return date.toLocaleDateString(undefined, { year: "numeric", month: "long", day: "numeric", }) } function formatDateTime( dateStr: string | null | undefined, emptyLabel: string = NOT_ASSIGNED_LABEL, ): string { if (!dateStr?.trim()) return emptyLabel const date = new Date(dateStr) if (Number.isNaN(date.getTime())) return dateStr return date.toLocaleString(undefined, { year: "numeric", month: "short", day: "numeric", hour: "2-digit", minute: "2-digit", }) } function getRelativeTime(dateStr: string | null | undefined): string { if (!dateStr?.trim()) return "Never" const now = new Date() const date = new Date(dateStr) if (Number.isNaN(date.getTime())) return NOT_ASSIGNED_LABEL const diffMs = now.getTime() - date.getTime() const diffMins = Math.floor(diffMs / 60000) const diffHours = Math.floor(diffMs / 3600000) const diffDays = Math.floor(diffMs / 86400000) if (diffMins < 1) return "Just now" if (diffMins < 60) return `${diffMins}m ago` if (diffHours < 24) return `${diffHours}h ago` if (diffDays < 7) return `${diffDays}d ago` return formatDate(dateStr) } function getStatusClasses(status: string): string { const normalized = status.trim().toLowerCase() if (normalized === "active") { return "bg-mint-500/15 text-mint-500 border border-mint-500/25" } if (normalized === "invited" || normalized === "pending") { return "bg-gold-100 text-gold-600 border border-gold-300/40" } return "bg-destructive/15 text-destructive border border-destructive/25" } function getRoleBadgeClasses(role: string): string { const normalized = role.trim().toLowerCase() switch (normalized) { case "super_admin": return "bg-brand-500/15 text-brand-600 border border-brand-500/25" case "admin": return "bg-brand-100 text-brand-600 border border-brand-200" case "content_manager": return "bg-mint-100 text-mint-500 border border-mint-300/40" case "instructor": return "bg-gold-100 text-gold-600 border border-gold-300/40" case "support_agent": return "bg-orange-100 text-orange-600 border border-orange-200" case "finance": return "bg-sky-100 text-sky-600 border border-sky-200" case "hr": return "bg-pink-100 text-pink-600 border border-pink-200" case "analyst": return "bg-violet-100 text-violet-600 border border-violet-200" default: return "bg-grayScale-100 text-grayScale-600 border border-grayScale-200" } } function LoadingSkeleton() { return (
{label}
{typeof value === "string" && isUnassignedLabel(value) ?
{label}
{typeof value === "string" && isUnassignedLabel(value) ?
{error || "Member not found"}
Team members
Member #{member.id} {member.department?.trim() ? ` ยท ${member.department.trim()}` : ""}
Bio
Platform audit trail for actions performed by this team member.
Are you sure you want to change the status of{" "} {fullName || "this team member"} to{" "} {confirmDialog.newStatus}?