| 1 |
import { useState, useEffect } from "@wordpress/element"; |
| 2 |
import { useBlockProps } from "@wordpress/block-editor"; |
| 3 |
import Inspector from "./inspector"; |
| 4 |
import { MessageIcon } from "./icons"; |
| 5 |
import FeedbackModalForm from "./modal"; |
| 6 |
import { safeHTML } from '@wordpress/dom'; |
| 7 |
import { |
| 8 |
usePreviewDeviceType, |
| 9 |
useStyleSheets, |
| 10 |
useDuplicateBlockIdFix, |
| 11 |
} from "../../../hooks"; |
| 12 |
import cssProperties from "./cssProperties"; |
| 13 |
|
| 14 |
const BLOCK_PREFIX = "betterdocs-feedback-form"; |
| 15 |
const edit = ({ isSelected, clientId, attributes, setAttributes }) => { |
| 16 |
const { |
| 17 |
resOption, |
| 18 |
blockId, |
| 19 |
blockMeta, |
| 20 |
formContent, |
| 21 |
formTitle, |
| 22 |
buttonText, |
| 23 |
formContentColor, |
| 24 |
feedbackFormHeadingColor, |
| 25 |
feedbackFormNameLabelText, |
| 26 |
feedbackFormEmailLabelText, |
| 27 |
feedbackFormMessageLabelText |
| 28 |
} = attributes; |
| 29 |
|
| 30 |
const [display, setDisplay] = useState("none"); |
| 31 |
|
| 32 |
usePreviewDeviceType(setAttributes); |
| 33 |
useDuplicateBlockIdFix(BLOCK_PREFIX, blockId, clientId, setAttributes); |
| 34 |
const { properties, htmlAttributes, styleTag } = useStyleSheets({ |
| 35 |
properties: cssProperties({ blockId }), |
| 36 |
setAttributes, |
| 37 |
attributes, |
| 38 |
}); |
| 39 |
|
| 40 |
const blockProps = useBlockProps({ |
| 41 |
className: `eb-guten-block-main-parent-wrapper`, |
| 42 |
}); |
| 43 |
|
| 44 |
return ( |
| 45 |
<> |
| 46 |
{isSelected && ( |
| 47 |
<Inspector |
| 48 |
attributes={attributes} |
| 49 |
setAttributes={setAttributes} |
| 50 |
/> |
| 51 |
)} |
| 52 |
<div {...blockProps}> |
| 53 |
{styleTag()} |
| 54 |
<div className={`${safeHTML(blockId)} feedback-form`}> |
| 55 |
<a |
| 56 |
className="feedback-form-link" |
| 57 |
href="#betterdocs-form-modal" |
| 58 |
name="betterdocs-form-modal" |
| 59 |
onClick={() => { |
| 60 |
setDisplay("block"); |
| 61 |
}} |
| 62 |
> |
| 63 |
<span className="feedback-form-icon"> |
| 64 |
<MessageIcon /> |
| 65 |
</span> |
| 66 |
{formContent} |
| 67 |
</a> |
| 68 |
</div> |
| 69 |
<FeedbackModalForm |
| 70 |
display={display} |
| 71 |
setDisplay={setDisplay} |
| 72 |
blockId={blockId} |
| 73 |
formTitle={formTitle} |
| 74 |
buttonText={buttonText} |
| 75 |
labelNameText={feedbackFormNameLabelText} |
| 76 |
labelEmailText={feedbackFormEmailLabelText} |
| 77 |
labelMessageText={feedbackFormMessageLabelText} |
| 78 |
/> |
| 79 |
</div> |
| 80 |
</> |
| 81 |
); |
| 82 |
}; |
| 83 |
|
| 84 |
export default edit; |
| 85 |
|