Commit 9db2c91d authored by Karen Konou's avatar Karen Konou

[Team] show team leader

parent 46286418
......@@ -2,13 +2,13 @@ module Gargantext.Components.Forest.Tree.Node.Action.ManageTeam where
import Gargantext.Prelude
import Data.Array (filter, null)
import Data.Array (filter, null, (:))
import Data.Either (Either(..))
import Effect.Aff (runAff_)
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.Components.GraphQL.Team (Team, TeamMember)
import Gargantext.Config.REST (AffRESTError, logRESTError)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Sessions (Session)
......@@ -47,7 +47,7 @@ actionManageTeamCpt = here.component "actionManageTeam" cpt where
type TeamProps =
( nodeId :: ID
, session :: Session
, team :: (Array TeamMember)
, team :: Team
)
teamLayoutWrapper :: R2.Component TeamProps
......@@ -55,21 +55,22 @@ teamLayoutWrapper = R.createElement teamLayoutWrapperCpt
teamLayoutWrapperCpt :: R.Component TeamProps
teamLayoutWrapperCpt = here.component "teamLayoutWrapper" cpt where
cpt {nodeId, session, team} _ = do
teamS <- T.useBox team
cpt {nodeId, session, team: {team_leader_username, team_members}} _ = do
teamS <- T.useBox team_members
team' <- T.useLive T.unequal teamS
error <- T.useBox ""
error' <- T.useLive T.unequal error
pure $ teamLayoutRows {nodeId, session, team: teamS, team', error, error'}
pure $ teamLayoutRows {nodeId, session, team: teamS, team', error, error', team_leader_username}
type TeamRowProps =
( nodeId :: ID
, session :: Session
, team :: T.Box (Array TeamMember)
, error :: T.Box String
, team' :: Array TeamMember
, error' :: String
( nodeId :: ID
, session :: Session
, team :: T.Box (Array TeamMember)
, error :: T.Box String
, team' :: Array TeamMember
, error' :: String
, team_leader_username :: String
)
teamLayoutRows :: R2.Leaf TeamRowProps
......@@ -77,12 +78,12 @@ teamLayoutRows = R2.leafComponent teamLayoutRowsCpt
teamLayoutRowsCpt :: R.Component TeamRowProps
teamLayoutRowsCpt = here.component "teamLayoutRows" cpt where
cpt { team, nodeId, session, error, team', error' } _ = do
cpt { team, nodeId, session, error, team', error', team_leader_username} _ = do
case null team' of
true -> pure $ H.div { style: {margin: "10px"}}
[ H.h4 {} [H.text "Your team is empty, you can send some invitations."]]
false -> pure $ Tools.panel (map makeTeam team') (H.div {} [H.text error'])
false -> pure $ Tools.panel (makeLeader team_leader_username : (map makeTeam team')) (H.div {} [H.text error'])
where
makeTeam :: TeamMember -> R.Element
......@@ -93,6 +94,10 @@ teamLayoutRowsCpt = here.component "teamLayoutRows" cpt where
, on: {click: submit shared_folder_id }
} []
]
makeLeader username = H.div {className: "from-group row"} [ H.div { className: "col-8"} [ H.text username ]
, H.p { className: "col-2"} [ H.text "leader"]
]
submit sharedFolderId _ = do
runAff_ callback $ saveDeleteTeam { session, nodeId, sharedFolderId }
......@@ -114,17 +119,17 @@ teamLayoutRowsCpt = here.component "teamLayoutRows" cpt where
type LoadProps =
(
session :: Session,
nodeId :: Int
nodeId :: Int
)
loadTeam :: Record LoadProps -> AffRESTError (Array TeamMember)
loadTeam :: Record LoadProps -> AffRESTError Team
loadTeam { session, nodeId } = getTeam session nodeId
type DeleteProps =
(
session :: Session,
nodeId :: Int,
session :: Session,
nodeId :: Int,
sharedFolderId :: Int
)
......
......@@ -14,7 +14,7 @@ import Gargantext.Components.GraphQL.IMT as GQLIMT
import Gargantext.Components.GraphQL.Node (Node)
import Gargantext.Components.GraphQL.Tree (TreeFirstLevel)
import Gargantext.Components.GraphQL.User (User, UserInfo, UserInfoM)
import Gargantext.Components.GraphQL.Team (TeamMember, TeamDeleteM)
import Gargantext.Components.GraphQL.Team (Team, TeamDeleteM)
import Gargantext.Ends (Backend(..))
import Gargantext.Sessions (Session(..))
import Gargantext.Utils.Reactix as R2
......@@ -78,7 +78,7 @@ type Schema
, users :: { user_id :: Int } ==> Array User
, tree :: { root_id :: Int } ==> TreeFirstLevel
, annuaire_contacts :: { contact_id :: Int } ==> Array AnnuaireContact
, team :: { team_node_id :: Int } ==> Array TeamMember
, team :: { team_node_id :: Int } ==> Team
}
type Mutation
......
......@@ -10,7 +10,7 @@ import Effect.Class (liftEffect)
import Gargantext.Components.GraphQL (getClient, queryGql)
import Gargantext.Components.GraphQL.IMT as GQLIMT
import Gargantext.Components.GraphQL.Node (Node, nodeParentQuery, nodesQuery)
import Gargantext.Components.GraphQL.Team (TeamMember, teamQuery)
import Gargantext.Components.GraphQL.Team (Team, teamQuery)
import Gargantext.Components.GraphQL.Tree (TreeFirstLevel, treeFirstLevelQuery)
import Gargantext.Components.GraphQL.User (UserInfo, userInfoQuery)
import Gargantext.Config.REST (RESTError(..), AffRESTError)
......@@ -73,7 +73,7 @@ getTreeFirstLevel session id = do
liftEffect $ here.log2 "[getTreeFirstLevel] tree first level" tree
pure $ Right tree -- TODO: error handling
getTeam :: Session -> Int -> AffRESTError (Array TeamMember)
getTeam :: Session -> Int -> AffRESTError Team
getTeam session id = do
{ team } <- queryGql session "get team" $ teamQuery `withVars` { id }
liftEffect $ here.log2 "[getTree] data" team
......
......@@ -5,6 +5,11 @@ import Gargantext.Prelude
import GraphQL.Client.Args (NotNull, (=>>))
import GraphQL.Client.Variable (Var(..))
type Team
= { team_leader_username :: String
, team_members :: Array TeamMember
}
type TeamMember
= { username :: String
, shared_folder_id :: Int
......@@ -17,6 +22,9 @@ type TeamDeleteM
}
teamQuery = { team: { team_node_id: Var :: _ "id" Int } =>>
{ username: unit
, shared_folder_id: unit }
{ team_leader_username: unit
, team_members: { username: unit
, shared_folder_id: unit
}
}
}
\ No newline at end of file
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