From 616b4959ef33a1e5fae167a37d108f736badf2a6 Mon Sep 17 00:00:00 2001 From: Jeff Date: Wed, 27 Mar 2024 13:35:00 -0400 Subject: init --- components/popupWidget.js | 332 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 332 insertions(+) create mode 100644 components/popupWidget.js (limited to 'components/popupWidget.js') diff --git a/components/popupWidget.js b/components/popupWidget.js new file mode 100644 index 0000000..710dc9e --- /dev/null +++ b/components/popupWidget.js @@ -0,0 +1,332 @@ +import React, { useState } from "react"; +import { useForm, useWatch } from "react-hook-form"; +import { Disclosure, Transition } from "@headlessui/react"; + +const PopupWidget = () => { + const { + register, + handleSubmit, + reset, + control, + formState: { errors, isSubmitSuccessful, isSubmitting }, + } = useForm({ + mode: "onTouched", + }); + const [isSuccess, setIsSuccess] = useState(false); + const [Message, setMessage] = useState(""); + + const userName = useWatch({ control, name: "name", defaultValue: "Someone" }); + + const onSubmit = async (data, e) => { + console.log(data); + await fetch("https://api.web3forms.com/submit", { + method: "POST", + headers: { + "Content-Type": "application/json", + Accept: "application/json", + }, + body: JSON.stringify(data, null, 2), + }) + .then(async (response) => { + let json = await response.json(); + if (json.success) { + setIsSuccess(true); + setMessage(json.message); + e.target.reset(); + reset(); + } else { + setIsSuccess(false); + setMessage(json.message); + } + }) + .catch((error) => { + setIsSuccess(false); + setMessage("Client Error. Please check the console.log for more info"); + console.log(error); + }); + }; + + return ( +
+ + {({ open }) => ( + <> + + Open Contact form Widget + + + + {" "} + + + + + + + {" "} + + + + +
+

How can we help?

+

+ We usually respond in a few hours +

+
+
+ {!isSubmitSuccessful && ( +
+ + + + + +
+ + + {errors.name && ( +
+ {errors.name.message} +
+ )} +
+ +
+ + + + {errors.email && ( +
+ {errors.email.message} +
+ )} +
+ +
+ + + + {errors.message && ( +
+ {errors.message.message} +
+ )} +
+
+ +
+

+ + Powered by{" "} + + Web3Forms + + +

+
+ )} + + {isSubmitSuccessful && isSuccess && ( + <> +
+ + + +

+ Message sent successfully +

+

{Message}

+ +
+ + )} + + {isSubmitSuccessful && !isSuccess && ( +
+ + + + +

+ Oops, Something went wrong! +

+

{Message}

+ +
+ )} +
+
+
+ + )} +
+
+ ); +} + +export default PopupWidget; \ No newline at end of file -- cgit v1.2.3-70-g09d2