Исправления формы желаний, очистка кода
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 46s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 46s
This commit is contained in:
@@ -65,24 +65,44 @@ function WishlistForm({ onNavigate, wishlistId, editConditionIndex }) {
|
||||
}
|
||||
}, [wishlistId, tasks, projects])
|
||||
|
||||
// Сброс формы при размонтировании компонента
|
||||
// Сброс формы при размонтировании компонента или при изменении wishlistId на undefined
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
resetForm()
|
||||
}
|
||||
}, [])
|
||||
}, [wishlistId])
|
||||
|
||||
// Открываем форму редактирования условия, если передан editConditionIndex
|
||||
useEffect(() => {
|
||||
if (editConditionIndex !== undefined && editConditionIndex !== null && unlockConditions.length > editConditionIndex) {
|
||||
setEditingConditionIndex(editConditionIndex)
|
||||
setShowConditionForm(true)
|
||||
} else if (editConditionIndex === undefined || editConditionIndex === null) {
|
||||
// Закрываем форму условия, если editConditionIndex сброшен
|
||||
setEditingConditionIndex(null)
|
||||
setShowConditionForm(false)
|
||||
}
|
||||
}, [editConditionIndex, unlockConditions])
|
||||
|
||||
const loadWishlist = async () => {
|
||||
setLoadingWishlist(true)
|
||||
try {
|
||||
// Сначала очищаем форму, чтобы удалить старые данные
|
||||
setName('')
|
||||
setPrice('')
|
||||
setLink('')
|
||||
setImageUrl(null)
|
||||
setImageFile(null)
|
||||
setUnlockConditions([])
|
||||
setError('')
|
||||
setShowCropper(false)
|
||||
setCrop({ x: 0, y: 0 })
|
||||
setZoom(1)
|
||||
setCroppedAreaPixels(null)
|
||||
setShowConditionForm(false)
|
||||
setEditingConditionIndex(null)
|
||||
setToastMessage(null)
|
||||
|
||||
const response = await authFetch(`${API_URL}/${wishlistId}`)
|
||||
if (!response.ok) {
|
||||
throw new Error('Ошибка загрузки желания')
|
||||
@@ -102,6 +122,8 @@ function WishlistForm({ onNavigate, wishlistId, editConditionIndex }) {
|
||||
start_date: cond.start_date || null,
|
||||
display_order: idx,
|
||||
})))
|
||||
} else {
|
||||
setUnlockConditions([])
|
||||
}
|
||||
} catch (err) {
|
||||
setError(err.message)
|
||||
|
||||
Reference in New Issue
Block a user