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