// 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"; // function MobileApp() { // const [loading, setLoading] = useState(false); // const [PDApp, setPDApp] = useState(""); // const [RDApp, setRDApp] = useState(""); // const [SCApp, setSCApp] = useState(""); // const [TMApp, setTMApp] = useState(""); // const [display, setDisplay] = useState(true); // const token = isAutheticated(); // // urlcreated images // const [PDAppUrl, setPDAppUrl] = useState(""); // const [RDAppUrl, setRDAppUrl] = useState(""); // const [SCAppUrl, setSCAppUrl] = useState(""); // const [TMAppUrl, setTMAppUrl] = useState(""); // useEffect(() => { // async function getConfiguration() { // const configDetails = await axios.get(`/api/config`, { // headers: { // Authorization: `Bearer ${token}`, // }, // }); // // console.log(configDetails.data.result[0]?.mobileapp[0]); // const data = configDetails.data.result[0]?.mobileapp[0]; // setPDApp(data?.PDApp); // setRDApp(data?.RDApp); // setSCApp(data?.SCApp); // setTMApp(data?.TMApp); // } // getConfiguration(); // }, []); // async function handelSubmit() { // setLoading(true); // const formdata = new FormData(); // formdata.append("PDApp", PDApp); // formdata.append("RDApp", RDApp); // formdata.append("SCApp", SCApp); // formdata.append("TMApp", TMApp); // await axios // .post(`/api/config/mobile-app`, 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) => { // setLoading(false); // }); // } // return ( //
//
//
//
//
//
//
//
//
//
//

Mobile App

//
//
//
//
// <> // //
// { // setPDApp(e.target.files[0]); // if ( // e.target.files && // e.target.files[0] // ) { // setPDAppUrl({ // image: URL.createObjectURL( // e.target.files[0] // ), // }); // console.log(setPDAppUrl); // } // }} // className="form-control input-field mb-3 col-md-6 d-inline-block" // id="basicpill-phoneno-input" // /> // {display ? ( // // ) : ( // "" // )} //
// //
// { // setRDApp(e.target.files[0]); // if (e.target.files && e.target.files[0]) { // setRDAppUrl({ // 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 ? ( // // ) : ( // "" // )} // // { // setSCApp(e.target.files[0]); // if (e.target.files && e.target.files[0]) { // setSCAppUrl({ // image: URL.createObjectURL( // e.target.files[0] // ), // }); // } // }} // className="form-control input-field col-md-6 d-inline-block" // id="basicpill-phoneno-input" // />{" "} // {display ? ( // // ) : ( // "" // )} // // { // setRDApp(e.target.files[0]); // if (e.target.files && e.target.files[0]) { // setRDAppUrl({ // image: URL.createObjectURL( // e.target.files[0] // ), // }); // } // }} // className="form-control input-field col-md-6 d-inline-block" // id="basicpill-phoneno-input" // />{" "} // {display ? ( // // ) : ( // "" // )} // //
//
//
//
//
//
// //
//
//
//
//
//
// {/* */} //
//
//
//
//
// {/* */} //
// {/* */} //
//
// ); // } // export default MobileApp; import React, { useEffect, useState } from "react"; import swal from "sweetalert"; import ClipLoader from "react-spinners/ClipLoader"; import axios from "axios"; import { isAutheticated } from "src/auth"; function MobileApp() { const [loading, setLoading] = useState(false); const [PDApp, setPDApp] = useState(null); const [RDApp, setRDApp] = useState(null); const [SCApp, setSCApp] = useState(null); const [TMApp, setTMApp] = useState(null); const token = isAutheticated(); // URLs for the uploaded APKs const [PDAppUrl, setPDAppUrl] = useState(""); const [RDAppUrl, setRDAppUrl] = useState(""); const [SCAppUrl, setSCAppUrl] = useState(""); const [TMAppUrl, setTMAppUrl] = useState(""); useEffect(() => { async function getConfiguration() { try { const configDetails = await axios.get(`/api/config`, { headers: { Authorization: `Bearer ${token}`, }, }); const data = configDetails.data.result[0]?.mobileapp[0]; setPDAppUrl(data?.PDAppUrl || ""); setRDAppUrl(data?.RDAppUrl || ""); setSCAppUrl(data?.SCAppUrl || ""); setTMAppUrl(data?.TMAppUrl || ""); } catch (error) { console.error("Failed to fetch configuration", error); } } getConfiguration(); }, []); async function handelSubmit() { setLoading(true); const formData = new FormData(); if (PDApp) formData.append("PDApp", PDApp); if (RDApp) formData.append("RDApp", RDApp); if (SCApp) formData.append("SCApp", SCApp); if (TMApp) formData.append("TMApp", TMApp); try { const response = await axios.post(`/api/config/mobile-app`, formData, { headers: { Authorization: `Bearer ${token}`, "Content-Type": "multipart/form-data", }, }); setLoading(false); swal("Success!", response.data.message, "success"); // Update the APK URLs from response setPDAppUrl(response.data.PDAppUrl); setRDAppUrl(response.data.RDAppUrl); setSCAppUrl(response.data.SCAppUrl); setTMAppUrl(response.data.TMAppUrl); } catch (error) { setLoading(false); console.error("Failed to upload APKs", error); swal("Error", "Failed to upload APKs", "error"); } } return (

Mobile App

setPDApp(e.target.files[0])} className="form-control input-field mb-3" /> {PDAppUrl && ( Download PD App )}
setRDApp(e.target.files[0])} className="form-control input-field mb-3" /> {RDAppUrl && ( Download Retailer App )}
setSCApp(e.target.files[0])} className="form-control input-field mb-3" /> {SCAppUrl && ( Download SC App )}
setTMApp(e.target.files[0])} className="form-control input-field mb-3" /> {TMAppUrl && ( Download TM App )}
); } export default MobileApp;