diff options
| author | FifthWit <fifthwitbusiness@gmail.com> | 2025-01-30 10:44:30 -0600 |
|---|---|---|
| committer | FifthWit <fifthwitbusiness@gmail.com> | 2025-01-30 10:44:30 -0600 |
| commit | e40f07211f5f15dcb138e2520a76d13afd3c0cfd (patch) | |
| tree | 46bad6a17e66d55a4a65088c0b6eb8c48641615a /frontend/src/hooks/UseConfirm.tsx | |
| parent | added prettier for more consistency (diff) | |
| download | lphub-e40f07211f5f15dcb138e2520a76d13afd3c0cfd.tar.gz lphub-e40f07211f5f15dcb138e2520a76d13afd3c0cfd.tar.bz2 lphub-e40f07211f5f15dcb138e2520a76d13afd3c0cfd.zip | |
formatted with prettier
Diffstat (limited to 'frontend/src/hooks/UseConfirm.tsx')
| -rw-r--r-- | frontend/src/hooks/UseConfirm.tsx | 61 |
1 files changed, 34 insertions, 27 deletions
diff --git a/frontend/src/hooks/UseConfirm.tsx b/frontend/src/hooks/UseConfirm.tsx index e86d70d..7b4bffa 100644 --- a/frontend/src/hooks/UseConfirm.tsx +++ b/frontend/src/hooks/UseConfirm.tsx | |||
| @@ -2,39 +2,46 @@ import React, { useState } from 'react'; | |||
| 2 | import ConfirmDialog from '@components/ConfirmDialog'; | 2 | import ConfirmDialog from '@components/ConfirmDialog'; |
| 3 | 3 | ||
| 4 | const useConfirm = () => { | 4 | const useConfirm = () => { |
| 5 | const [isOpen, setIsOpen] = useState(false); | 5 | const [isOpen, setIsOpen] = useState(false); |
| 6 | const [title, setTitle] = useState<string>(""); | 6 | const [title, setTitle] = useState<string>(''); |
| 7 | const [subtitle, setSubtitle] = useState<string>(""); | 7 | const [subtitle, setSubtitle] = useState<string>(''); |
| 8 | const [resolvePromise, setResolvePromise] = useState<((value: boolean) => void) | null>(null); | 8 | const [resolvePromise, setResolvePromise] = useState< |
| 9 | ((value: boolean) => void) | null | ||
| 10 | >(null); | ||
| 9 | 11 | ||
| 10 | const confirm = ( titleN: string, subtitleN: string ) => { | 12 | const confirm = (titleN: string, subtitleN: string) => { |
| 11 | setIsOpen(true); | 13 | setIsOpen(true); |
| 12 | setTitle(titleN); | 14 | setTitle(titleN); |
| 13 | setSubtitle(subtitleN); | 15 | setSubtitle(subtitleN); |
| 14 | return new Promise<boolean>((resolve) => { | 16 | return new Promise<boolean>(resolve => { |
| 15 | setResolvePromise(() => resolve); | 17 | setResolvePromise(() => resolve); |
| 16 | }); | 18 | }); |
| 17 | }; | 19 | }; |
| 18 | 20 | ||
| 19 | const handleConfirm = () => { | 21 | const handleConfirm = () => { |
| 20 | setIsOpen(false); | 22 | setIsOpen(false); |
| 21 | if (resolvePromise) { | 23 | if (resolvePromise) { |
| 22 | resolvePromise(true); | 24 | resolvePromise(true); |
| 23 | } | ||
| 24 | } | 25 | } |
| 26 | }; | ||
| 25 | 27 | ||
| 26 | const handleCancel = () => { | 28 | const handleCancel = () => { |
| 27 | setIsOpen(false); | 29 | setIsOpen(false); |
| 28 | if (resolvePromise) { | 30 | if (resolvePromise) { |
| 29 | resolvePromise(false); | 31 | resolvePromise(false); |
| 30 | } | ||
| 31 | } | 32 | } |
| 33 | }; | ||
| 32 | 34 | ||
| 33 | const ConfirmDialogComponent = isOpen && ( | 35 | const ConfirmDialogComponent = isOpen && ( |
| 34 | <ConfirmDialog title={title} subtitle={subtitle} onConfirm={handleConfirm} onCancel={handleCancel}></ConfirmDialog> | 36 | <ConfirmDialog |
| 35 | ); | 37 | title={title} |
| 38 | subtitle={subtitle} | ||
| 39 | onConfirm={handleConfirm} | ||
| 40 | onCancel={handleCancel} | ||
| 41 | ></ConfirmDialog> | ||
| 42 | ); | ||
| 36 | 43 | ||
| 37 | return { confirm, ConfirmDialogComponent }; | 44 | return { confirm, ConfirmDialogComponent }; |
| 38 | } | 45 | }; |
| 39 | 46 | ||
| 40 | export default useConfirm; | 47 | export default useConfirm; |