This commit is contained in:
Anton Tranelis 2025-02-19 14:14:14 +00:00
parent feae3dc482
commit 34d7e45ad6
4 changed files with 12 additions and 12 deletions

View File

@ -48,7 +48,7 @@ export const Layer = ({
markerDefaultColor2 = 'RGBA(35, 31, 32, 0.2)',
api,
itemType,
onlyOnePerOwner = false,
userProfileLayer = false,
customEditLink,
customEditParameter,
// eslint-disable-next-line camelcase
@ -100,7 +100,7 @@ export const Layer = ({
markerDefaultColor2,
api,
itemType,
onlyOnePerOwner,
userProfileLayer,
// Can we just use editCallback for all cases?
customEditLink,
customEditParameter,
@ -126,7 +126,7 @@ export const Layer = ({
markerDefaultColor2,
api,
itemType,
onlyOnePerOwner,
userProfileLayer,
customEditLink,
customEditParameter,
// eslint-disable-next-line camelcase

View File

@ -93,10 +93,10 @@ export function ItemFormPopup(props: ItemFormPopupProps) {
const uuid = crypto.randomUUID()
let success = false
try {
props.layer.onlyOnePerOwner &&
props.layer.userProfileLayer &&
item &&
(await props.layer.api?.updateItem!({ ...formItem, id: item.id }))
;(!props.layer.onlyOnePerOwner || !item) &&
;(!props.layer.userProfileLayer || !item) &&
(await props.layer.api?.createItem!({
...formItem,
id: uuid,
@ -108,8 +108,8 @@ export function ItemFormPopup(props: ItemFormPopupProps) {
toast.error(error.toString())
}
if (success) {
if (props.layer.onlyOnePerOwner && item) updateItem({ ...item, ...formItem })
if (!props.layer.onlyOnePerOwner || !item) {
if (props.layer.userProfileLayer && item) updateItem({ ...item, ...formItem })
if (!props.layer.userProfileLayer || !item) {
addItem({
...formItem,
name: (formItem.name ? formItem.name : user?.first_name) ?? '',

View File

@ -60,9 +60,9 @@ export const ItemViewPopup = forwardRef((props: ItemViewPopupProps, ref: any) =>
setLoading(true)
let success = false
try {
!props.item.layer?.onlyOnePerOwner &&
!props.item.layer?.userProfileLayer &&
(await props.item.layer?.api?.deleteItem!(props.item.id))
props.item.layer?.onlyOnePerOwner &&
props.item.layer?.userProfileLayer &&
(await props.item.layer.api?.updateItem!({ id: props.item.id, position: null }))
success = true
// eslint-disable-next-line no-catch-all/no-catch-all
@ -71,8 +71,8 @@ export const ItemViewPopup = forwardRef((props: ItemViewPopupProps, ref: any) =>
toast.error(error.toString())
}
if (success) {
!props.item.layer?.onlyOnePerOwner && removeItem(props.item)
props.item.layer?.onlyOnePerOwner && updadateItem({ ...props.item, position: undefined })
!props.item.layer?.userProfileLayer && removeItem(props.item)
props.item.layer?.userProfileLayer && updadateItem({ ...props.item, position: undefined })
toast.success('Item deleted')
}
setLoading(false)

View File

@ -21,7 +21,7 @@ export interface LayerProps {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
api?: ItemsApi<any>
itemType: ItemType
onlyOnePerOwner?: boolean
userProfileLayer?: boolean
customEditLink?: string
customEditParameter?: string
public_edit_items?: boolean