2021-05-10 14:21:19 +00:00
|
|
|
import React, { useContext } from "react"
|
2021-04-26 16:37:14 +00:00
|
|
|
import Style from "./RepositorySummaryBase.module.css"
|
2021-04-24 02:23:23 +00:00
|
|
|
import classNames from "classnames"
|
|
|
|
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"
|
2021-04-29 14:58:31 +00:00
|
|
|
import Button from "../base/Button"
|
2021-04-24 02:23:23 +00:00
|
|
|
import { faArchive, faPencilAlt, faTrash } from "@fortawesome/free-solid-svg-icons"
|
2021-05-10 13:22:07 +00:00
|
|
|
import { useHistory } from "react-router"
|
2021-05-10 14:21:19 +00:00
|
|
|
import useData from "../../hooks/useData"
|
|
|
|
import ContextUser from "../../contexts/ContextUser"
|
2021-04-24 02:23:23 +00:00
|
|
|
|
|
|
|
|
2021-04-25 15:22:52 +00:00
|
|
|
/**
|
|
|
|
* A long line representing a repository in a list.
|
|
|
|
*
|
2021-05-10 13:22:07 +00:00
|
|
|
* @param id - The id of the repository.
|
|
|
|
* @param owner - The owner of the repository.
|
2021-04-25 15:22:52 +00:00
|
|
|
* @param icon - The FontAwesome IconDefinition that represents the repository.
|
2021-05-02 16:10:09 +00:00
|
|
|
* @param name - The title of the repository.
|
|
|
|
* @param start - The start date of the repository.
|
|
|
|
* @param end - The end date of the repository.
|
|
|
|
* @param isActive - Whether the repository is active or not.
|
2021-04-25 15:22:52 +00:00
|
|
|
* @param canDelete - If the Delete button should be displayed or not.
|
|
|
|
* @param canEdit - If the Edit button should be displayed or not.
|
|
|
|
* @param canArchive - If the Archive button should be displayed or not.
|
|
|
|
* @param className - Additional class(es) to be added to the outer box.
|
|
|
|
* @param props - Additional props to pass to the outer box.
|
|
|
|
* @returns {JSX.Element}
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
export default function RepositorySummaryBase(
|
2021-05-10 13:22:07 +00:00
|
|
|
{ id, owner, icon, name, start, end, isActive, canDelete, canEdit, canArchive, className, ...props }
|
2021-04-25 15:22:52 +00:00
|
|
|
) {
|
2021-05-10 14:21:19 +00:00
|
|
|
const {fetchDataAuth} = useContext(ContextUser)
|
2021-05-10 13:22:07 +00:00
|
|
|
const {history} = useHistory()
|
2021-05-10 14:21:19 +00:00
|
|
|
const {fetchNow: archiveThis} = useData(fetchDataAuth, "PATCH", `/api/v1/repositories/${id}`, {"close": true})
|
|
|
|
const {fetchNow: unarchiveThis} = useData(fetchDataAuth, "PATCH", `/api/v1/repositories/${id}`, {"open": true})
|
|
|
|
const {fetchNow: deletThis} = useData(fetchDataAuth, "DELETE", `/api/v1/repositories/${id}`)
|
2021-05-10 13:22:07 +00:00
|
|
|
|
2021-04-24 02:23:23 +00:00
|
|
|
return (
|
|
|
|
<div className={classNames(Style.RepositorySummary, className)} {...props}>
|
|
|
|
<div className={Style.Left}>
|
|
|
|
<div className={Style.IconContainer}>
|
|
|
|
<FontAwesomeIcon icon={icon}/>
|
|
|
|
</div>
|
|
|
|
<div className={Style.Title}>
|
2021-05-02 16:10:09 +00:00
|
|
|
{name}
|
2021-04-24 02:23:23 +00:00
|
|
|
</div>
|
2021-05-10 13:22:07 +00:00
|
|
|
<div className={Style.Author}>
|
|
|
|
{owner["username"]}
|
2021-04-24 02:23:23 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className={Style.Middle}>
|
2021-05-10 13:22:07 +00:00
|
|
|
<div className={Style.StartDate}>
|
|
|
|
Start: {start}
|
|
|
|
</div>
|
|
|
|
<div className={Style.EndDate}>
|
|
|
|
End: {end}
|
|
|
|
</div>
|
2021-04-24 02:23:23 +00:00
|
|
|
</div>
|
|
|
|
<div className={Style.Right}>
|
|
|
|
{canDelete ?
|
2021-05-10 13:22:07 +00:00
|
|
|
<Button
|
|
|
|
color={"Red"}
|
|
|
|
icon={faTrash}
|
2021-05-10 14:21:19 +00:00
|
|
|
onClick={deletThis}
|
2021-05-10 13:22:07 +00:00
|
|
|
>
|
|
|
|
Delete
|
|
|
|
</Button>
|
2021-04-24 02:23:23 +00:00
|
|
|
: null}
|
|
|
|
{canEdit ?
|
2021-05-10 13:22:07 +00:00
|
|
|
<Button
|
|
|
|
color={"Yellow"}
|
|
|
|
icon={faPencilAlt}
|
|
|
|
onClick={() => history.push(`/repositories/${id}/edit`)}
|
|
|
|
>
|
|
|
|
Edit
|
|
|
|
</Button>
|
2021-04-24 02:23:23 +00:00
|
|
|
: null}
|
|
|
|
{canArchive ?
|
2021-05-10 13:22:07 +00:00
|
|
|
<Button
|
|
|
|
color={"Grey"}
|
|
|
|
icon={faArchive}
|
2021-05-10 14:21:19 +00:00
|
|
|
onClick={isActive ? archiveThis : unarchiveThis}
|
2021-05-10 13:22:07 +00:00
|
|
|
>
|
|
|
|
{isActive ? "Archive" : "Unarchive"}
|
|
|
|
</Button>
|
2021-04-24 02:23:23 +00:00
|
|
|
: null}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|