Success in the api call

This commit is contained in:
Chukwumdiebube
2023-01-14 15:57:02 +01:00
parent 2bc9ed0fdb
commit 0f34385f13
2 changed files with 21 additions and 11 deletions
+20 -10
View File
@@ -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>
<option value={''} onCha>Country</option>
<option
value={""}
onCha>
Country
</option>
{countries.length > 0 &&
countries.map((country, index) => (
<option
@@ -232,7 +241,8 @@ const Main = ({ brdcum }) => {
<div className="form-group mb-0">
<button
type="submit"
className="btn puprple_btn" aria-label="submit form">
className="btn puprple_btn"
aria-label="submit form">
SEND MESSAGE
</button>
</div>
+1 -1
View File
@@ -58,7 +58,7 @@ class SiteService {
postAuxEnd(uri, reqData) {
const endPoint = process.env.REACT_APP_AUX_ENDPOINT + uri;
Axios.post(endPoint)
return Axios.post(endPoint, reqData)
.then((response) => {
console.log(response);
// res = response;