Commit df277c4e authored by Karen Konou's avatar Karen Konou

[Team] team layout component

parent 08c8d76c
...@@ -2,17 +2,20 @@ module Gargantext.Components.Nodes.Team where ...@@ -2,17 +2,20 @@ module Gargantext.Components.Nodes.Team where
import Gargantext.Prelude import Gargantext.Prelude
import Effect.Class (liftEffect)
import Gargantext.Components.App.Store (Boxes) import Gargantext.Components.App.Store (Boxes)
import Gargantext.Components.FolderView as FV import Gargantext.Components.FolderView as FV
import Gargantext.Components.GraphQL.Endpoints (getTeam, deleteTeamMembership)
import Gargantext.Components.GraphQL.Team (TeamMember) import Gargantext.Components.GraphQL.Team (TeamMember)
import Gargantext.Components.GraphQL.Endpoints (getTeam)
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)
import Gargantext.Types (ID) import Gargantext.Types (ID)
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Toestand as T2
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Toestand as T
here :: R2.Here here :: R2.Here
here = R2.here "Gargantext.Components.Nodes.Team" here = R2.here "Gargantext.Components.Nodes.Team"
...@@ -39,6 +42,9 @@ teamLayoutMain = R2.leafComponent teamLayoutMainCpt ...@@ -39,6 +42,9 @@ teamLayoutMain = R2.leafComponent teamLayoutMainCpt
teamLayoutMainCpt :: R.Component Props teamLayoutMainCpt :: R.Component Props
teamLayoutMainCpt = here.component "teamLayoutMain" cpt where teamLayoutMainCpt = here.component "teamLayoutMain" cpt where
cpt { nodeId, session, boxes } _ = do cpt { nodeId, session, boxes } _ = do
reload <- T.useBox T2.newReload
_ <- T.useLive T.unequal reload
useLoader { errorHandler useLoader { errorHandler
, loader: loadTeam , loader: loadTeam
, path: { nodeId, session } , path: { nodeId, session }
...@@ -46,6 +52,7 @@ teamLayoutMainCpt = here.component "teamLayoutMain" cpt where ...@@ -46,6 +52,7 @@ teamLayoutMainCpt = here.component "teamLayoutMain" cpt where
, team , team
, nodeId , nodeId
, session , session
, reload
} }
} }
where where
...@@ -55,17 +62,22 @@ type TeamProps = ...@@ -55,17 +62,22 @@ type TeamProps =
( boxes :: Boxes ( boxes :: Boxes
, nodeId :: ID , nodeId :: ID
, session :: Session , session :: Session
, team :: Array TeamMember ) , team :: Array TeamMember
, reload :: T.Box T2.Reload )
teamLayoutRows :: R2.Leaf TeamProps teamLayoutRows :: R2.Leaf TeamProps
teamLayoutRows = R2.leafComponent teamLayoutRowsCpt teamLayoutRows = R2.leafComponent teamLayoutRowsCpt
teamLayoutRowsCpt :: R.Component TeamProps teamLayoutRowsCpt :: R.Component TeamProps
teamLayoutRowsCpt = here.component "teamLayoutRows" cpt where teamLayoutRowsCpt = here.component "teamLayoutRows" cpt where
cpt { team } _ = do cpt { team, nodeId, session, reload } _ = do
pure $ H.div {} $ map makeTeam team pure $ H.div {} $ map makeTeam team
where where
makeTeam { username } = H.p {} [H.text username] 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 = type LoadProps =
( (
...@@ -76,3 +88,14 @@ type LoadProps = ...@@ -76,3 +88,14 @@ type LoadProps =
loadTeam :: Record LoadProps -> AffRESTError (Array TeamMember) loadTeam :: Record LoadProps -> AffRESTError (Array TeamMember)
loadTeam { session, nodeId } = getTeam session nodeId 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
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