-
Notifications
You must be signed in to change notification settings - Fork 72
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 #19 from hack3r-0m/adminPortal
admin page added
- Loading branch information
Showing
6 changed files
with
208 additions
and
35,525 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,99 @@ | ||
import React, { useState } from 'react' | ||
import axios from 'axios'; | ||
import CircularProgress from '@material-ui/core/CircularProgress'; | ||
|
||
const Admin = ({ item, token, signerAddress }) => { | ||
const [approved, setApproved] = useState(false); | ||
const [declined, setDeclined] = useState(false); | ||
const [error, setError] = useState(''); | ||
const [loading, setLoading] = useState(false); | ||
|
||
const approve = async (e, _id) => { | ||
try { | ||
setLoading(true); | ||
console.log("Approving id", _id) | ||
const res = await axios.post("http://127.0.0.1:8080/approve", { | ||
id: _id, | ||
withCredentials: true, | ||
credentials: "include", | ||
}, { | ||
headers: { | ||
address: signerAddress, | ||
token: token | ||
} | ||
}); | ||
console.log(res.data) | ||
setApproved(true); | ||
setLoading(false); | ||
} catch (e) { | ||
setLoading(false); | ||
console.error(e); | ||
setError('Something went wrong...'); | ||
} | ||
} | ||
const decline = async (e, _id) => { | ||
try { | ||
setLoading(true); | ||
const res = await axios.post("http://127.0.0.1:8080/decline", { | ||
id: _id, | ||
withCredentials: true, | ||
credentials: "include", | ||
}, { | ||
headers: { | ||
address: signerAddress, | ||
token: token | ||
} | ||
}); | ||
console.log(res.data) | ||
setDeclined(true); | ||
setLoading(false); | ||
} catch (e) { | ||
setLoading(false); | ||
console.error(e); | ||
setError('Something went wrong...'); | ||
} | ||
} | ||
|
||
if (loading) { | ||
return ( | ||
<CircularProgress color="secondary" /> | ||
) | ||
} | ||
if (error) { | ||
return ( | ||
<div style={{ width: 'max-content', border: '2px dashed black', margin: '5px 0' }}> | ||
<p>{error}</p> | ||
</div> | ||
) | ||
} | ||
if (approved) { | ||
return ( | ||
<div style={{ width: 'max-content', border: '2px dashed black', margin: '5px 0' }}> | ||
<p>Approved Successfully!</p> | ||
</div> | ||
) | ||
} | ||
|
||
if (declined) { | ||
return ( | ||
<div style={{ width: 'max-content', border: '2px dashed black', margin: '5px 0' }}> | ||
<p>Declined Successfully!</p> | ||
</div> | ||
) | ||
} | ||
|
||
return ( | ||
<div style={{ width: 'max-content', border: '2px dashed black', margin: '5px 0' }}> | ||
<p>ObjectId: {item._id}</p> | ||
<p>Name: {item.name}</p> | ||
<p>Description: {item.description}</p> | ||
<p>Image URL: ${item.image}</p> | ||
<p>External URL: ${item.externam_url}</p> | ||
<p>Timestamp: ${item.timestamp}</p> | ||
<button value={item._id} onClick={(e) => approve(e, item._id)}>Approve</button> | ||
<button value={item._id} onClick={(e) => decline(e, item._id)}>Decline</button> | ||
</div> | ||
) | ||
} | ||
|
||
export default Admin; |
Oops, something went wrong.