fixed image storage local on minio

This commit is contained in:
SlimusMinus
2026-07-10 01:24:58 +03:00
parent 7e9053e498
commit a344540267
9 changed files with 37 additions and 22 deletions

View File

@@ -24,21 +24,31 @@ export default function ProfileModal({ onClose, initialData = {} }) {
const existingImageUrl = initialData.avatar || null;
const {
imageFile,
displayImage,
images,
imgError,
compressing,
fileInputRef,
handleFileChange,
removeImage,
getExistingUrlsToKeep,
getFilesForUpload,
} = useImageUpload(existingImageUrl);
const currentImage = images[0];
const displayImage = currentImage?.preview ?? null;
const imageFile = currentImage?.file ?? null;
// ─── Field change handler ───────────────────────────────────────────────
const handleFieldChange = useCallback((key, value) => {
setForm(prev => ({ ...prev, [key]: value }));
setErrors(prev => ({ ...prev, [key]: "" }));
}, []);
// ─── Remove image handler (wraps removeImage with the only image id) ─────
const handleRemoveImage = useCallback(() => {
if (currentImage?.id) removeImage(currentImage.id);
}, [currentImage, removeImage]);
// ─── Phone field change with formatting ──────────────────────────────────
const handlePhoneChange = useCallback((value) => {
const formatted = formatPhone(value);
@@ -53,13 +63,15 @@ export default function ProfileModal({ onClose, initialData = {} }) {
return;
}
const newAvatars = getFilesForUpload();
const keptExisting = getExistingUrlsToKeep();
const profileData = {
firstName: form.firstName.trim(),
lastName: form.lastName.trim(),
login: form.login.trim(),
phone: form.phone.trim(),
email: form.email.trim(),
avatar: imageFile || existingImageUrl,
avatar: newAvatars.length > 0 ? newAvatars[0] : (keptExisting.length > 0 ? keptExisting[0] : null),
};
const updatedUser = await updateProfile(user?.id, profileData);
@@ -82,7 +94,7 @@ export default function ProfileModal({ onClose, initialData = {} }) {
compressing={compressing}
fileInputRef={fileInputRef}
onFileChange={handleFileChange}
onRemove={removeImage}
onRemove={handleRemoveImage}
/>
<LoginField