diff --git a/src/Gargantext/Components/GraphQL.purs b/src/Gargantext/Components/GraphQL.purs index 10cac96d9b4b9f4e9fe3c1343d1cca2e600cc943..8d7d88f784a8a12a304bd8e1eb54ed554f8157fb 100644 --- a/src/Gargantext/Components/GraphQL.purs +++ b/src/Gargantext/Components/GraphQL.purs @@ -7,7 +7,7 @@ import Effect (Effect) import Effect.Aff (Aff) import Effect.Class (liftEffect) import Foreign (unsafeToForeign, ForeignError) -import Gargantext.Components.GraphQL.User (User, UserInfo) +import Gargantext.Components.GraphQL.User (User, UserInfo, UserInfoM) import Gargantext.Prelude import Gargantext.Utils.Reactix as R2 import GraphQL.Client.Args (type (==>)) @@ -40,7 +40,7 @@ gqlQuery = queryWithDecoder (unsafeToForeign >>> JSON.read >>> lmap toJsonError toJsonError :: NonEmptyList ForeignError -> JsonDecodeError toJsonError = unsafeCoerce -- map ForeignErrors to JsonDecodeError as you wish -getClient :: Effect (Client UrqlClient Schema Void Void) +getClient :: Effect (Client UrqlClient Schema Mutation Void) getClient = createClient { headers: [], url: "http://localhost:8008/gql" } queryGql :: @@ -51,7 +51,7 @@ queryGql :: queryGql name q = do --query client name q client <- liftEffect getClient - gqlQuery (client :: Client UrqlClient Schema Void Void) name q + gqlQuery (client :: Client UrqlClient Schema Mutation Void) name q --query_ "http://localhost:8008/gql" (Proxy :: Proxy Schema) @@ -60,3 +60,6 @@ type Schema = { user_infos :: { user_id :: Int } ==> Array UserInfo , users :: { user_id :: Int } ==> Array User } + +type Mutation + = { update_user_info :: UserInfoM } ==> UserInfo diff --git a/src/Gargantext/Components/GraphQL/User.purs b/src/Gargantext/Components/GraphQL/User.purs index bf632321ada6debfe8d53668050586eba68fd169..760590ee96393f74788db75fdf82e3dfdf36a7e9 100644 --- a/src/Gargantext/Components/GraphQL/User.purs +++ b/src/Gargantext/Components/GraphQL/User.purs @@ -1,9 +1,10 @@ module Gargantext.Components.GraphQL.User where +import Gargantext.Prelude + import Data.Array as A import Data.Lens (Lens', lens) import Data.Maybe (Maybe(..), fromMaybe, maybe) -import Gargantext.Prelude import Type.Proxy (Proxy(..)) @@ -23,7 +24,40 @@ type UserInfo , ui_cwRole :: Maybe String , ui_cwTouchPhone :: Maybe String , ui_cwTouchMail :: Maybe String } - +type UserInfoM + = { ui_id :: Int + , ui_username :: Maybe String + , ui_email :: Maybe String + , ui_title :: Maybe String + , ui_source :: Maybe String + , ui_cwFirstName :: Maybe String + , ui_cwLastName :: Maybe String + , ui_cwOrganization :: Maybe (Array String) + , ui_cwLabTeamDepts :: Maybe (Array String) + , ui_cwOffice :: Maybe String + , ui_cwCity :: Maybe String + , ui_cwCountry :: Maybe String + , ui_cwRole :: Maybe String + , ui_cwTouchPhone :: Maybe String + , ui_cwTouchMail :: Maybe String } +defaultUserInfoM :: UserInfoM +defaultUserInfoM = + { ui_id: 0 + , ui_username: Nothing + , ui_email: Nothing + , ui_title: Nothing + , ui_source: Nothing + , ui_cwFirstName: Nothing + , ui_cwLastName: Nothing + , ui_cwOrganization: Nothing + , ui_cwLabTeamDepts: Nothing + , ui_cwOffice: Nothing + , ui_cwCity: Nothing + , ui_cwCountry: Nothing + , ui_cwRole: Nothing + , ui_cwTouchPhone: Nothing + , ui_cwTouchMail: Nothing } + _ui_cwFirstName :: Lens' UserInfo String _ui_cwFirstName = lens getter setter where @@ -106,35 +140,3 @@ showUser { u_id , u_username , u_email } = "[" <> show u_id <> "] " <> u_username <> " :: " <> u_email showMUser u = maybe "" showUser u - --- Symbols -ui_id :: Proxy "ui_id" -ui_id = Proxy -ui_username :: Proxy "ui_username" -ui_username = Proxy -ui_email :: Proxy "ui_email" -ui_email = Proxy -ui_title :: Proxy "ui_title" -ui_title = Proxy -ui_source :: Proxy "ui_source" -ui_source = Proxy -ui_cwFirstName :: Proxy "ui_cwFirstName" -ui_cwFirstName = Proxy -ui_cwLastName :: Proxy "ui_cwLastName" -ui_cwLastName = Proxy -ui_cwCity :: Proxy "ui_cwCity" -ui_cwCity = Proxy -ui_cwCountry :: Proxy "ui_cwCountry" -ui_cwCountry = Proxy -ui_cwLabTeamDepts :: Proxy "ui_cwLabTeamDepts" -ui_cwLabTeamDepts = Proxy -ui_cwOrganization :: Proxy "ui_cwOrganization" -ui_cwOrganization = Proxy -ui_cwOffice :: Proxy "ui_cwOffice" -ui_cwOffice = Proxy -ui_cwRole :: Proxy "ui_cwRole" -ui_cwRole = Proxy -ui_cwTouchMail :: Proxy "ui_cwTouchMail" -ui_cwTouchMail = Proxy -ui_cwTouchPhone :: Proxy "ui_cwTouchPhone" -ui_cwTouchPhone = Proxy diff --git a/src/Gargantext/Components/Nodes/Annuaire/User/Contact.purs b/src/Gargantext/Components/Nodes/Annuaire/User/Contact.purs index 371effaecf8b07ee226337cc27b9f93bcdd80468..64c7b5b5862a934b312beb50e3ffaae5b4841431 100644 --- a/src/Gargantext/Components/Nodes/Annuaire/User/Contact.purs +++ b/src/Gargantext/Components/Nodes/Annuaire/User/Contact.purs @@ -21,6 +21,7 @@ import Effect.Aff (Aff, launchAff_) import Effect.Class (liftEffect) import Gargantext.Components.App.Data (Boxes) import Gargantext.Components.GraphQL (getClient, queryGql) +import Gargantext.Components.GraphQL.User (defaultUserInfoM) import Gargantext.Components.InputWithEnter (inputWithEnter) import Gargantext.Components.Nodes.Annuaire.User.Contacts.Tabs as Tabs import Gargantext.Components.Nodes.Annuaire.User.Contacts.Types (Contact'(..), ContactData', ContactTouch(..), ContactWhere(..), ContactWho(..), HyperdataContact(..), HyperdataUser(..), _city, _country, _firstName, _labTeamDeptsJoinComma, _lastName, _mail, _office, _organizationJoinComma, _ouFirst, _phone, _role, _shared, _touch, _who, defaultContactTouch, defaultContactWhere, defaultContactWho, defaultHyperdataContact, defaultHyperdataUser) @@ -34,7 +35,7 @@ import Gargantext.Types (NodeType(..)) import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Toestand as T2 import GraphQL.Client.Args (type (==>), (=>>), onlyArgs) -import GraphQL.Client.Query (mutationOpts) +import GraphQL.Client.Query (mutationOpts, mutation) import Reactix as R import Reactix.DOM.HTML as H import Record as Record @@ -224,13 +225,15 @@ saveContactHyperdata session id = put session (Routes.NodeAPI Node (Just id) "") saveUserInfo :: Session -> Int -> UserInfo -> Aff (Either RESTError Int) saveUserInfo session id ui = do -- TODO GraphQL - --pure $ Left $ CustomError "TODO implement graphql for saveUserInfo" - client <- liftEffect $ getClient - mutationOpts - (\m -> m) - client - "update user_info" - { update_user_info: onlyArgs { ui_id: id } } + pure $ Left $ CustomError "TODO implement graphql for saveUserInfo" +-- client <- liftEffect $ getClient +-- res <- mutation +-- client +-- "update user_info" +-- { update_user_info: userInfo =>> { ui_id: unit } } +-- pure $ Right 0 +-- where +-- userInfo = defaultUserInfoM { ui_id = id } type AnnuaireLayoutProps = ( annuaireId :: Int, session :: Session | ReloadProps ) @@ -307,21 +310,21 @@ getUserInfo :: Session -> Int -> Aff (Either RESTError UserInfo) getUserInfo session id = do { user_infos } <- queryGql "get user infos" { user_infos: { user_id: id } =>> - { ui_id - , ui_username - , ui_email - , ui_title - , ui_source - , ui_cwFirstName - , ui_cwLastName - , ui_cwCity - , ui_cwCountry - , ui_cwLabTeamDepts - , ui_cwOrganization - , ui_cwOffice - , ui_cwRole - , ui_cwTouchMail - , ui_cwTouchPhone } + { ui_id: unit + , ui_username: unit + , ui_email: unit + , ui_title: unit + , ui_source: unit + , ui_cwFirstName: unit + , ui_cwLastName: unit + , ui_cwCity: unit + , ui_cwCountry: unit + , ui_cwLabTeamDepts: unit + , ui_cwOrganization: unit + , ui_cwOffice: unit + , ui_cwRole: unit + , ui_cwTouchMail: unit + , ui_cwTouchPhone: unit } } liftEffect $ here.log2 "[getUserInfo] user infos" user_infos pure $ case A.head user_infos of