{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE NoImplicitPrelude #-} module Client.Handlers.Profile where import Relude hiding (id) import Client.ApiRequests import Client.Types import Client.FormFields import Data.Morpheus.Client import Server.Types import Yesod hiding (emailField) import Yesod.Auth declareLocalTypesInline "schema.gql" [raw| query ProfilePage($id: UserID) { user(id: $id) { id name nickname email pendingEmail homeplace birthdate } permissions } |] declareLocalTypesInline "schema.gql" [raw| mutation UpdateProfile($user: UserID, $name: String, $homeplace: String, $nickname: String, $email: Email) { update(user: $user, name: $name, homeplace: $homeplace, nickname: $nickname, email: $email) { id } } |] declareLocalTypesInline "schema.gql" [raw| mutation UpdatePassword($user: UserID, $password: String!) { update(user: $user, password: $password) { id } } |] passwordForm :: Form Text passwordForm = renderDivs $ areq verifiedPasswordField "Uusi salasana" Nothing profileForm :: (Maybe UserID) -> (Maybe ProfilePageUser) -> Form UpdateProfileArgs profileForm userID user extraHtml = do (nameRes, nameView) <- mopt textField "Nimi" (Just $ maybe Nothing (\x -> Just $ name (x ::ProfilePageUser)) user) (homeRes, homeView) <- mopt textField "Kotipaikka" (Just $ maybe Nothing (\x -> Just $ homeplace (x :: ProfilePageUser)) user) (nicknameRes, nicknameView) <- mopt textField "Kutsumanimi" (Just $ maybe Nothing (\x -> Just $ nickname (x :: ProfilePageUser)) user) (emailRes, emailView) <- mopt emailField "Sähköposti" (maybe Nothing (\x -> Just $ email (x :: ProfilePageUser)) user) let profileUpdateRes = UpdateProfileArgs userID <$> nameRes <*> homeRes <*> nicknameRes <*> emailRes maybePendingEmail = user >>= \x -> pendingEmail (x :: ProfilePageUser) inputField FieldView {..} = [whamlet|