diff --git a/src/containers/TheHeader.js b/src/containers/TheHeader.js index 381d923..c1d0de4 100644 --- a/src/containers/TheHeader.js +++ b/src/containers/TheHeader.js @@ -69,7 +69,7 @@ const TheHeader = ({ HOST_IP, showSidebar, setShowSidebar, API_KEY }) => { }; const handleupdate = (state) => { - if (state == "anyreadytoinstall" || state == "allreadytoinstall") { + if (state === "anyreadytoinstall" || state === "allreadytoinstall") { axios .put(`${HOST_IP}/api/${API_KEY}/config`, { swupdate2: { install: true }, @@ -83,7 +83,7 @@ const TheHeader = ({ HOST_IP, showSidebar, setShowSidebar, API_KEY }) => { toast.error(`Error occurred: ${error.message}`); }); } - if (state == "noupdates" || state == "unknown") { + if (state === "noupdates" || state === "unknown") { axios .put(`${HOST_IP}/api/${API_KEY}/config`, { swupdate2: { checkforupdate: true, install: false }, @@ -100,25 +100,25 @@ const TheHeader = ({ HOST_IP, showSidebar, setShowSidebar, API_KEY }) => { } const getValueState = (state) => { - if (state == "anyreadytoinstall" || state == "allreadytoinstall") { + if (state === "anyreadytoinstall" || state === "allreadytoinstall") { return "Update available"; } - else if (state == "noupdates" || state == "unknown") { + else if (state === "noupdates" || state === "unknown") { return "No Update"; } - else if (state == "installing"){ + else if (state === "installing"){ return "installing..." } } const getClassState = (state) => { - if (state == "anyreadytoinstall" || state == "allreadytoinstall") { + if (state === "anyreadytoinstall" || state === "allreadytoinstall") { return "updatebtn"; } - else if (state == "noupdates" || state == "unknown") { + else if (state === "noupdates" || state === "unknown") { return "checkbtn"; } - else if (state == "installing"){ + else if (state === "installing"){ return "installbtn" } } @@ -139,8 +139,8 @@ const TheHeader = ({ HOST_IP, showSidebar, setShowSidebar, API_KEY }) => {
handleupdate(swstate, e)}>
diff --git a/src/containers/TheSidebar.js b/src/containers/TheSidebar.js index 877a787..8f2671a 100644 --- a/src/containers/TheSidebar.js +++ b/src/containers/TheSidebar.js @@ -8,6 +8,7 @@ import { FaSignOutAlt, FaInfoCircle, FaExclamationTriangle, + FaUser, } from "react-icons/fa"; import { SiHomeassistant } from "react-icons/si"; import { MdSettingsRemote } from "react-icons/md"; @@ -123,6 +124,12 @@ const TheSidebar = ({ showSidebar, setShowSidebar, isMobile }) => {

About

+ +
  • itemClicked("account")}> +

    Account

    +
  • +
  • Logout

    diff --git a/src/routes.js b/src/routes.js index 159ede9..c22e493 100644 --- a/src/routes.js +++ b/src/routes.js @@ -13,6 +13,7 @@ const Bridge = React.lazy(() => import('./views/Bridge')); const HueBridge = React.lazy(() => import('./views/HueBridge')); const About = React.lazy(() => import('./views/About')); const Settings = React.lazy(() => import('./views/Settings')); +const Account = React.lazy(() => import('./views/Account')); const routes = [ { path: '/', exact: true, name: 'Groups', component: Groups }, @@ -29,6 +30,7 @@ const routes = [ { path: '/tradfri', exact: true, name: 'Tradfri', component: Tradfri }, { path: '/about', exact: true, name: 'About', component: About }, { path: '/settings', exact: true, name: 'Settings', component: Settings }, + { path: '/account', exact: true, name: 'Account', component: Account }, ]; export default routes; diff --git a/src/views/Account.js b/src/views/Account.js new file mode 100644 index 0000000..85883f7 --- /dev/null +++ b/src/views/Account.js @@ -0,0 +1,79 @@ +import { useState, useEffect } from "react"; +import axios from "axios"; +import { toast } from 'react-hot-toast'; + +const Account = ({ HOST_IP, API_KEY }) => { + const [email, setEmail] = useState(""); + const [pass, setPass] = useState(""); + const [pass1, setPass1] = useState(""); + + useEffect(() => { + axios + .get(`${HOST_IP}/api/${API_KEY}/config/users`) + .then((result) => { + setEmail(Object.keys(result.data)[0]); + }) + .catch((error) => { + console.error(error); + toast.error(`Error: ${error.message}`); + }); + }, [HOST_IP, API_KEY]); + + const onSubmit = (e) => { + if (pass !== pass1) { + console.error("Password not the same"); + toast.error("Password not the same"); + } else if(pass === "") { + console.error("Password can not be empty"); + toast.error("Password can not be empty"); + } else if(pass === pass1) { + e.preventDefault(); + axios + .put(`${HOST_IP}/api/${API_KEY}/config`, { + users: { [email]: { password: pass } }, + }) + .then((fetchedData) => { + console.log(fetchedData.data); + toast.success("Successfully saved"); + }) + .catch((error) => { + console.error(error); + toast.error(`Error: ${error.message}`); + }); + } + }; + + return ( +
    + +
    +
    Change password for {email}
    +
    onSubmit(e)}> +
    + + setPass(e.target.value)} + /> +
    +
    + + setPass1(e.target.value)} + /> +
    +
    + +
    +
    +
    +
    + ); +}; + +export default Account; \ No newline at end of file