mirror of
https://github.com/khairul169/garage-webui.git
synced 2026-09-15 00:43:21 +07:00
feat: add keys & bucket permissions management
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
|
||||
export const useDisclosure = <T = any>() => {
|
||||
const dialogRef = useRef<HTMLDialogElement>(null);
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [data, setData] = useState<T | null | undefined>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const dlg = dialogRef.current;
|
||||
if (!dlg || !isOpen) return;
|
||||
|
||||
const onDialogClose = () => {
|
||||
setIsOpen(false);
|
||||
};
|
||||
|
||||
dlg.addEventListener("close", onDialogClose);
|
||||
return () => dlg.removeEventListener("close", onDialogClose);
|
||||
}, [dialogRef, isOpen]);
|
||||
|
||||
return {
|
||||
dialogRef,
|
||||
isOpen,
|
||||
data,
|
||||
onOpen: (data?: T | null) => {
|
||||
setIsOpen(true);
|
||||
setData(data);
|
||||
},
|
||||
onClose: () => {
|
||||
setIsOpen(false);
|
||||
},
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user