Commit 8f8b3160 authored by Karen Konou's avatar Karen Konou

[Team management] works in box

parent 1c33ebf2
Pipeline #3067 failed with stage
in 0 seconds
......@@ -2,12 +2,20 @@ module Gargantext.Components.Forest.Tree.Node.Action.ManageTeam where
import Gargantext.Prelude
import Gargantext.Components.Forest.Tree.Node.Tools (panel)
import Gargantext.Sessions (Session(..))
import Effect.Aff (launchAff_)
import Effect.Class (liftEffect)
import Gargantext.Components.Forest.Tree.Node.Tools as Tools
import Gargantext.Components.GraphQL.Endpoints (deleteTeamMembership, getTeam)
import Gargantext.Components.GraphQL.Team (TeamMember)
import Gargantext.Config.REST (AffRESTError, logRESTError)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Sessions (Session)
import Gargantext.Types (ID, NodeType)
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Toestand as T2
import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
here :: R2.Here
here = R2.here "Gargantext.Components.Forest.Tree.Node.Action.ManageTeam"
......@@ -23,5 +31,67 @@ actionManageTeam = R.createElement actionManageTeamCpt
actionManageTeamCpt :: R.Component ActionManageTeam
actionManageTeamCpt = here.component "actionManageTeam" cpt where
cpt _ _ = do
pure $ H.text "todo"
cpt {id, session} _ = do
reload <- T.useBox T2.newReload
_ <- T.useLive T.unequal reload
useLoader { errorHandler
, loader: loadTeam
, path: { nodeId: id, session }
, render: \team -> teamLayoutRows { team
, nodeId: id
, session
, reload
}
}
where
errorHandler = logRESTError here "teamLayout"
type TeamProps =
( nodeId :: ID
, session :: Session
, team :: Array TeamMember
, reload :: T.Box T2.Reload )
teamLayoutRows :: R2.Leaf TeamProps
teamLayoutRows = R2.leafComponent teamLayoutRowsCpt
teamLayoutRowsCpt :: R.Component TeamProps
teamLayoutRowsCpt = here.component "teamLayoutRows" cpt where
cpt { team, nodeId, session, reload } _ = do
pure $ Tools.panel (map makeTeam team) (H.div {} [])
where
makeTeam { username, shared_folder_id } = H.div {className: "from-group row"} [ H.div { className: "col-8" } [ H.text username ]
, H.a { className: "text-danger col-2 fa fa-times"
, title: "Remove user from team"
, type: "button"
, on: {click: submit shared_folder_id}
} []
]
submit sharedFolderId _ = do
launchAff_ $ saveDeleteTeam { session, nodeId, sharedFolderId }
liftEffect $ T2.reload reload
-------------------------------------------------------------
type LoadProps =
(
session :: Session,
nodeId :: Int
)
loadTeam :: Record LoadProps -> AffRESTError (Array TeamMember)
loadTeam { session, nodeId } = getTeam session nodeId
type DeleteProps =
(
session :: Session,
nodeId :: Int,
sharedFolderId :: Int
)
saveDeleteTeam ∷ Record DeleteProps -> AffRESTError Int
saveDeleteTeam { session, nodeId, sharedFolderId } = deleteTeamMembership session sharedFolderId nodeId
module Gargantext.Components.Nodes.Team where
import Gargantext.Prelude
import Effect.Class (liftEffect)
import Gargantext.Components.App.Store (Boxes)
import Gargantext.Components.FolderView as FV
import Gargantext.Components.GraphQL.Endpoints (getTeam, deleteTeamMembership)
import Gargantext.Components.GraphQL.Team (TeamMember)
import Gargantext.Config.REST (AffRESTError, logRESTError)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Sessions (Session)
import Gargantext.Types (ID)
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Toestand as T2
import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
here :: R2.Here
here = R2.here "Gargantext.Components.Nodes.Team"
type Props =
( boxes :: Boxes
, nodeId :: ID
, session :: Session )
teamLayout :: R2.Leaf Props
teamLayout = R2.leafComponent teamLayoutCpt
teamLayoutCpt :: R.Component Props
teamLayoutCpt = here.component "teamLayout" cpt where
cpt props _ = do
pure $ R.fragment [
FV.folderView props
, teamLayoutMain props
]
teamLayoutMain :: R2.Leaf Props
teamLayoutMain = R2.leafComponent teamLayoutMainCpt
teamLayoutMainCpt :: R.Component Props
teamLayoutMainCpt = here.component "teamLayoutMain" cpt where
cpt { nodeId, session, boxes } _ = do
reload <- T.useBox T2.newReload
_ <- T.useLive T.unequal reload
useLoader { errorHandler
, loader: loadTeam
, path: { nodeId, session }
, render: \team -> teamLayoutRows { boxes
, team
, nodeId
, session
, reload
}
}
where
errorHandler = logRESTError here "teamLayout"
type TeamProps =
( boxes :: Boxes
, nodeId :: ID
, session :: Session
, team :: Array TeamMember
, reload :: T.Box T2.Reload )
teamLayoutRows :: R2.Leaf TeamProps
teamLayoutRows = R2.leafComponent teamLayoutRowsCpt
teamLayoutRowsCpt :: R.Component TeamProps
teamLayoutRowsCpt = here.component "teamLayoutRows" cpt where
cpt { team, nodeId, session, reload } _ = do
pure $ H.div {} $ map makeTeam team
where
makeTeam { username, shared_folder_id } = H.div {} [H.text username, H.button {className: "btn btn-danger", on: {click: submit shared_folder_id}} [ H.text "remove" ]]
submit sharedFolderId = do
_ <- saveDeleteTeam { session, nodeId, sharedFolderId }
liftEffect $ T2.reload reload
type LoadProps =
(
session :: Session,
nodeId :: Int
)
loadTeam :: Record LoadProps -> AffRESTError (Array TeamMember)
loadTeam { session, nodeId } = getTeam session nodeId
type DeleteProps =
(
session :: Session,
nodeId :: Int,
sharedFolderId :: Int
)
saveDeleteTeam ∷ Record DeleteProps -> AffRESTError Int
saveDeleteTeam { session, nodeId, sharedFolderId } = deleteTeamMembership session sharedFolderId nodeId
......@@ -26,7 +26,6 @@ import Gargantext.Components.Nodes.File (fileLayout)
import Gargantext.Components.Nodes.Frame as Frame
import Gargantext.Components.Nodes.Home (homeLayout)
import Gargantext.Components.Nodes.Lists as Lists
import Gargantext.Components.Nodes.Team (teamLayout)
import Gargantext.Components.Nodes.Texts as Texts
import Gargantext.Components.Tile (tileBlock)
import Gargantext.Components.TopBar as TopBar
......@@ -625,7 +624,7 @@ teamCpt = here.component "team" cpt where
cpt props@{ boxes, nodeId } _ = do
let sessionProps = RE.pick props :: Record SessionProps
pure $ authed (Record.merge { content: \session ->
teamLayout { boxes
corpusLayout { boxes
, nodeId
, session } } sessionProps) []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment