1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-26 23:14:19 +00:00
pds-2021-g2-nest/code/frontend/src/components/interactive/SummaryUser.js

39 lines
1.1 KiB
JavaScript
Raw Normal View History

2021-05-12 02:10:36 +00:00
import React, { useContext } from "react"
import Summary from "../base/Summary"
import { faStar, faTrash, faUser } from "@fortawesome/free-solid-svg-icons"
import Button from "../base/Button"
import ContextUser from "../../contexts/ContextUser"
export default function SummaryUser({ user, destroyUser, running, ...props }) {
const { user: loggedUser } = useContext(ContextUser)
const buttons = <>
{loggedUser.email !== user.email ?
<Button
color={"Red"}
icon={faTrash}
onClick={async () => {
// TODO: Errors are not caught here. Where should they be displayed?
await destroyUser(user["email"])
}}
disabled={running}
>
Delete
</Button>
: null}
</>
return (
<Summary
icon={user.isAdmin ? faStar : faUser}
title={user.username}
subtitle={user.email}
upperLabel={"Tipo"}
upperValue={user.isAdmin ? "Amministratore" : "Utente"}
buttons={buttons}
{...props}
/>
)
}