mirror of
https://github.com/pds-nest/nest.git
synced 2024-11-22 04:54:18 +00:00
✨ Complete repository share
This commit is contained in:
parent
1928435f6f
commit
7b0b028a50
5 changed files with 24 additions and 8 deletions
|
@ -54,11 +54,17 @@ export default {
|
|||
emptyMenu: "Non c'è nulla qui.",
|
||||
delete: "Elimina",
|
||||
share: "Condividi",
|
||||
unshare: "Rimuovi",
|
||||
archive: "Archivia",
|
||||
edit: "Modifica",
|
||||
created: "Creata",
|
||||
archived: "Archiviata",
|
||||
|
||||
// TODO: migliorare, maybe?
|
||||
repoShare: "Condivisioni",
|
||||
availableUsers: "Utenti disponibili",
|
||||
sharingWith: "In condivisione con",
|
||||
|
||||
alerts: "Allarmi",
|
||||
alertTitle: "I tuoi allarmi",
|
||||
alertCreate: "Crea un allarme",
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import React from "react"
|
||||
import React, { useContext } from "react"
|
||||
import BoxFullScrollable from "../base/BoxFullScrollable"
|
||||
import Loading from "../base/Loading"
|
||||
import SummaryRepository from "./SummaryRepository"
|
||||
import Empty from "./Empty"
|
||||
import ContextUser from "../../contexts/ContextUser"
|
||||
|
||||
|
||||
/**
|
||||
|
@ -34,6 +35,8 @@ export default function BoxRepositories(
|
|||
...props
|
||||
})
|
||||
{
|
||||
const {user} = useContext(ContextUser)
|
||||
|
||||
let contents
|
||||
if(loading) {
|
||||
contents = <Loading/>
|
||||
|
@ -47,7 +50,7 @@ export default function BoxRepositories(
|
|||
key={repo["id"]}
|
||||
repo={repo}
|
||||
view={view ? () => view(repo["id"]) : null}
|
||||
share={share ? () => share(repo["id"]) : null}
|
||||
share={(share && user["email"] === repo["owner"]["email"]) ? () => share(repo["id"]) : null}
|
||||
archive={archive ? () => archive(repo["id"]) : null}
|
||||
edit={edit ? () => edit(repo["id"]) : null}
|
||||
destroy={destroy ? () => destroy(repo["id"]) : null}
|
||||
|
|
|
@ -7,6 +7,7 @@ import SummaryLabels from "../base/summary/SummaryLabels"
|
|||
import SummaryButton from "../base/summary/SummaryButton"
|
||||
import SummaryRight from "../base/summary/SummaryRight"
|
||||
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"
|
||||
import ContextUser from "../../contexts/ContextUser"
|
||||
|
||||
|
||||
/**
|
||||
|
@ -23,6 +24,7 @@ import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"
|
|||
*/
|
||||
export default function SummaryUser({ user, shareWithUser, unshareWithUser, destroyUser, running, ...props }) {
|
||||
const { strings } = useContext(ContextLanguage)
|
||||
const {user: loggedUser} = useContext(ContextUser)
|
||||
|
||||
return (
|
||||
<SummaryBase {...props}>
|
||||
|
@ -36,7 +38,7 @@ export default function SummaryUser({ user, shareWithUser, unshareWithUser, dest
|
|||
upperLabel={strings.type}
|
||||
upperValue={user.isAdmin ? strings.admin : strings.user}
|
||||
/>
|
||||
{shareWithUser ?
|
||||
{(shareWithUser && loggedUser["email"] !== user["email"]) ?
|
||||
<SummaryButton
|
||||
color={"Green"}
|
||||
icon={faShare}
|
||||
|
@ -49,7 +51,7 @@ export default function SummaryUser({ user, shareWithUser, unshareWithUser, dest
|
|||
{strings.share}
|
||||
</SummaryButton>
|
||||
: null}
|
||||
{unshareWithUser ?
|
||||
{(unshareWithUser && loggedUser["email"] !== user["email"]) ?
|
||||
<SummaryButton
|
||||
color={"Red"}
|
||||
icon={<FontAwesomeIcon icon={faShare} flip={"horizontal"}/>}
|
||||
|
|
|
@ -5,6 +5,7 @@ import useBackendViewset from "../hooks/useBackendViewset"
|
|||
import BoxRepositories from "../components/interactive/BoxRepositories"
|
||||
import { useHistory } from "react-router"
|
||||
import ContextLanguage from "../contexts/ContextLanguage"
|
||||
import ContextUser from "../contexts/ContextUser"
|
||||
|
||||
|
||||
export default function PageRepositories({ children, className, ...props }) {
|
||||
|
|
|
@ -6,12 +6,14 @@ import Style from "./PageShare.module.css"
|
|||
import BoxUserList from "../components/interactive/BoxUserList"
|
||||
import useBackendViewset from "../hooks/useBackendViewset"
|
||||
import { useParams } from "react-router"
|
||||
import ContextUser from "../contexts/ContextUser"
|
||||
|
||||
|
||||
export default function PageShare({ className, ...props }) {
|
||||
const { strings } = useContext(ContextLanguage)
|
||||
const {user: loggedUser} = useContext(ContextUser)
|
||||
const { id } = useParams()
|
||||
const {resources: users} = useBackendViewset(
|
||||
const {resources: users, running: usersBvRunning} = useBackendViewset(
|
||||
"/api/v1/users/",
|
||||
"email",
|
||||
{
|
||||
|
@ -24,7 +26,7 @@ export default function PageShare({ className, ...props }) {
|
|||
action: false,
|
||||
}
|
||||
)
|
||||
const {resources: authorizations, createResource: createAuthorization, destroyResource: destroyAuthorization} = useBackendViewset(
|
||||
const {resources: authorizations, createResource: createAuthorization, destroyResource: destroyAuthorization, running: authBvRunning} = useBackendViewset(
|
||||
`/api/v1/repositories/${id}/authorizations/`,
|
||||
"email",
|
||||
{
|
||||
|
@ -61,15 +63,17 @@ export default function PageShare({ className, ...props }) {
|
|||
</BoxHeader>
|
||||
<BoxUserList
|
||||
className={Style.UserList}
|
||||
users={users.filter(user => !authorizations.map(a => a.email).includes(user.email))}
|
||||
users={users.filter(user => user["email"] !== loggedUser["email"] && !authorizations.map(a => a.email).includes(user.email))}
|
||||
shareWithUser={shareWith}
|
||||
header={strings.availableUsers}
|
||||
running={usersBvRunning && authBvRunning}
|
||||
/>
|
||||
<BoxUserList
|
||||
className={Style.SharingWith}
|
||||
users={users.filter(user => authorizations.map(a => a.email).includes(user.email))}
|
||||
users={users.filter(user => user["email"] === loggedUser["email"] || authorizations.map(a => a.email).includes(user.email))}
|
||||
unshareWithUser={unshareWith}
|
||||
header={strings.sharingWith}
|
||||
running={usersBvRunning && authBvRunning}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue