diff --git a/src/components/contact/ContactForm.tsx b/src/components/contact/ContactForm.tsx index 791ed66..579f66f 100644 --- a/src/components/contact/ContactForm.tsx +++ b/src/components/contact/ContactForm.tsx @@ -6,9 +6,12 @@ import Skeleton from "react-loading-skeleton"; import board from "../../images/board.jpg"; // Helpers -import { getContact } from "../../helpers/apiRequests"; +import { getContact, sendData } from "../../helpers/apiRequests"; import { highlightColor } from "../../helpers/otherVariables"; +// Components +import Loader from "../global/Loader"; + // Icons import forward from "../../icons/arrow-forward.svg"; import email from "../../icons/email-black.svg"; @@ -19,8 +22,17 @@ import yt from "../../icons/youtube-gray.svg"; import ig from "../../icons/instagram-grey.svg"; import twitter from "../../icons/twitter-gray.svg"; +// Types +import { ContactData } from "../../types/contact"; + const ContactForm = () => { const [contact, setContact]: [any, React.Dispatch] = useState(); + const [data, setData]: [ContactData, React.Dispatch] = useState({ + name: "", + email: "", + message: "", + }); + const [load, setLoad]: [boolean, React.Dispatch] = useState(false); useEffect(() => { getContact(setContact); @@ -29,10 +41,18 @@ const ContactForm = () => { return (
{ + onSubmit={(e: any) => { e.preventDefault(); + sendData(setLoad, data); + e.target.reset(); + setData({ + name: "", + email: "", + message: "", + }); }} > +
@@ -166,31 +186,53 @@ const ContactForm = () => {
{ + setData({ ...data, name: e.target.value }); + }} + onChange={(e: any) => { + setData({ ...data, name: e.target.value }); + }} />
{ + setData({ ...data, email: e.target.value }); + }} + onChange={(e: any) => { + setData({ ...data, email: e.target.value }); + }} />
+ {/* */}
- +
diff --git a/src/components/global/Loader.tsx b/src/components/global/Loader.tsx new file mode 100644 index 0000000..11c0efc --- /dev/null +++ b/src/components/global/Loader.tsx @@ -0,0 +1,19 @@ +// Modules + +// Icons +import { ReactComponent as Spinner } from "../../icons/loader.svg"; + +// Types +interface Props { + className: string; +} + +const Loader = ({ className }: Props) => { + return ( +
+ +
+ ); +}; + +export default Loader; diff --git a/src/helpers/apiRequests.ts b/src/helpers/apiRequests.ts index c72ee0b..47edf5a 100644 --- a/src/helpers/apiRequests.ts +++ b/src/helpers/apiRequests.ts @@ -1,4 +1,5 @@ import axios from "axios"; +import React from "react"; import { SlideProps } from "../types/mainSliderSlide"; import { partnersType } from "../types/partnersType"; import { eventType } from "../types/eventProps"; @@ -17,8 +18,11 @@ import { about, players, events, + contact_us, } from "../links"; -import React from "react"; + +// Types +import { ContactData } from "../types/contact"; export const getMainSliderData = ( setState: React.Dispatch @@ -151,3 +155,18 @@ export const getPlayerInfo = (setState: any, link: string) => { }) .catch(); }; + +export const sendData = (setState: any, data: ContactData) => { + const formData = new FormData(); + formData.append("name", data.name); + formData.append("email", data.email); + formData.append("message", data.message); + axios + .post(contact_us, formData) + .then((res) => { + if (res.data === "Contact message sent") { + setState(false); + } + }) + .catch(); +}; diff --git a/src/icons/loader.svg b/src/icons/loader.svg new file mode 100644 index 0000000..f17c5bc --- /dev/null +++ b/src/icons/loader.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/links.ts b/src/links.ts index 876f208..39a4989 100644 --- a/src/links.ts +++ b/src/links.ts @@ -23,3 +23,5 @@ export const about: string = hosting + "/api/v1/about"; export const players: string = hosting + "/api/v1/players"; export const events: string = hosting + "/api/v1/events"; + +export const contact_us: string = hosting + "/api/v1/send-contact-form"; diff --git a/src/styles/_contact.scss b/src/styles/_contact.scss index 0bc7b55..1aa1063 100644 --- a/src/styles/_contact.scss +++ b/src/styles/_contact.scss @@ -31,6 +31,7 @@ display: grid; grid-template-columns: 1fr 1fr; gap: 3rem; + position: relative; } .contact-img { diff --git a/src/styles/_loader.scss b/src/styles/_loader.scss new file mode 100644 index 0000000..bb96bdb --- /dev/null +++ b/src/styles/_loader.scss @@ -0,0 +1,22 @@ +.loader { + @include flex-c; + z-index: 100; + pointer-events: none; + opacity: 0; + width: 100%; + height: 100%; + position: absolute; + background: rgba(255, 255, 255, 0.8); + @include transition-std; + + &.active { + pointer-events: all; + opacity: 1; + @include transition-std; + } +} + +.spinner { + width: 9rem; + height: 9rem; +} diff --git a/src/styles/style.scss b/src/styles/style.scss index a3fd3b1..618dc2c 100644 --- a/src/styles/style.scss +++ b/src/styles/style.scss @@ -19,3 +19,4 @@ @import "./tournaments"; @import "./burger"; @import "./player-profile"; +@import "./loader"; diff --git a/src/types/contact.ts b/src/types/contact.ts new file mode 100644 index 0000000..329dffd --- /dev/null +++ b/src/types/contact.ts @@ -0,0 +1,5 @@ +export interface ContactData { + name: string; + email: string; + message: string; +}