"use client"
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import {
faUser,
faIdCard,
faGraduationCap,
faAddressCard,
faSchool,
faCalendarAlt,
faFlag,
faVenus,
faMars,
faEnvelope,
faPhone,
faMapMarkerAlt,
faPassport
} from '@fortawesome/free-solid-svg-icons';
import { useEffect, useState } from 'react';
import { getAccessToken } from '@/lib/auth';
import { IconDefinition } from '@fortawesome/fontawesome-svg-core';
type PersonalInfo = {
firstName: string;
middleName: string;
lastName: string;
maidenName: string;
dateOfBirth: string;
gender: string;
nationality: string;
citizenship: string;
scholarship: string;
currentPlan: string;
registryNumber: string;
studyGroup: string;
notes?: string;
index: string;
embg: string;
};
type BirthInfo = {
placeOfBirth: string;
municipalityOfBirth: string;
country: string;
};
type PreviousEducation = {
type: string;
profession: string;
average: string | number;
language: string;
country: string;
previousUniversity: string;
previousFaculty: string;
previousStudyMode: string;
};
type EnrollmentInfo = {
enrollmentYear: string | number;
status: string;
cycle: string;
program: string;
quota: string;
secondaryEducationNumber: string;
previousEducationCredits: string | number;
};
type Contact = {
placeOfResidence: string;
municipalityOfResidence: string;
country: string;
address: string;
temporaryAddress: string;
phone: string;
mobilePhone: string;
passportNumber: string;
passportExpiryDate: string;
email: string;
microsoftEmail: string;
};
type StudentProfile = {
personalInfo: PersonalInfo;
birthInfo: BirthInfo;
previousEducation: PreviousEducation;
enrollmentInfo: EnrollmentInfo;
contact: Contact;
};
interface InfoRowProps {
label: string;
value: string | number;
icon?: IconDefinition;
}
const InfoRow = ({ label, value, icon }: InfoRowProps) => (
{icon && }
{label}:
{value || "N/A"}
);
interface SectionProps {
title: string;
icon: IconDefinition;
children: React.ReactNode;
}
const Section = ({ title, icon, children }: SectionProps) => (
);
export default function ProfilePage() {
const [studentData, setStudentData] = useState(null);
const [isLoading, setIsLoading] = useState(true);
const [errorMessage, setErrorMessage] = useState(null);
useEffect(() => {
let cancelled = false;
async function load() {
setIsLoading(true);
setErrorMessage(null);
const token = getAccessToken();
if (!token) {
setErrorMessage('Not authenticated. Please login again.');
setIsLoading(false);
return;
}
try {
const response = await fetch('https://iknow-api.onrender.com/api/user/getUser', {
method: 'GET',
headers: {
Authorization: `Bearer ${token}`,
},
});
if (!response.ok) {
const text = await response.text().catch(() => '');
throw new Error(text || `Failed to load profile (${response.status})`);
}
const data = (await response.json()) as StudentProfile;
if (!cancelled) setStudentData(data);
} catch (err) {
if (!cancelled) {
setErrorMessage(err instanceof Error ? err.message : 'Failed to load profile.');
}
} finally {
if (!cancelled) setIsLoading(false);
}
}
void load();
return () => {
cancelled = true;
};
}, []);
if (isLoading) {
return (
);
}
if (errorMessage || !studentData) {
return (
{errorMessage ?? 'Failed to load profile.'}
);
}
const { personalInfo, birthInfo, previousEducation, enrollmentInfo, contact } = studentData;
return (
{/* Header */}
{personalInfo.firstName} {personalInfo.middleName} {personalInfo.lastName}
Индекс: {personalInfo.index} | ЕМБГ: {personalInfo.embg}
{enrollmentInfo.program}
{/* Profile Sections */}
{/* Personal Information */}
{personalInfo.notes && (
Забелешка:
{personalInfo.notes}
)}
{/* Birth Information */}
{/* Previous Education */}
{/* Enrollment Information */}
{/* Contact Information */}
);
}