UNPKG

1.91 kBJavaScriptView Raw
1import React from 'react';
2import PropTypes from 'prop-types';
3import { Dropdown, DropdownToggle } from 'reactstrap';
4import { avLogMessagesApi } from '@availity/api-axios';
5import { useToggle } from '@availity/hooks';
6import FeedbackDropdown from './FeedbackDropdown';
7import FeedbackModal from './FeedbackModal';
8
9const Feedback = ({
10 appName,
11 modal,
12 zIndex,
13 children,
14 analytics,
15 className,
16 outline,
17 color,
18 formProps,
19 prompt,
20 onFeedbackSent,
21 ...props
22}) => {
23 const [isOpen, toggle] = useToggle(false);
24
25 return (
26 <Dropdown
27 isOpen={isOpen && !modal}
28 toggle={() => toggle()}
29 className={`${className} hidden-print`}
30 {...props}
31 >
32 <DropdownToggle color={color} outline={outline}>
33 {children || 'Give Feedback'}
34 </DropdownToggle>
35 {modal ? (
36 <FeedbackModal
37 onFeedbackSent={onFeedbackSent}
38 prompt={prompt}
39 isOpen={isOpen}
40 zIndex={zIndex}
41 toggle={() => toggle()}
42 name={appName}
43 analytics={analytics}
44 {...formProps}
45 />
46 ) : (
47 <FeedbackDropdown
48 onFeedbackSent={onFeedbackSent}
49 prompt={prompt}
50 analytics={analytics}
51 toggle={() => toggle()}
52 name={appName}
53 {...formProps}
54 />
55 )}
56 </Dropdown>
57 );
58};
59
60Feedback.propTypes = {
61 appName: PropTypes.string,
62 modal: PropTypes.bool,
63 zIndex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
64 children: PropTypes.node,
65 className: PropTypes.string,
66 outline: PropTypes.bool,
67 color: PropTypes.string,
68 formProps: PropTypes.object,
69 prompt: PropTypes.string,
70 onFeedbackSent: PropTypes.func,
71 analytics: PropTypes.shape({
72 info: PropTypes.func.isRequired,
73 }),
74};
75
76Feedback.defaultProps = {
77 modal: false,
78 color: 'light',
79 analytics: avLogMessagesApi,
80};
81
82export default Feedback;