diff --git a/index.html b/index.html index d508d81..b1621e9 100644 --- a/index.html +++ b/index.html @@ -752,20 +752,20 @@ dateofbirth: "" }; - const getDataContentProfileProfile = async () => { + const getDataFromBackend = async (path) => { try { - const data = await axios.get("https://ggu18j.sse.codesandbox.io/profile"); - console.log(data.data.profile); - return data.data.profile; + const data = await axios.get(`https://ggu18j.sse.codesandbox.io/${path}`); + console.log(data.data[path]); + return data.data[path]; } catch (err) { console.log(err); } }; - const setDataContentProfileProfile = async (json) => { + const saveDataToBackend = async (path, json) => { try { - const data = await axios.post("https://ggu18j.sse.codesandbox.io/profile", json); - return data.data.profile; + const data = await axios.post(`https://ggu18j.sse.codesandbox.io/${path}`, json); + return data.data[path]; } catch (err) { console.log(err); } @@ -789,8 +789,8 @@ // set data navbar first time (async () => { setDataProfileOnNavbar(undefined, undefined, true); - const getData = await getDataContentProfileProfile(); - setDataProfileOnNavbar(getData.name, getData.profileUrlOrBase64, false); + const getData1 = await getDataFromBackend("profile"); + setDataProfileOnNavbar(getData1.name, getData1.profileUrlOrBase64, false); })(); const hiddenModal = (id, funcMove, funcParams) => setTimeout(() => { $(`#${id}`).modal('hide'); funcMove(funcParams) }, 900); @@ -919,6 +919,7 @@ const swithToDarkMode = () => { + let togle = false; const navBar = document.querySelector("nav"); const searchButtonNavbar = document.querySelector(".input-group-append"); const myNameOnNavbar = document.querySelectorAll("span")[6]; @@ -926,8 +927,8 @@ const textTitle = document.querySelector("h1"); const buttonOnHead = document.querySelector(".btn-toolbar"); const footerAbove = document.querySelector("footer"); - idContainerFluid.classList.forEach((it) => { - if (it == "bg-dark") { + idContainerFluid.classList.forEach(async (it) => { + if (it == "bg-dark" && togle === false) { searchButtonNavbar.innerHTML = ``; myNameOnNavbar.classList.replace("text-white", "text-gray-600"); paddingBeginPageContent.className = "bg-light"; @@ -939,7 +940,7 @@ idContainerFluid.classList.remove("bg-dark"); footerAbove.classList.replace("bg-dark", "bg-white"); footerAbove.children[0].children[0].innerHTML = `Copyright © Dashboard 2022`; - } else if (it != "bg-dark") { + } else if (it != "bg-dark" && togle === false) { searchButtonNavbar.innerHTML = ``; myNameOnNavbar.classList.replace("text-gray-600", "text-white"); paddingBeginPageContent.className = "bg-dark"; @@ -1125,7 +1126,10 @@ return ``; } else { let [datefrom, dateto] = [it.datefrom.split("/"), it.dateto.split("/")]; - [datefrom, dateto] = [`${datefrom[0]} ${monthNames[Math.ceil(dateto[1]) - 1]} ${dateto[2]}`, `${dateto[0]} ${monthNames[Math.ceil(dateto[1]) - 1]} ${dateto[2]}`]; + [datefrom, dateto] = [ + `${datefrom[0]} ${monthNames[Math.ceil(datefrom[1]) - 1]} ${datefrom[2]}`, + `${dateto[0]} ${monthNames[Math.ceil(dateto[1]) - 1]} ${dateto[2]}` + ]; return it = `${index + 1}Rp${it.earning.toLocaleString("id", "ID")}${datefrom}${dateto}`; } }); @@ -1232,7 +1236,7 @@ idContainerFluid.innerHTML = `

My Profile









`; setDataProfileOnNavbar(undefined, undefined, true); (async () => { - const dataContentProfileProfile = await getDataContentProfileProfile(); + const dataContentProfileProfile = await getDataFromBackend("profile"); if (dataContentAdminEarnings) { idContainerFluid.innerHTML = `

My Profile

avatar









`; const getSelectorProfileSettings = document.querySelectorAll('[id=profile-settings]'); @@ -1266,7 +1270,7 @@ }); const getSelectorProfileSettings = document.querySelectorAll('[id=profile-settings]'); - await setDataContentProfileProfile( + await saveDataToBackend("profile", { profile: { profileUrlOrBase64: getSelectorProfileSettings[1].value.length == 0 ? getSelectorProfileSettings[0].src : await toBase64(getSelectorProfileSettings[1].files[0]),