fixed get profile avatar and get user from back
This commit is contained in:
@@ -22,6 +22,7 @@ export default function ProfileModal({ onClose, initialData = {} }) {
|
||||
const [errors, setErrors] = useState({});
|
||||
|
||||
const existingImageUrl = initialData.avatar || null;
|
||||
const existingImages = existingImageUrl ? [existingImageUrl] : [];
|
||||
|
||||
const {
|
||||
images,
|
||||
@@ -32,7 +33,7 @@ export default function ProfileModal({ onClose, initialData = {} }) {
|
||||
removeImage,
|
||||
getExistingUrlsToKeep,
|
||||
getFilesForUpload,
|
||||
} = useImageUpload(existingImageUrl);
|
||||
} = useImageUpload(existingImages);
|
||||
|
||||
const currentImage = images[0];
|
||||
const displayImage = currentImage?.preview ?? null;
|
||||
@@ -58,15 +59,21 @@ export default function ProfileModal({ onClose, initialData = {} }) {
|
||||
return;
|
||||
}
|
||||
|
||||
const newAvatars = getFilesForUpload();
|
||||
const keptExisting = getExistingUrlsToKeep();
|
||||
const newAvatars = getFilesForUpload();
|
||||
const keptExisting = getExistingUrlsToKeep();
|
||||
|
||||
// Пользователь удалил старый аватар и не выбрал новый —
|
||||
// явно сигналим бэку, что аватар нужно снести.
|
||||
const removeAvatar = !!existingImageUrl && newAvatars.length === 0 && keptExisting.length === 0;
|
||||
|
||||
const profileData = {
|
||||
firstName: form.firstName.trim(),
|
||||
lastName: form.lastName.trim(),
|
||||
login: form.login.trim(),
|
||||
phone: form.phone.trim(),
|
||||
email: form.email.trim(),
|
||||
avatar: newAvatars.length > 0 ? newAvatars[0] : (keptExisting.length > 0 ? keptExisting[0] : null),
|
||||
avatar: newAvatars.length > 0 ? newAvatars[0] : null,
|
||||
removeAvatar,
|
||||
};
|
||||
|
||||
const result = await updateProfile(user?.id, profileData);
|
||||
|
||||
Reference in New Issue
Block a user