-
-
Notifications
You must be signed in to change notification settings - Fork 685
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): support deleting multiple storage files (#1755)
* feat(web): support deleting multiple storage files
- Loading branch information
Showing
9 changed files
with
365 additions
and
113 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { useCallback, useRef, useState } from "react"; | ||
import { | ||
AlertDialog, | ||
AlertDialogBody, | ||
AlertDialogCloseButton, | ||
AlertDialogContent, | ||
AlertDialogFooter, | ||
AlertDialogHeader, | ||
AlertDialogOverlay, | ||
Box, | ||
Button, | ||
} from "@chakra-ui/react"; | ||
|
||
interface ConfirmDialogProps { | ||
onConfirm: React.MouseEventHandler<HTMLButtonElement>; | ||
headerText: string; | ||
bodyText: string | React.ReactElement | any; | ||
confirmButtonText?: string; | ||
isOpen: boolean; | ||
onClose: () => void; | ||
} | ||
|
||
const ConfirmDialog = ({ | ||
onConfirm, | ||
headerText, | ||
bodyText, | ||
confirmButtonText, | ||
isOpen, | ||
onClose, | ||
}: ConfirmDialogProps) => { | ||
const cancelRef = useRef(null); | ||
|
||
const onSubmit: React.MouseEventHandler<HTMLButtonElement> = (event) => { | ||
onConfirm(event); | ||
onClose(); | ||
}; | ||
|
||
return ( | ||
<AlertDialog isOpen={isOpen} leastDestructiveRef={cancelRef} onClose={onClose}> | ||
<AlertDialogOverlay /> | ||
<AlertDialogContent> | ||
<AlertDialogHeader fontSize="lg" fontWeight="bold"> | ||
{headerText} | ||
</AlertDialogHeader> | ||
<AlertDialogCloseButton /> | ||
<AlertDialogBody> | ||
<Box>{bodyText}</Box> | ||
</AlertDialogBody> | ||
<AlertDialogFooter> | ||
<Button onClick={onSubmit}>{confirmButtonText}</Button> | ||
</AlertDialogFooter> | ||
</AlertDialogContent> | ||
</AlertDialog> | ||
); | ||
}; | ||
|
||
export const useConfirmDialog = () => { | ||
const [isOpen, setOpen] = useState(false); | ||
const [data, setData] = useState<Omit<Omit<ConfirmDialogProps, "isOpen">, "onClose"> | null>( | ||
null, | ||
); | ||
|
||
const show = useCallback((data: Omit<Omit<ConfirmDialogProps, "isOpen">, "onClose">) => { | ||
setOpen(true); | ||
setData({ | ||
...data, | ||
}); | ||
}, []); | ||
|
||
const onClose = useCallback(() => { | ||
setOpen(false); | ||
}, []); | ||
|
||
const Dialog = useCallback( | ||
() => (data ? <ConfirmDialog {...data} isOpen={isOpen} onClose={onClose} /> : <></>), | ||
[data, isOpen, onClose], | ||
); | ||
return { | ||
Dialog, | ||
show, | ||
onClose, | ||
isOpen, | ||
}; | ||
}; | ||
|
||
export default ConfirmDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.