Improve share email form

This commit is contained in:
eikek 2021-10-24 00:37:53 +02:00
parent eaccb60732
commit f5bb85c61e
6 changed files with 74 additions and 16 deletions

View File

@ -10,6 +10,7 @@ module Comp.ItemMail exposing
, Model , Model
, Msg , Msg
, clear , clear
, clearRecipients
, emptyModel , emptyModel
, init , init
, setMailInfo , setMailInfo
@ -115,6 +116,15 @@ clear model =
} }
clearRecipients : Model -> Model
clearRecipients model =
{ model
| recipients = []
, ccRecipients = []
, bccRecipients = []
}
setMailInfo : String -> String -> Msg setMailInfo : String -> String -> Msg
setMailInfo subject body = setMailInfo subject body =
SetSubjectBody subject body SetSubjectBody subject body

View File

@ -29,6 +29,7 @@ import Data.ItemQuery exposing (ItemQuery)
import Data.UiSettings exposing (UiSettings) import Data.UiSettings exposing (UiSettings)
import Html exposing (..) import Html exposing (..)
import Html.Attributes exposing (..) import Html.Attributes exposing (..)
import Html.Events exposing (onClick)
import Http import Http
import Messages.Comp.PublishItems exposing (Texts) import Messages.Comp.PublishItems exposing (Texts)
import Ports import Ports
@ -57,6 +58,7 @@ type alias Model =
, viewMode : ViewMode , viewMode : ViewMode
, formError : FormError , formError : FormError
, loading : Bool , loading : Bool
, mailVisible : Bool
} }
@ -74,6 +76,7 @@ init flags =
, viewMode = ViewModeEdit , viewMode = ViewModeEdit
, formError = FormErrorNone , formError = FormErrorNone
, loading = False , loading = False
, mailVisible = False
} }
, Cmd.batch , Cmd.batch
[ Cmd.map FormMsg fc [ Cmd.map FormMsg fc
@ -96,6 +99,7 @@ initQuery flags query =
, viewMode = ViewModeEdit , viewMode = ViewModeEdit
, formError = FormErrorNone , formError = FormErrorNone
, loading = False , loading = False
, mailVisible = False
} }
, Cmd.batch , Cmd.batch
[ Cmd.map FormMsg fc [ Cmd.map FormMsg fc
@ -115,6 +119,7 @@ type Msg
| SubmitPublish | SubmitPublish
| PublishResp (Result Http.Error IdResult) | PublishResp (Result Http.Error IdResult)
| GetShareResp (Result Http.Error ShareDetail) | GetShareResp (Result Http.Error ShareDetail)
| ToggleMailVisible
type Outcome type Outcome
@ -210,6 +215,7 @@ update texts flags msg model =
| formError = FormErrorNone | formError = FormErrorNone
, loading = False , loading = False
, viewMode = ViewModeInfo share , viewMode = ViewModeInfo share
, mailVisible = False
, mailModel = mm , mailModel = mm
} }
, cmd = , cmd =
@ -228,6 +234,13 @@ update texts flags msg model =
, outcome = OutcomeInProgress , outcome = OutcomeInProgress
} }
ToggleMailVisible ->
{ model = { model | mailVisible = not model.mailVisible }
, cmd = Cmd.none
, sub = Sub.none
, outcome = OutcomeInProgress
}
--- View --- View
@ -281,14 +294,26 @@ viewInfo texts settings flags model share =
, div [] , div []
[ Comp.ShareView.view cfg texts.shareView flags share [ Comp.ShareView.view cfg texts.shareView flags share
] ]
, div [ class "flex flex-col mt-6" ] , div
[ div [ class "flex flex-col mt-6"
]
[ a
[ class S.header2 [ class S.header2
, class "inline-block w-full"
, href "#"
, onClick ToggleMailVisible
] ]
[ text texts.sendViaMail [ if model.mailVisible then
i [ class "fa fa-caret-down mr-2" ] []
else
i [ class "fa fa-caret-right mr-2" ] []
, text texts.sendViaMail
]
, div [ classList [ ( "hidden", not model.mailVisible ) ] ]
[ Html.map MailMsg
(Comp.ShareMail.view texts.shareMail flags settings model.mailModel)
] ]
, Html.map MailMsg
(Comp.ShareMail.view texts.shareMail flags settings model.mailModel)
] ]
] ]

View File

