mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2025-12-13 07:46:10 +00:00
delete confirmation popup
This commit is contained in:
parent
0f690f6f24
commit
eff243bc36
@ -9,6 +9,7 @@ import { useHasUserPermission } from "../../hooks/usePermissions";
|
|||||||
import { useAuth } from "../../../Auth";
|
import { useAuth } from "../../../Auth";
|
||||||
import { getValue } from "../../../../Utils/GetValue";
|
import { getValue } from "../../../../Utils/GetValue";
|
||||||
import { useAssetApi } from '../../../AppShell/hooks/useAssets'
|
import { useAssetApi } from '../../../AppShell/hooks/useAssets'
|
||||||
|
import DialogModal from "../../../Templates/DialogModal";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -18,6 +19,9 @@ export function HeaderView({ item, setItemFormPopup }: {
|
|||||||
setItemFormPopup?: React.Dispatch<React.SetStateAction<ItemFormPopupProps | null>>
|
setItemFormPopup?: React.Dispatch<React.SetStateAction<ItemFormPopupProps | null>>
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
|
|
||||||
|
const [modalOpen, setModalOpen] = React.useState<boolean>(false);
|
||||||
|
|
||||||
const [loading, setLoading] = React.useState<boolean>(false);
|
const [loading, setLoading] = React.useState<boolean>(false);
|
||||||
const removeItem = useRemoveItem();
|
const removeItem = useRemoveItem();
|
||||||
|
|
||||||
@ -49,7 +53,12 @@ export function HeaderView({ item, setItemFormPopup }: {
|
|||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
map.closePopup();
|
map.closePopup();
|
||||||
|
window.history.pushState({}, "", "/");
|
||||||
|
event.stopPropagation();
|
||||||
|
}
|
||||||
|
|
||||||
|
const openDeleteModal = async (event: React.MouseEvent<HTMLElement>) => {
|
||||||
|
setModalOpen(true);
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,6 +71,7 @@ export function HeaderView({ item, setItemFormPopup }: {
|
|||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
<div className='tw-grid tw-grid-cols-6 tw-pb-2'>
|
<div className='tw-grid tw-grid-cols-6 tw-pb-2'>
|
||||||
<div className='tw-col-span-5'>
|
<div className='tw-col-span-5'>
|
||||||
<div className="tw-flex tw-flex-row">{
|
<div className="tw-flex tw-flex-row">{
|
||||||
@ -96,7 +106,7 @@ export function HeaderView({ item, setItemFormPopup }: {
|
|||||||
</li>}
|
</li>}
|
||||||
|
|
||||||
{item.layer.api.deleteItem && hasUserPermission(item.layer.api?.collectionName!, "delete") && <li>
|
{item.layer.api.deleteItem && hasUserPermission(item.layer.api?.collectionName!, "delete") && <li>
|
||||||
<a className=' !tw-text-error' onClick={removeItemFromMap}>
|
<a className=' !tw-text-error' onClick={openDeleteModal}>
|
||||||
{loading ? <span className="tw-loading tw-loading-spinner tw-loading-sm"></span>
|
{loading ? <span className="tw-loading tw-loading-spinner tw-loading-sm"></span>
|
||||||
:
|
:
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" className="tw-h-5 tw-w-5" viewBox="0 0 20 20" fill="currentColor">
|
<svg xmlns="http://www.w3.org/2000/svg" className="tw-h-5 tw-w-5" viewBox="0 0 20 20" fill="currentColor">
|
||||||
@ -108,5 +118,15 @@ export function HeaderView({ item, setItemFormPopup }: {
|
|||||||
</div>}
|
</div>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<DialogModal isOpened={modalOpen} title="Are you sure?" showCloseButton={false} onClose={ () => (setModalOpen(false)) }>
|
||||||
|
<span>Do you want to delte <b>{item.name}</b>?</span>
|
||||||
|
<div className="tw-grid">
|
||||||
|
<div className="tw-flex tw-justify-between">
|
||||||
|
<label className="tw-btn tw-mt-4 tw-btn-error" onClick={removeItemFromMap}>Yes</label>
|
||||||
|
<label className="tw-btn tw-mt-4" onClick={() => setModalOpen(false)}>No</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</DialogModal>
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,7 +58,7 @@ function UtopiaMap({
|
|||||||
props.setItemFormPopup({ layer: props.selectNewItemPosition, position: e.latlng })
|
props.setItemFormPopup({ layer: props.selectNewItemPosition, position: e.latlng })
|
||||||
props.setSelectNewItemPosition(null)
|
props.setSelectNewItemPosition(null)
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
})
|
})
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
@ -212,7 +212,7 @@ export function ProfileSettings() {
|
|||||||
<ReactCrop crop={crop} onChange={(c) => setCrop(c)} aspect={1} >
|
<ReactCrop crop={crop} onChange={(c) => setCrop(c)} aspect={1} >
|
||||||
<img src={image} ref={imgRef} onLoad={onImageLoad} />
|
<img src={image} ref={imgRef} onLoad={onImageLoad} />
|
||||||
</ReactCrop>
|
</ReactCrop>
|
||||||
<button className={`tw-btn `} onClick={() => {
|
<button className={`tw-btn tw-btn-primary`} onClick={() => {
|
||||||
setCropping(true);
|
setCropping(true);
|
||||||
setCropModalOpen(false);
|
setCropModalOpen(false);
|
||||||
renderCrop();
|
renderCrop();
|
||||||
|
|||||||
@ -18,6 +18,7 @@ type Props = {
|
|||||||
isOpened: boolean;
|
isOpened: boolean;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
|
showCloseButton?: boolean
|
||||||
};
|
};
|
||||||
|
|
||||||
const DialogModal = ({
|
const DialogModal = ({
|
||||||
@ -25,6 +26,7 @@ const DialogModal = ({
|
|||||||
isOpened,
|
isOpened,
|
||||||
onClose,
|
onClose,
|
||||||
children,
|
children,
|
||||||
|
showCloseButton = true
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
|
|
||||||
const ref = useRef<HTMLDialogElement>(null);
|
const ref = useRef<HTMLDialogElement>(null);
|
||||||
@ -43,7 +45,7 @@ const DialogModal = ({
|
|||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<dialog className='tw-card tw-shadow-xl tw-absolute tw-right-0 tw-top-0 tw-bottom-0 tw-left-0 tw-m-auto tw-transition-opacity tw-duration-300 tw-p-4 tw-max-w-xl'
|
<dialog className='tw-card tw-shadow-xl tw-absolute tw-right-0 tw-top-0 tw-bottom-0 tw-left-0 tw-m-auto tw-transition-opacity tw-duration-300 tw-p-4 tw-max-w-xl tw-bg-base-100'
|
||||||
|
|
||||||
ref={ref}
|
ref={ref}
|
||||||
onCancel={onClose}
|
onCancel={onClose}
|
||||||
@ -56,7 +58,7 @@ const DialogModal = ({
|
|||||||
<h2 className='tw-text-2xl tw-font-semibold tw-mb-2 tw-text-center'>{title}</h2>
|
<h2 className='tw-text-2xl tw-font-semibold tw-mb-2 tw-text-center'>{title}</h2>
|
||||||
|
|
||||||
{children}
|
{children}
|
||||||
<button className="tw-btn tw-btn-sm tw-btn-circle tw-btn-ghost tw-absolute tw-right-2 tw-top-2" onClick={onClose}>✕</button>
|
{showCloseButton && <button className="tw-btn tw-btn-sm tw-btn-circle tw-btn-ghost tw-absolute tw-right-2 tw-top-2" onClick={onClose}>✕</button>}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</dialog>
|
</dialog>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user