-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from hendriksen-mark/main
add remove apiusers
- Loading branch information
Showing
6 changed files
with
126 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { MdDeleteForever } from "react-icons/md"; | ||
import { RiApps2Fill } from "react-icons/ri"; | ||
|
||
import axios from "axios"; | ||
import { confirmAlert } from "react-confirm-alert"; // Import | ||
import "react-confirm-alert/src/react-confirm-alert.css"; // Import css | ||
import { toast } from 'react-hot-toast'; | ||
|
||
const Users = ({ HOST_IP, api_key, id, user }) => { | ||
const deleteAlert = () => { | ||
confirmAlert({ | ||
title: "Delete User " + user["name"], | ||
message: "Are you sure to do this?", | ||
buttons: [ | ||
{ | ||
label: "Yes", | ||
onClick: () => deleteUser(), | ||
}, | ||
{ | ||
label: "No", | ||
}, | ||
], | ||
}); | ||
}; | ||
|
||
const deleteUser = () => { | ||
axios | ||
.delete(`${HOST_IP}/api/${api_key}/config/whitelist/${id}`) | ||
.then((fetchedData) => { | ||
//console.log(fetchedData.data); | ||
toast.success("User successfully deleted"); | ||
}) | ||
.catch((error) => { | ||
console.error(error); | ||
toast.error(`Error occurred: ${error.message}`); | ||
}); | ||
}; | ||
|
||
return ( | ||
<div className="devicecard device"> | ||
<div className="row1"> | ||
<div className="icon"> | ||
<RiApps2Fill /> | ||
</div> | ||
<div className="text">{user["name"]}</div> | ||
</div> | ||
<div className="row2"> | ||
<div className="text"> | ||
Last use date: {user["last use date"]} <br /> | ||
Create date: {user["create date"]} <br /> | ||
</div> | ||
</div> | ||
<div className="row3"> | ||
<div className="iconbtn red"> | ||
<MdDeleteForever title="Delete" onClick={() => deleteAlert()} /> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Users; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { useState, useEffect } from "react"; | ||
import axios from "axios"; | ||
import Users from "../containers/Users"; | ||
import { toast } from 'react-hot-toast'; | ||
|
||
const Config = ({ HOST_IP, API_KEY }) => { | ||
const [whitelist, setWhitelist] = useState({}); | ||
|
||
useEffect(() => { | ||
const fetchConfig = () => { | ||
if (API_KEY !== undefined) { | ||
axios | ||
.get(`${HOST_IP}/api/${API_KEY}/config`) | ||
.then((fetchedData) => { | ||
console.log(fetchedData.data); | ||
setWhitelist(fetchedData.data.whitelist); | ||
}) | ||
.catch((error) => { | ||
console.error(error); | ||
toast.error(`Error occurred: ${error.message}`, { duration: 5000 }); | ||
}); | ||
} | ||
}; | ||
|
||
fetchConfig(); | ||
const interval = setInterval(() => { | ||
fetchConfig(); | ||
}, 2000); // <<-- ⏱ 1000ms = 1s | ||
return () => clearInterval(interval); | ||
}, [HOST_IP, API_KEY]); | ||
|
||
return ( | ||
<div className="content"> | ||
<div className="inner"> | ||
<div className="devicecontainer"> | ||
<div className="cardGrid"> | ||
{Object.entries(whitelist).map(([id, user]) => ( | ||
<Users | ||
key={id} | ||
HOST_IP={HOST_IP} | ||
api_key={API_KEY} | ||
id={id} | ||
user={user} | ||
/> | ||
))} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Config; |