From 0f34385f133025bc8dc2835ac4efc2ef048501c1 Mon Sep 17 00:00:00 2001 From: Chukwumdiebube Date: Sat, 14 Jan 2023 15:57:02 +0100 Subject: [PATCH] Success in the api call --- src/component/Contact/Main.js | 30 ++++++++++++++++++++---------- src/vendors/service/siteService.js | 2 +- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/component/Contact/Main.js b/src/component/Contact/Main.js index eb4d922..e93dd6c 100644 --- a/src/component/Contact/Main.js +++ b/src/component/Contact/Main.js @@ -6,7 +6,7 @@ import Bredcrumb from "../Bredcrumb/Main"; import BGImg from "../../assets/images/bread_crumb_bg.png"; import BGImg1 from "../../assets/images/bread_crumb_bg_one.png"; import BGImg2 from "../../assets/images/bread_crumb_bg_two.png"; -import axios from "axios" +import axios from "axios"; import SiteService from "../../vendors/service/siteService"; @@ -57,7 +57,7 @@ const Main = ({ brdcum }) => { phone: "", msg: "", country: "", - checkBox: false + checkBox: false, }); //initial state values const [countries, setCountries] = useState([]); // initial state for country dropdown @@ -68,25 +68,30 @@ const Main = ({ brdcum }) => { return API_CALL.countryData(); }; - const contactForm = () => { - return API_CALL.contactData(); + const contactForm = async (value) => { + return await API_CALL.contactData(value); }; - + const onChange = (e) => { setValues((prev) => ({ ...prev, [e.target.name]: e.target.value })); }; - console.log(values) + console.log(values); // Submitting form - const handleSubmit = (e) => { + const handleSubmit = async (e) => { e.preventDefault(); + let formReg; + + contactForm(JSON.stringify(values)).then((contact) => { + formReg = contact; + console.log("FormReg:", formReg); + }); }; //CALLS THE API AFTER COMPONENT LOADS useEffect(() => { allCountry().then((data) => setCountries(Object.values(data.data))); - console.log(values); }, []); return ( @@ -185,7 +190,11 @@ const Main = ({ brdcum }) => { value={values.country} onChange={onChange} required> - + {countries.length > 0 && countries.map((country, index) => (