@ -120,7 +120,11 @@ update texts flags msg model =
(texts.bodyTemplate url) (texts.bodyTemplate url)
nm = nm =
{ model | share = share } { model
| share = share
, mailModel = Comp.ItemMail.clearRecipients model.mailModel
, formState = FormStateNone
}
in in
update texts flags (MailMsg lm) nm update texts flags (MailMsg lm) nm
@ -128,7 +132,7 @@ update texts flags msg model =
if res.success then if res.success then
( { model ( { model
| formState = FormStateSent | formState = FormStateSent
, mailModel = Comp.ItemMail.clear model.mailModel , mailModel = Comp.ItemMail.clearRecipients model.mailModel
, sending = False , sending = False
} }
, Cmd.none , Cmd.none
@ -176,7 +180,7 @@ view texts flags settings model =
FormStateSent -> FormStateSent ->
div [ class S.successMessage ] div [ class S.successMessage ]
[ text "Mail sent." [ text texts.mailSent
] ]
, Html.map MailMsg , Html.map MailMsg
(Comp.ItemMail.view texts.itemMail settings cfg model.mailModel) (Comp.ItemMail.view texts.itemMail settings cfg model.mailModel)

View File

@ -58,6 +58,7 @@ type alias Model =
, deleteConfirm : DeleteConfirm , deleteConfirm : DeleteConfirm
, query : String , query : String
, owningOnly : Bool , owningOnly : Bool
, sendMailVisible : Bool
} }
@ -79,6 +80,7 @@ init flags =
, deleteConfirm = DeleteConfirmOff , deleteConfirm = DeleteConfirmOff
, query = "" , query = ""
, owningOnly = True , owningOnly = True
, sendMailVisible = False
} }
, Cmd.batch , Cmd.batch
[ Cmd.map FormMsg fc [ Cmd.map FormMsg fc
@ -96,6 +98,7 @@ type Msg
| SetViewMode ViewMode | SetViewMode ViewMode
| SetQuery String | SetQuery String
| ToggleOwningOnly | ToggleOwningOnly
| ToggleSendMailVisible
| Submit | Submit
| RequestDelete | RequestDelete
| CancelDelete | CancelDelete
@ -260,6 +263,9 @@ update texts flags msg model =
, Sub.none , Sub.none
) )
ToggleSendMailVisible ->
( { model | sendMailVisible = not model.sendMailVisible }, Cmd.none, Sub.none )
setShare : Texts -> ShareDetail -> Flags -> Model -> ( Model, Cmd Msg, Sub Msg ) setShare : Texts -> ShareDetail -> Flags -> Model -> ( Model, Cmd Msg, Sub Msg )
setShare texts share flags model = setShare texts share flags model =
@ -268,7 +274,7 @@ setShare texts share flags model =
flags.config.baseUrl ++ Page.pageToString (SharePage share.id) flags.config.baseUrl ++ Page.pageToString (SharePage share.id)
nextModel = nextModel =
{ model | formError = FormErrorNone, viewMode = Form, loading = False } { model | formError = FormErrorNone, viewMode = Form, loading = False, sendMailVisible = False }
initClipboard = initClipboard =
Ports.initClipboard (Comp.ShareView.clipboardData share) Ports.initClipboard (Comp.ShareView.clipboardData share)
@ -490,13 +496,23 @@ shareSendMail texts flags settings model =
[ class "mt-8 mb-2" [ class "mt-8 mb-2"
, classList [ ( "hidden", share.id == "" || not share.enabled || share.expired ) ] , classList [ ( "hidden", share.id == "" || not share.enabled || share.expired ) ]
] ]
[ h2 [ a
[ class S.header2 [ class S.header2
, class "border-b-2 dark:border-bluegray-600" , class "border-b-2 dark:border-bluegray-600 w-full inline-block"
, href "#"
, onClick ToggleSendMailVisible
] ]
[ text "Send via E-Mail" [ if model.sendMailVisible then
i [ class "fa fa-caret-down mr-2" ] []
else
i [ class "fa fa-caret-right mr-2" ] []
, text texts.sendViaMail
]
, div
[ class "px-2 py-2 dark:border-bluegray-600"
, classList [ ( "hidden", not model.sendMailVisible ) ]
] ]
, div [ class "px-2 py-2 dark:border-bluegray-600" ]
[ Html.map MailMsg [ Html.map MailMsg
(Comp.ShareMail.view texts.shareMail flags settings model.mailModel) (Comp.ShareMail.view texts.shareMail flags settings model.mailModel)
] ]

View File

@ -23,6 +23,7 @@ type alias Texts =
, httpError : Http.Error -> String , httpError : Http.Error -> String
, subjectTemplate : Maybe String -> String , subjectTemplate : Maybe String -> String
, bodyTemplate : String -> String , bodyTemplate : String -> String
, mailSent : String
} }
@ -40,6 +41,7 @@ you can find the documents here:
Kind regards Kind regards
""" """
, mailSent = "Mail sent."
} }
@ -57,4 +59,5 @@ die freigegebenen Dokumente befinden sich hier:
Freundliche Grüße Freundliche Grüße
""" """
, mailSent = "E-Mail gesendet."
} }

View File

@ -38,7 +38,7 @@ type alias Texts =
, correctFormErrors : String , correctFormErrors : String
, noName : String , noName : String
, shareInformation : String , shareInformation : String
, sendMail : String , sendViaMail : String
, notOwnerInfo : String , notOwnerInfo : String
, showOwningSharesOnly : String , showOwningSharesOnly : String
} }
@ -63,7 +63,7 @@ gb =
, correctFormErrors = "Please correct the errors in the form." , correctFormErrors = "Please correct the errors in the form."
, noName = "No Name" , noName = "No Name"
, shareInformation = "Share Information" , shareInformation = "Share Information"
, sendMail = "Send via E-Mail" , sendViaMail = "Send via E-Mail"
, notOwnerInfo = "Only the user who created this share can edit its properties." , notOwnerInfo = "Only the user who created this share can edit its properties."
, showOwningSharesOnly = "Show my shares only" , showOwningSharesOnly = "Show my shares only"
} }
@ -88,7 +88,7 @@ de =
, correctFormErrors = "Bitte korrigiere die Fehler im Formular." , correctFormErrors = "Bitte korrigiere die Fehler im Formular."
, noName = "Ohne Name" , noName = "Ohne Name"
, shareInformation = "Informationen zur Freigabe" , shareInformation = "Informationen zur Freigabe"
, sendMail = "Per E-Mail versenden" , sendViaMail = "Per E-Mail versenden"
, notOwnerInfo = "Nur der Benutzer, der diese Freigabe erstellt hat, kann diese auch ändern." , notOwnerInfo = "Nur der Benutzer, der diese Freigabe erstellt hat, kann diese auch ändern."
, showOwningSharesOnly = "Nur meine Freigaben anzeigen" , showOwningSharesOnly = "Nur meine Freigaben anzeigen"
} }