Repository navigation
Expand file tree
/
Copy pathFormModal.tsx
More file actions
66 lines (60 loc) · 1.51 KB
/
Copy pathFormModal.tsx
File metadata and controls
66 lines (60 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import {
Box,
Modal,
ModalOverlay,
ModalContent,
ModalHeader,
ModalBody,
ModalCloseButton,
Text,
} from '@chakra-ui/react';
import React, { useCallback } from 'react';
import useIsMobile from 'lib/hooks/useIsMobile';
import FormSubmitAlert from 'ui/shared/FormSubmitAlert';
interface Props<TData> {
isOpen: boolean;
onClose: () => void;
data?: TData;
title: string;
text?: string;
renderForm: () => React.JSX.Element;
isAlertVisible?: boolean;
setAlertVisible?: (isAlertVisible: boolean) => void;
}
export default function FormModal<TData>({
isOpen,
onClose,
title,
text,
renderForm,
isAlertVisible,
setAlertVisible,
}: Props<TData>) {
const onModalClose = useCallback(() => {
setAlertVisible && setAlertVisible(false);
onClose();
}, [ onClose, setAlertVisible ]);
const isMobile = useIsMobile();
return (
<Modal isOpen={ isOpen } onClose={ onModalClose } size={ isMobile ? 'full' : 'md' }>
<ModalOverlay/>
<ModalContent>
<ModalHeader fontWeight="500" textStyle="h3">{ title }</ModalHeader>
<ModalCloseButton/>
<ModalBody>
{ (isAlertVisible || text) && (
<Box marginBottom={{ base: 6, lg: 8 }}>
{ text && (
<Text lineHeight="30px" mb={ 3 }>
{ text }
</Text>
) }
{ isAlertVisible && <FormSubmitAlert/> }
</Box>
) }
{ renderForm() }
</ModalBody>
</ModalContent>
</Modal>
);
}