fix(lib): auto close update position toast (#277)

* add close button to custom info modal

* auto close update position toat

* Revert "add close button to custom info modal"

This reverts commit cf5b9a407effe0772ed622ce2369cf16e0b82175.

* fix: reset position for new items without text
This commit is contained in:
Anton Tranelis 2025-07-03 13:18:10 +02:00 committed by GitHub
parent c92695eea7
commit 045ec726eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 49 additions and 10 deletions

View File

@ -20,7 +20,7 @@ export const SelectPosition = ({
</label>
<div className='tw:alert tw:bg-base-100 tw:text-base-content'>
<div>
{selectNewItemPosition && 'text' in selectNewItemPosition && (
{selectNewItemPosition && 'layer' in selectNewItemPosition && (
<span className='tw:text-lg'>
Select new position of <b>{selectNewItemPosition.name}</b> on the map!
</span>

View File

@ -69,7 +69,7 @@ function useSelectPositionManager(): {
})
setSelectPosition(null)
}
if ('text' in selectPosition) {
if ('layer' in selectPosition) {
// if selectPosition is an Item
const position =
mapClicked?.position.lng &&
@ -101,9 +101,9 @@ function useSelectPositionManager(): {
success = true
} catch (error: unknown) {
if (error instanceof Error) {
toast.update(toastId, { render: error.message, type: 'error' })
toast.update(toastId, { render: error.message, type: 'error', autoClose: 5000 })
} else if (typeof error === 'string') {
toast.update(toastId, { render: error, type: 'error' })
toast.update(toastId, { render: error, type: 'error', autoClose: 5000 })
} else {
throw error
}
@ -115,6 +115,7 @@ function useSelectPositionManager(): {
render: 'Item position updated',
type: 'success',
isLoading: false,
autoClose: 5000,
})
setSelectPosition(null)
setMarkerClicked(null)
@ -125,6 +126,8 @@ function useSelectPositionManager(): {
render: "you don't have permission to add items to " + markerClicked?.name,
type: 'error',
isLoading: false,
autoClose: 5000,
closeButton: true,
})
}
}
@ -140,16 +143,34 @@ function useSelectPositionManager(): {
success = true
} catch (error: unknown) {
if (error instanceof Error) {
toast.update(toastId, { render: error.message, type: 'error', isLoading: false })
toast.update(toastId, {
render: error.message,
type: 'error',
isLoading: false,
autoClose: 5000,
closeButton: true,
})
} else if (typeof error === 'string') {
toast.update(toastId, { render: error, type: 'error', isLoading: false })
toast.update(toastId, {
render: error,
type: 'error',
isLoading: false,
autoClose: 5000,
closeButton: true,
})
} else {
throw error
}
}
if (success) {
updateItem(updatedItem)
toast.update(toastId, { render: 'Item position updated', type: 'success', isLoading: false })
toast.update(toastId, {
render: 'Item position updated',
type: 'success',
isLoading: false,
autoClose: 5000,
closeButton: true,
})
}
}
@ -168,16 +189,34 @@ function useSelectPositionManager(): {
success = true
} catch (error: unknown) {
if (error instanceof Error) {
toast.update(toastId, { render: error.message, type: 'error', isLoading: false })
toast.update(toastId, {
render: error.message,
type: 'error',
isLoading: false,
autoClose: 5000,
closeButton: true,
})
} else if (typeof error === 'string') {
toast.update(toastId, { render: error, type: 'error', isLoading: false })
toast.update(toastId, {
render: error,
type: 'error',
isLoading: false,
autoClose: 5000,
closeButton: true,
})
} else {
throw error
}
}
if (success) {
updateItem({ ...markerClicked, relations: newRelations })
toast.update(toastId, { render: 'Item linked', type: 'success', isLoading: false })
toast.update(toastId, {
render: 'Item linked',
type: 'success',
isLoading: false,
autoClose: 5000,
closeButton: true,
})
}
}
}