Delete.purs 2.7 KB
Newer Older
1 2 3
module Gargantext.Components.Forest.Tree.Node.Action.Delete
  where

4 5
import Gargantext.Prelude

6 7
import Data.Maybe (Maybe(..))
import Effect.Aff (Aff)
8
import Gargantext.Components.Forest.Tree.Node.Action.Types (Action(..))
9
import Gargantext.Components.Forest.Tree.Node.Tools (submitButton, panel)
10
import Gargantext.Config.REST (AffRESTError)
11 12 13
import Gargantext.Routes (SessionRoute(..))
import Gargantext.Sessions (Session, delete, put_)
import Gargantext.Types (NodeType(..))
14
import Gargantext.Types as GT
15
import Gargantext.Utils.Reactix as R2
16 17
import Reactix as R
import Reactix.DOM.HTML as H
18 19 20 21

here :: R2.Here
here = R2.here "Gargantext.Components.Forest.Tree.Node.Action.Delete"

22
-- TODO Delete with asyncTaskWithType
23

24
deleteNode :: Session -> GT.ID -> AffRESTError GT.ID
25
deleteNode session nodeId = delete session $ NodeAPI GT.Node (Just nodeId) ""
26 27

{-
28
  case nt of
29
    NodePublic FolderPublic -> delete session $ NodeAPI GT.Node (Just nodeId) ""
30
    NodePublic _ -> put_   session $ NodeAPI GT.Node (Just nodeId) "unpublish"
31
    _            -> delete session $ NodeAPI GT.Node (Just nodeId) ""
32 33 34
    -}

type ParentID = GT.ID
35
unpublishNode :: Session -> Maybe ParentID -> GT.ID -> AffRESTError GT.ID
36 37
unpublishNode s p n = put_ s $ NodeAPI GT.Node p ("unpublish/" <> show n)

38

39
-- | Action : Delete
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
type Delete =
  ( dispatch :: Action -> Aff Unit
  , nodeType :: NodeType )

actionDelete :: R2.Component Delete
actionDelete = R.createElement actionDeleteCpt
actionDeleteCpt :: R.Component Delete
actionDeleteCpt = here.component "actionDelete" cpt where
  cpt props@{ nodeType: NodeUser } _ = pure $ actionDeleteUser props []
  cpt props                        _ = pure $ actionDeleteOther props []

actionDeleteUser :: R2.Component Delete
actionDeleteUser = R.createElement actionDeleteUserCpt
actionDeleteUserCpt :: R.Component Delete
actionDeleteUserCpt = here.component "actionDeleteUser" cpt where
  cpt _  _ = do
    pure $ panel [ H.div { style: {margin: "10px"}}
                    [ H.text $ "Yes, we are RGPD compliant!"
                    <> " But you can not delete User Node yet."
                    <> " We are still on development."
                    <> " Thanks for your comprehensin."
                    ]
            ] (H.div {} [])

actionDeleteOther :: R2.Component Delete
actionDeleteOther = R.createElement actionDeleteOtherCpt
actionDeleteOtherCpt :: R.Component Delete
actionDeleteOtherCpt = here.component "actionDeleteOther" cpt where
  cpt { dispatch, nodeType } _ = do
    pure $ panel (map (\t -> H.p {} [H.text t])
                       [ "Are your sure you want to delete it ?"
                       , "If yes, click again below."
72
                       ]
73
                  ) (submitButton (DeleteNode nodeType) dispatch)