Update ProfileModal

This commit is contained in:
Sosthene 2025-06-13 20:26:50 +02:00
parent a25e1b4ae5
commit 8636d37d29

View File

@ -6,7 +6,7 @@ import type { ProfileData } from '../sdk/models/ProfileData';
interface ProfileModalProps {
isOpen: boolean;
onClose: () => void;
onSubmit: (profileData: ProfileData) => void;
onSubmit: (profileData: ProfileData, validatorId: string | null, ownerId: string | null) => void;
initialData?: Partial<ProfileData>;
}
@ -23,6 +23,10 @@ function ProfileModal({ isOpen, onClose, onSubmit, initialData = {} }: ProfileMo
idDocument: initialData.idDocument || null,
idCertified: false,
});
const [validatorId, setValidatorId] = useState<string | null>(null);
const [ownerId, setOwnerId] = useState<string | null>(null);
const [isOwnProfile, setIsOwnProfile] = useState<boolean>(false);
const [errorMessage, setErrorMessage] = useState<string | null>(null);
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const { name, type, files, value } = e.target;
@ -44,7 +48,12 @@ function ProfileModal({ isOpen, onClose, onSubmit, initialData = {} }: ProfileMo
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
onSubmit(profileData);
if (!validatorId && !ownerId) {
setErrorMessage("Please set either a Validator ID or an Owner ID.");
return;
}
setErrorMessage(null);
onSubmit(profileData, validatorId, ownerId);
};
return (
@ -176,6 +185,45 @@ function ProfileModal({ isOpen, onClose, onSubmit, initialData = {} }: ProfileMo
</div>
</div>
<div className="form-section">
<h3 className="section-title">Profil</h3>
<button type="button" onClick={() => setIsOwnProfile(!isOwnProfile)}>
{isOwnProfile ? "Je veux faire valider mon profil" : "Je valide le profil d'un utilisateur"}</button>
{isOwnProfile ? (
<div className="form-field">
<label htmlFor="validatorId">ID du validateur</label>
<input
type="text"
id="validatorId"
name="validatorId"
value={validatorId || ''}
onChange={(e) => {
setValidatorId(e.target.value);
setOwnerId(null);
}}
placeholder="ID du validateur"
/>
</div>
) : (
<div className="form-field">
<label htmlFor="ownerId">ID de l'utilisateur</label>
<input
type="text"
id="ownerId"
name="ownerId"
value={ownerId || ''}
onChange={(e) => {
setOwnerId(e.target.value);
setValidatorId(null);
}}
placeholder="ID de l'utilisateur"
/>
</div>
)}
</div>
{errorMessage && <div className="error-message">{errorMessage}</div>}
<div className="form-actions">
<button type="button" className="btn-cancel" onClick={onClose}>Annuler</button>
<button type="submit" className="btn-submit">Créer le profil</button>