diff --git a/src/views/configuration/Address.js b/src/views/configuration/Address.js index ab02706..e639604 100644 --- a/src/views/configuration/Address.js +++ b/src/views/configuration/Address.js @@ -76,16 +76,21 @@ function Address() { contact, email, }; + let res = await axios.post(`/api/config/address`, data, { headers: { Authorization: `Bearer ${token}`, }, }); + console.log(res); if (res) { setLoading(false); - console.log(res); - swal("Success!", res.data.message, res.data.status); + + swal("Success!", res.data.message); + } else { + setLoading(false); + swal("something went wrong!", res.data.message); } } diff --git a/src/views/configuration/Logo.js b/src/views/configuration/Logo.js index 362cc1a..2bd89d9 100644 --- a/src/views/configuration/Logo.js +++ b/src/views/configuration/Logo.js @@ -1,222 +1,246 @@ -import React, { useEffect, useState } from 'react' +import React, { useEffect, useState } from "react"; -import swal from 'sweetalert' -import ClipLoader from 'react-spinners/ClipLoader' -import { Link } from 'react-router-dom' -import axios from 'axios' -import { isAutheticated } from 'src/auth' +import swal from "sweetalert"; +import ClipLoader from "react-spinners/ClipLoader"; +import { Link } from "react-router-dom"; +import axios from "axios"; +import { isAutheticated } from "src/auth"; function Logo() { - const [loading, setLoading] = useState(false) - const [Headerlogo, setHeaderlogo] = useState('') - const [Footerlogo, setFooterlogo] = useState('') - const [Adminlogo, setAdminlogo] = useState('') - const [display, setDisplay] = useState(true) - const token = isAutheticated() + const [loading, setLoading] = useState(false); + const [Headerlogo, setHeaderlogo] = useState(""); + const [Footerlogo, setFooterlogo] = useState(""); + const [Adminlogo, setAdminlogo] = useState(""); + const [display, setDisplay] = useState(true); + const token = isAutheticated(); - // urlcreated images + // urlcreated images - const [HeaderlogoUrl, setHeaderlogoUrl] = useState('') - const [FooterlogoUrl, setFooterlogoUrl] = useState('') - const [AdminlogoUrl, setAdminlogoUrl] = useState('') + const [HeaderlogoUrl, setHeaderlogoUrl] = useState(""); + const [FooterlogoUrl, setFooterlogoUrl] = useState(""); + const [AdminlogoUrl, setAdminlogoUrl] = useState(""); - useEffect(() => { - async function getConfiguration() { - const configDetails = await axios.get(`/api/config`, { - headers: { - Authorization: `Bearer ${token}`, - }, - }) + useEffect(() => { + async function getConfiguration() { + const configDetails = await axios.get(`/api/config`, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); - configDetails.data.result.map((item) => { - setHeaderlogo(item?.logo[0]?.Headerlogo) - setFooterlogo(item?.logo[0]?.Footerlogo) - setAdminlogo(item?.logo[0]?.Adminlogo) - }) - } - getConfiguration() - }, []) - - // async function handelChange(e) { - // setDisplay(false); - // console.log(e.target.name === "Logo htmlFor Website Header(148 x 48 px)"); - // if (e.target.name === "Logo htmlFor Website Header(148 x 48 px)") { - // console.log(e.target.files[0]); - // setHeaderlogo(e.target.files[0]); - // } else if (e.target.name === "Logo htmlFor Website Footer(148 x 48 px)") { - // setFooterlogo(e.target.files[0]); - // } else if (e.target.name === "Logo htmlFor Admin Header(148 x 48 px)") { - // setAdminlogo(e.target.files[0]); - // } - // } - - async function handelSubmit() { - setLoading(true) - - const formdata = new FormData() - formdata.append('Headerlogo', Headerlogo) - formdata.append('Footerlogo', Footerlogo) - formdata.append('Adminlogo', Adminlogo) - - await axios.post(`/api/config/logo`, formdata, { - headers: { - Authorization: `Bearer ${token}`, - 'Content-Type': 'multipart/formdata', - 'Access-Control-Allow-Origin': '*', - }, - }).then((res) => { - setLoading(false) - swal('Success!', res.data.message, res.data.status) - } - ).catch(error => { - console.log(error) - }) + configDetails.data.result.map((item) => { + setHeaderlogo(item?.logo[0]?.Headerlogo); + setFooterlogo(item?.logo[0]?.Footerlogo); + setAdminlogo(item?.logo[0]?.Adminlogo); + }); } + getConfiguration(); + }, []); - return ( -
-
-
-
-
+ // async function handelChange(e) { + // setDisplay(false); + // console.log(e.target.name === "Logo htmlFor Website Header(148 x 48 px)"); + // if (e.target.name === "Logo htmlFor Website Header(148 x 48 px)") { + // console.log(e.target.files[0]); + // setHeaderlogo(e.target.files[0]); + // } else if (e.target.name === "Logo htmlFor Website Footer(148 x 48 px)") { + // setFooterlogo(e.target.files[0]); + // } else if (e.target.name === "Logo htmlFor Admin Header(148 x 48 px)") { + // setAdminlogo(e.target.files[0]); + // } + // } + + async function handelSubmit() { + setLoading(true); + + const formdata = new FormData(); + formdata.append("Headerlogo", Headerlogo); + formdata.append("Footerlogo", Footerlogo); + formdata.append("Adminlogo", Adminlogo); + + await axios + .post(`/api/config/logo`, formdata, { + headers: { + Authorization: `Bearer ${token}`, + "Content-Type": "multipart/formdata", + "Access-Control-Allow-Origin": "*", + }, + }) + .then((res) => { + setLoading(false); + swal("Success!", res.data.message, res.data.status); + }) + .catch((error) => { + console.log(error); + }); + } + + return ( +
+
+
+
+
+
+
+
+
+
+

Logo

+ +
+
-
-
-
-
-

Logo

+
+ <> + +
+ { + setHeaderlogo(e.target.files[0]); + if ( + e.target.files && + e.target.files[0] + ) { + setHeaderlogoUrl({ + image: URL.createObjectURL( + e.target.files[0] + ), + }); + console.log(setHeaderlogoUrl); + } + }} + className="form-control input-field mb-3 col-md-6 d-inline-block" + id="basicpill-phoneno-input" + /> + {display ? ( + header logo + ) : ( + "" + )} +
+ + { + setFooterlogo(e.target.files[0]); - -
-
-
- <> - -
- { - setHeaderlogo(e.target.files[0]) - if (e.target.files && e.target.files[0]) { - setHeaderlogoUrl({ - image: URL.createObjectURL(e.target.files[0]), - }) - console.log(setHeaderlogoUrl) - } - }} - className="form-control input-field mb-3 col-md-6 d-inline-block" - id="basicpill-phoneno-input" - /> - {display ? ( - header logo - ) : ( - '' - )} -
- - { - setFooterlogo(e.target.files[0]) + if (e.target.files && e.target.files[0]) { + setFooterlogoUrl({ + image: URL.createObjectURL( + e.target.files[0] + ), + }); + } + }} + className="form-control input-field mt-1 col-md-6 d-inline-block" + id="basicpill-phoneno-input" + />{" "} + {display ? ( + Footer logo + ) : ( + "" + )} + + { + setAdminlogo(e.target.files[0]); - if (e.target.files && e.target.files[0]) { - setFooterlogoUrl({ - image: URL.createObjectURL(e.target.files[0]), - }) - } - }} - className="form-control input-field mt-1 col-md-6 d-inline-block" - id="basicpill-phoneno-input" - />{' '} - {display ? ( - Footer logo - ) : ( - '' - )} - - { - setAdminlogo(e.target.files[0]) - - if (e.target.files && e.target.files[0]) { - setAdminlogoUrl({ - image: URL.createObjectURL(e.target.files[0]), - }) - } - }} - className="form-control input-field col-md-6 d-inline-block" - id="basicpill-phoneno-input" - />{' '} - {display ? ( - Admin logo - ) : ( - '' - )} - -
-
-
-
-
-
- -
-
-
- -
-
- - {/* */} -
-
+ if (e.target.files && e.target.files[0]) { + setAdminlogoUrl({ + image: URL.createObjectURL( + e.target.files[0] + ), + }); + } + }} + className="form-control input-field col-md-6 d-inline-block" + id="basicpill-phoneno-input" + />{" "} + {display ? ( + Admin logo + ) : ( + "" + )} + +
-
+
+
+
+
+ +
+
+
+ +
- {/* */} + + {/* */} +
- {/* */} +
+
+ {/* */}
- ) + {/* */} +
+
+ ); } -export default Logo +export default Logo;