2021-05-12 02:10:36 +00:00
|
|
|
import React, { useContext } from "react"
|
2021-05-23 15:35:38 +00:00
|
|
|
import { faShare, faStar, faTrash, faUser } from "@fortawesome/free-solid-svg-icons"
|
2021-05-18 15:51:36 +00:00
|
|
|
import SummaryBase from "../base/summary/SummaryBase"
|
|
|
|
import SummaryLeft from "../base/summary/SummaryLeft"
|
|
|
|
import SummaryLabels from "../base/summary/SummaryLabels"
|
|
|
|
import SummaryButton from "../base/summary/SummaryButton"
|
|
|
|
import SummaryRight from "../base/summary/SummaryRight"
|
2021-05-24 12:13:24 +00:00
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
|
2021-05-23 15:56:25 +00:00
|
|
|
import ContextUser from "../../contexts/ContextUser"
|
2021-05-24 12:13:24 +00:00
|
|
|
import useStrings from "../../hooks/useStrings"
|
2021-05-12 02:10:36 +00:00
|
|
|
|
|
|
|
|
2021-05-23 03:03:41 +00:00
|
|
|
/**
|
|
|
|
* A {@link SummaryBase} representing a N.E.S.T. user.
|
|
|
|
*
|
|
|
|
* @param user - The user to represent.
|
2021-05-23 15:35:38 +00:00
|
|
|
* @param shareWithUser - Async function to share a repository with an user, to be passed to {@link SummaryUser}.
|
|
|
|
* @param unshareWithUser - Async function to unshare a repository with an user, to be passed to {@link SummaryUser}.
|
2021-05-23 03:03:41 +00:00
|
|
|
* @param destroyUser - Async function <string> to destroy an user from the frontend.
|
|
|
|
* @param running - Whether another request is already running.
|
|
|
|
* @param props - Additional props to pass to the summary.
|
|
|
|
* @returns {JSX.Element}
|
|
|
|
* @constructor
|
|
|
|
*/
|
2021-05-23 15:35:38 +00:00
|
|
|
export default function SummaryUser({ user, shareWithUser, unshareWithUser, destroyUser, running, ...props }) {
|
2021-05-24 12:13:24 +00:00
|
|
|
const strings = useStrings()
|
2021-05-23 15:56:25 +00:00
|
|
|
const {user: loggedUser} = useContext(ContextUser)
|
2021-05-12 02:10:36 +00:00
|
|
|
|
|
|
|
return (
|
2021-05-18 17:15:53 +00:00
|
|
|
<SummaryBase {...props}>
|
2021-05-18 15:51:36 +00:00
|
|
|
<SummaryLeft
|
|
|
|
icon={user.isAdmin ? faStar : faUser}
|
|
|
|
title={user.username}
|
|
|
|
subtitle={user.email}
|
2021-05-23 15:35:38 +00:00
|
|
|
disabled={running}
|
2021-05-18 15:51:36 +00:00
|
|
|
/>
|
|
|
|
<SummaryLabels
|
|
|
|
upperLabel={strings.type}
|
|
|
|
upperValue={user.isAdmin ? strings.admin : strings.user}
|
|
|
|
/>
|
2021-05-23 15:56:25 +00:00
|
|
|
{(shareWithUser && loggedUser["email"] !== user["email"]) ?
|
2021-05-23 15:35:38 +00:00
|
|
|
<SummaryButton
|
|
|
|
color={"Green"}
|
|
|
|
icon={faShare}
|
|
|
|
onClick={async event => {
|
|
|
|
event.stopPropagation()
|
|
|
|
await shareWithUser(user)
|
|
|
|
}}
|
|
|
|
disabled={running}
|
|
|
|
>
|
|
|
|
{strings.share}
|
|
|
|
</SummaryButton>
|
|
|
|
: null}
|
2021-05-23 15:56:25 +00:00
|
|
|
{(unshareWithUser && loggedUser["email"] !== user["email"]) ?
|
2021-05-23 15:35:38 +00:00
|
|
|
<SummaryButton
|
|
|
|
color={"Red"}
|
|
|
|
icon={<FontAwesomeIcon icon={faShare} flip={"horizontal"}/>}
|
|
|
|
onClick={async event => {
|
|
|
|
event.stopPropagation()
|
|
|
|
await unshareWithUser(user)
|
|
|
|
}}
|
|
|
|
disabled={running}
|
|
|
|
>
|
|
|
|
{strings.unshare}
|
|
|
|
</SummaryButton>
|
|
|
|
: null}
|
|
|
|
{destroyUser ?
|
|
|
|
<SummaryButton
|
|
|
|
color={"Red"}
|
|
|
|
icon={faTrash}
|
|
|
|
onClick={async event => {
|
|
|
|
event.stopPropagation()
|
|
|
|
// TODO: Errors are not caught here. Where should they be displayed?
|
|
|
|
await destroyUser(user["email"])
|
|
|
|
}}
|
|
|
|
disabled={running}
|
|
|
|
>
|
|
|
|
{strings.delete}
|
|
|
|
</SummaryButton>
|
|
|
|
: null}
|
2021-05-18 15:51:36 +00:00
|
|
|
<SummaryRight/>
|
|
|
|
</SummaryBase>
|
2021-05-12 02:10:36 +00:00
|
|
|
)
|
|
|
|
}
|