mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-09-30 08:38:22 +00:00
Externalize error messages
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
module Page.CollectiveSettings.Data exposing
|
||||
( Model
|
||||
( FormState(..)
|
||||
, Model
|
||||
, Msg(..)
|
||||
, Tab(..)
|
||||
, init
|
||||
@@ -21,10 +22,17 @@ type alias Model =
|
||||
, userModel : Comp.UserManage.Model
|
||||
, settingsModel : Comp.CollectiveSettingsForm.Model
|
||||
, insights : ItemInsights
|
||||
, submitResult : Maybe BasicResult
|
||||
, formState : FormState
|
||||
}
|
||||
|
||||
|
||||
type FormState
|
||||
= InitialState
|
||||
| SubmitSuccessful
|
||||
| SubmitFailed String
|
||||
| SubmitError Http.Error
|
||||
|
||||
|
||||
init : Flags -> ( Model, Cmd Msg )
|
||||
init flags =
|
||||
let
|
||||
@@ -39,7 +47,7 @@ init flags =
|
||||
, userModel = Comp.UserManage.emptyModel
|
||||
, settingsModel = cm
|
||||
, insights = Api.Model.ItemInsights.empty
|
||||
, submitResult = Nothing
|
||||
, formState = InitialState
|
||||
}
|
||||
, Cmd.batch
|
||||
[ Cmd.map SourceMsg sc
|
||||
|
@@ -1,13 +1,11 @@
|
||||
module Page.CollectiveSettings.Update exposing (update)
|
||||
|
||||
import Api
|
||||
import Api.Model.BasicResult exposing (BasicResult)
|
||||
import Comp.CollectiveSettingsForm
|
||||
import Comp.SourceManage
|
||||
import Comp.UserManage
|
||||
import Data.Flags exposing (Flags)
|
||||
import Page.CollectiveSettings.Data exposing (..)
|
||||
import Util.Http
|
||||
|
||||
|
||||
update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
|
||||
@@ -58,12 +56,12 @@ update flags msg model =
|
||||
Just sett ->
|
||||
Api.setCollectiveSettings flags sett SubmitResp
|
||||
in
|
||||
( { model | settingsModel = m2, submitResult = Nothing }
|
||||
( { model | settingsModel = m2, formState = InitialState }
|
||||
, Cmd.batch [ cmd, Cmd.map SettingsFormMsg c2 ]
|
||||
)
|
||||
|
||||
Init ->
|
||||
( { model | submitResult = Nothing }
|
||||
( { model | formState = InitialState }
|
||||
, Cmd.batch
|
||||
[ Api.getInsights flags GetInsightsResp
|
||||
, Api.getCollectiveSettings flags CollectiveSettingsResp
|
||||
@@ -89,11 +87,16 @@ update flags msg model =
|
||||
( model, Cmd.none )
|
||||
|
||||
SubmitResp (Ok res) ->
|
||||
( { model | submitResult = Just res }, Cmd.none )
|
||||
( { model
|
||||
| formState =
|
||||
if res.success then
|
||||
SubmitSuccessful
|
||||
|
||||
else
|
||||
SubmitFailed res.message
|
||||
}
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
SubmitResp (Err err) ->
|
||||
let
|
||||
res =
|
||||
BasicResult False (Util.Http.errorToString err)
|
||||
in
|
||||
( { model | submitResult = Just res }, Cmd.none )
|
||||
( { model | formState = SubmitError err }, Cmd.none )
|
||||
|
@@ -14,7 +14,6 @@ import Html.Events exposing (onClick)
|
||||
import Messages.Page.CollectiveSettings exposing (Texts)
|
||||
import Page.CollectiveSettings.Data exposing (..)
|
||||
import Styles as S
|
||||
import Util.Maybe
|
||||
import Util.Size
|
||||
|
||||
|
||||
@@ -249,6 +248,27 @@ viewSettings texts flags settings model =
|
||||
[ text texts.collectiveSettings
|
||||
]
|
||||
]
|
||||
, div
|
||||
[ classList
|
||||
[ ( "hidden", model.formState == InitialState )
|
||||
, ( S.successMessage, model.formState == SubmitSuccessful )
|
||||
, ( S.errorMessage, model.formState /= SubmitSuccessful )
|
||||
]
|
||||
, class "mb-2"
|
||||
]
|
||||
[ case model.formState of
|
||||
SubmitSuccessful ->
|
||||
text texts.submitSuccessful
|
||||
|
||||
SubmitError err ->
|
||||
text (texts.httpError err)
|
||||
|
||||
SubmitFailed m ->
|
||||
text m
|
||||
|
||||
InitialState ->
|
||||
text ""
|
||||
]
|
||||
, Html.map SettingsFormMsg
|
||||
(Comp.CollectiveSettingsForm.view2
|
||||
flags
|
||||
@@ -256,23 +276,4 @@ viewSettings texts flags settings model =
|
||||
settings
|
||||
model.settingsModel
|
||||
)
|
||||
, div
|
||||
[ classList
|
||||
[ ( "hidden", Util.Maybe.isEmpty model.submitResult )
|
||||
, ( S.successMessage
|
||||
, Maybe.map .success model.submitResult
|
||||
|> Maybe.withDefault False
|
||||
)
|
||||
, ( S.errorMessage
|
||||
, Maybe.map .success model.submitResult
|
||||
|> Maybe.map not
|
||||
|> Maybe.withDefault False
|
||||
)
|
||||
]
|
||||
, class "mt-2"
|
||||
]
|
||||
[ Maybe.map .message model.submitResult
|
||||
|> Maybe.withDefault ""
|
||||
|> text
|
||||
]
|
||||
]
|
||||
|
Reference in New Issue
Block a user