'use client' import { useState, useEffect } from 'react' import { onboardingService } from '../services/onboarding.service' import type { EmployeeStatusResponse } from '../types/onboarding' interface EmployeeStatusCardProps { tenantId: number seqNo: number showActions?: boolean } export default function EmployeeStatusCard({ tenantId, seqNo, showActions = false, }: EmployeeStatusCardProps) { const [status, setStatus] = useState(null) const [isLoading, setIsLoading] = useState(true) const [error, setError] = useState('') const [successMessage, setSuccessMessage] = useState('') const [isOffboarding, setIsOffboarding] = useState(false) const fetchEmployeeStatus = async () => { setIsLoading(true) setError('') try { const data = await onboardingService.getEmployeeStatus(tenantId, seqNo) setStatus(data) } catch (err: any) { const message = err.response?.data?.detail || 'Failed to load employee status' setError(message) } finally { setIsLoading(false) } } useEffect(() => { fetchEmployeeStatus() }, [tenantId, seqNo]) const handleOffboard = async () => { if (!confirm('Are you sure you want to offboard this employee?')) { return } setIsOffboarding(true) setError('') setSuccessMessage('') try { const response = await onboardingService.offboardEmployee(tenantId, seqNo) setSuccessMessage(response.message) // Refresh status after offboarding await fetchEmployeeStatus() } catch (err: any) { const message = err.response?.data?.detail || 'Failed to offboard employee' setError(message) } finally { setIsOffboarding(false) } } const getEmploymentStatusBadge = (status: string) => { const colors: { [key: string]: string } = { active: 'bg-green-100 text-green-800', inactive: 'bg-gray-100 text-gray-800', resigned: 'bg-red-100 text-red-800', } return ( {status.charAt(0).toUpperCase() + status.slice(1)} ) } const getMembershipTypeBadge = (type: string) => { const colors: { [key: string]: string } = { permanent: 'bg-blue-100 text-blue-800', concurrent: 'bg-purple-100 text-purple-800', temporary: 'bg-yellow-100 text-yellow-800', } return ( {type.charAt(0).toUpperCase() + type.slice(1)} ) } if (isLoading) { return (
Loading employee status...
) } if (error && !status) { return (

{error}

) } if (!status) { return null } return (
{/* Success/Error Messages */} {successMessage && (
{successMessage}
)} {error && (
{error}
)} {/* Employee Basic Information */}

{status.employee.name}

{status.employee.tenant_emp_code}

{getEmploymentStatusBadge(status.employee.employment_status)}

Keycloak Username

{status.employee.keycloak_username}

Keycloak User ID

{status.employee.keycloak_user_id}

Hire Date

{status.employee.hire_date}

{status.employee.resign_date && (

Resign Date

{status.employee.resign_date}

)}

Storage Quota

{status.employee.storage_quota_gb} GB

Email Quota

{status.employee.email_quota_mb} MB

{/* Offboard Button */} {showActions && status.employee.employment_status === 'active' && (
)}
{/* Departments */}

Department Assignments

{status.departments.length === 0 ? (

No departments assigned

) : (
{status.departments.map((dept) => (

{dept.department_name}

{dept.position}

Joined: {new Date(dept.joined_at).toLocaleString()}

{getMembershipTypeBadge(dept.membership_type)}
))}
)}
{/* Roles */}

Role Assignments

{status.roles.length === 0 ? (

No roles assigned

) : (
{status.roles.map((role) => (

{role.role_name}

{role.role_code}

Assigned: {new Date(role.assigned_at).toLocaleString()}

))}
)}
{/* Services */}

Enabled Services

{status.services.length === 0 ? (

No services enabled

) : (
{status.services.map((service) => (

{service.service_name}

{service.service_code}
{(service.quota_gb || service.quota_mb) && (

Quota:{' '} {service.quota_gb && `${service.quota_gb} GB`} {service.quota_mb && `${service.quota_mb} MB`}

)}

Enabled: {new Date(service.enabled_at).toLocaleString()}

))}
)}
) }