diff --git a/src/components/FeedbackForm/index.js b/src/components/FeedbackForm/index.js index 778eb1d9..166b6c10 100644 --- a/src/components/FeedbackForm/index.js +++ b/src/components/FeedbackForm/index.js @@ -50,7 +50,7 @@ export const FeedbackForm = () => { setModalShow(false)} /> diff --git a/src/components/ModalFormSpark/Forms/FormFeedback/index.js b/src/components/ModalFormSpark/Forms/FormFeedback/index.js new file mode 100644 index 00000000..fe4fcc72 --- /dev/null +++ b/src/components/ModalFormSpark/Forms/FormFeedback/index.js @@ -0,0 +1,149 @@ +import React, { useEffect, useState } from 'react' +import { useFormspark } from '@formspark/use-formspark' + +export const FormFeedback = (props) => { + const [url, setUrl] = useState('#'); + + const { form } = props; + + const [submit, submitting] = useFormspark({ + formId: form?.id || ``, + }); + + + const [message, setMessage] = useState(""); + const [email, setEmail] = useState(""); + const [name, setName] = useState(""); + + const [sending, setSending] = useState(false); + const [submitted, setSubmitted] = useState(false); + + const totalStars = 5; + const [rating, setRating] = useState(props.rating || 0); + const [hover, setHover] = useState(null); + + useEffect(() => { + if (props.rating) { + setRating(props.rating); + } + + if (window) { + setUrl(window.location.origin + window.location.pathname); + } + }, [props.rating]); + + const onSubmit = async (e) => { + if (submitting) return; + + e.preventDefault(); + setSending(true); + let query = {message, email, name, url} + + query = props?.rating ? {...query, rating} : query; + + await submit(query); + setSubmitted(true); + setSending(false); + setMessage(""); + setEmail(""); + setName(""); + setRating(0); + setTimeout(() => { + setSubmitted(false); + }, 4000) + }; + + return form?.id && ( + <> + {props?.rating && ( +
+ Current rating +
+ {[...Array(totalStars)].map((star, index) => { + const currentRating = index + 1; + + return ( + + ); + })} +
+
+ )} + +
+
+ {props?.rating && ( + + )} + setName(e.target.value)} + /> + setEmail(e.target.value)} + /> + +