Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 35 additions & 21 deletions src/components/Profile/ProfileEditForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,37 @@ import styles from './ProfileEditForm.module.css';
import { AvatarUpload } from './AvatarUpload';
import { ProfileCompletion } from './ProfileCompletion';

interface UserProfileData {
firstName?: string;
lastName?: string;
email?: string;
phone?: string;
avatarUrl?: string;
dateOfBirth?: string;
address?: string;
city?: string;
country?: string;
}

interface UserProfile extends UserProfileData {
id: string;
firstName: string;
lastName: string;
email: string;
emailVerified?: boolean;
phoneVerified?: boolean;
isVerified?: boolean;
}

interface ProfileCompletionState {
completionScore: number;
isComplete: boolean;
missingFields: string[];
}

interface ProfileEditFormProps {
user?: {
id: string;
firstName: string;
lastName: string;
email: string;
phone?: string;
avatarUrl?: string;
emailVerified?: boolean;
phoneVerified?: boolean;
isVerified?: boolean;
dateOfBirth?: string;
address?: string;
city?: string;
country?: string;
};
onSubmit: (data: any) => Promise<void>;
user?: UserProfile;
onSubmit: (data: UserProfileData) => Promise<void>;
onAvatarUpload: (file: File) => Promise<void>;
isLoading?: boolean;
}
Expand All @@ -45,7 +59,7 @@ export const ProfileEditForm: React.FC<ProfileEditFormProps> = ({
const [errors, setErrors] = useState<Record<string, string>>({});
const [successMessage, setSuccessMessage] = useState('');
const [isSubmitting, setIsSubmitting] = useState(false);
const [profileCompletion, setProfileCompletion] = useState<any>(null);
const [profileCompletion, setProfileCompletion] = useState<ProfileCompletionState | null>(null);

useEffect(() => {
if (user) {
Expand All @@ -72,7 +86,7 @@ export const ProfileEditForm: React.FC<ProfileEditFormProps> = ({
}
}, [user]);

const calculateCompletion = (userData: any) => {
const calculateCompletion = (userData: UserProfileData): number => {
let score = 0;
const fields = [
userData.firstName,
Expand All @@ -91,7 +105,7 @@ export const ProfileEditForm: React.FC<ProfileEditFormProps> = ({
return score;
};

const calculateMissingFields = (userData: any) => {
const calculateMissingFields = (userData: UserProfileData): string[] => {
const missing = [];
if (!userData.firstName) missing.push('firstName');
if (!userData.lastName) missing.push('lastName');
Expand Down Expand Up @@ -180,9 +194,9 @@ export const ProfileEditForm: React.FC<ProfileEditFormProps> = ({
missingFields: calculateMissingFields(formData),
};
setProfileCompletion(completion);
} catch (error: any) {
} catch (error: unknown) {
setErrors({
submit: error.message || 'Failed to update profile',
submit: error instanceof Error ? error.message : 'Failed to update profile',
});
} finally {
setIsSubmitting(false);
Expand Down
Loading