Information Update

This commit is contained in:
Nati
2026-08-17 07:36:44 +00:00
parent 1f2261a68b
commit ef3a59e617

View File

@@ -1,5 +1,6 @@
import { useRef, useState } from 'react';
import { useEffect, useRef, useState } from 'react';
import { useCurrentProfile, useUpdateMyProfileMutation } from '@ema-platform/auth';
import { useAppSelector } from '../../../store/hooks';
import { useSaveMyAddressMutation } from '../../profile/api/address-api';
import {
Alert,
@@ -252,7 +253,8 @@ export function SeafarerRegistrationPage() {
// Every signed-in user already has a profile (`/profiles/me` provisions
// one), so registering fills that row in rather than creating a second —
// POST /profiles trips the unique user_id constraint.
const { profileId } = useCurrentProfile();
const { profileId, profile } = useCurrentProfile();
const user = useAppSelector((state) => state.auth.user);
const [active, setActive] = useState(0);
const [completed, setCompleted] = useState<number[]>([]);
const [submitting, setSubmitting] = useState(false);
@@ -290,6 +292,27 @@ export function SeafarerRegistrationPage() {
const setFile = (key: string) => (f: File | null) =>
setFiles((prev) => ({ ...prev, [key]: f }));
// Signup already asked for name, email and phone — start from those (and
// whatever is on the profile) instead of making the applicant retype them.
// Only blank fields are filled, so nothing typed here is overwritten.
useEffect(() => {
const [enFirst = '', ...enRest] = (user?.name.en ?? '').trim().split(/\s+/);
const [amFirst = '', ...amRest] = (user?.name.am ?? '').trim().split(/\s+/);
const orEmpty = (v?: string | null) => v ?? '';
// Profile stores MALE / SINGLE; the selects here list Male / Single.
const title = (v: string) => v.charAt(0) + v.slice(1).toLowerCase();
setFirstName((c) => c.en ? c : { en: profile?.firstName || enFirst, am: amFirst });
setMiddleName((c) => c.en ? c : { en: profile?.middleName || enRest.slice(0, -1).join(' '), am: amRest.slice(0, -1).join(' ') });
setLastName((c) => c.en ? c : { en: profile?.lastName || orEmpty(enRest.at(-1)), am: orEmpty(amRest.at(-1)) });
if (profile?.gender) setGender((c) => c ?? title(profile.gender));
if (profile?.dob) setDob((c) => c ?? new Date(profile.dob));
if (profile?.pob) setPlaceOfBirth((c) => c || profile.pob);
if (profile?.maritalStatus) setMaritalStatus((c) => c ?? title(profile.maritalStatus));
setEmail((c) => c || profile?.address?.email || user?.email || '');
setMobile((c) => c || profile?.address?.primaryPhoneNumber || user?.phoneNumber || '');
if (profile?.address?.idNumber) setNationalIdNumber((c) => c || profile.address.idNumber);
}, [user, profile]);
const canNext = () => {
if (active === 0) return !!firstName.en.trim() && !!lastName.en.trim() && !!gender && !!dob && !!placeOfBirth && !!nationality && !!nationalIdNumber.trim();
if (active === 1) return !!mobile.trim() && !!email.trim() && !!locationId;