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"
|
2021-05-17 22:22:11 +00:00
|
|
|
import Localization from "../../Localization"
|
2021-05-12 02:10:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
export default function SummaryUser({ user, destroyUser, running, ...props }) {
|
|
|
|
const { user: loggedUser } = useContext(ContextUser)
|
|
|
|
|
|
|
|
const buttons = <>
|
|
|
|
{loggedUser.email !== user.email ?
|
|
|
|
<Button
|
|
|
|
color={"Red"}
|
|
|
|
icon={faTrash}
|
2021-05-12 02:34:54 +00:00
|
|
|
onClick={async event => {
|
|
|
|
event.stopPropagation()
|
2021-05-12 02:10:36 +00:00
|
|
|
// TODO: Errors are not caught here. Where should they be displayed?
|
|
|
|
await destroyUser(user["email"])
|
|
|
|
}}
|
|
|
|
disabled={running}
|
|
|
|
>
|
2021-05-17 22:22:11 +00:00
|
|
|
{Localization.delete}
|
2021-05-12 02:10:36 +00:00
|
|
|
</Button>
|
|
|
|
: null}
|
|
|
|
</>
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Summary
|
|
|
|
icon={user.isAdmin ? faStar : faUser}
|
|
|
|
title={user.username}
|
|
|
|
subtitle={user.email}
|
2021-05-17 22:22:11 +00:00
|
|
|
upperLabel={Localization.type}
|
|
|
|
upperValue={user.isAdmin ? Localization.admin : Localization.user}
|
2021-05-12 02:10:36 +00:00
|
|
|
buttons={buttons}
|
|
|
|
{...props}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|