Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: apply consistent redirect and toasty logic for schedules #698

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 41 additions & 19 deletions src/elm/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -1216,10 +1216,10 @@ update msg model =

ScheduleResponse response ->
case response of
Ok ( _, s ) ->
Ok ( _, schedule ) ->
let
updatedSchedulesModel =
Pages.Schedules.Update.reinitializeScheduleUpdate sm s
Pages.Schedules.Update.reinitializeScheduleUpdate sm schedule
in
( { model | schedulesModel = updatedSchedulesModel }
, Cmd.none
Expand All @@ -1230,32 +1230,26 @@ update msg model =

AddScheduleResponse response ->
case response of
Ok _ ->
Ok ( _, schedule ) ->
let
alertMessage =
"Schedule Added"

redirectTo =
Routes.routeToUrl (Routes.Schedules sm.org sm.repo Nothing Nothing)
updatedSchedulesModel =
Pages.Schedules.Update.reinitializeScheduleAdd sm
in
( model, Navigation.pushUrl model.navigationKey redirectTo )
|> Alerting.addToastIfUnique Alerts.successConfig AlertsUpdate (Alerts.Success "Success" alertMessage Nothing)
( { model | schedulesModel = updatedSchedulesModel }, Cmd.none )
|> addScheduleResponseAlert schedule

Err error ->
( model, addError error )

UpdateScheduleResponse response ->
case response of
Ok _ ->
Ok ( _, schedule ) ->
let
alertMessage =
"Schedule Modified"

redirectTo =
Routes.routeToUrl (Routes.Schedules sm.org sm.repo Nothing Nothing)
updatedSchedulesModel =
Pages.Schedules.Update.reinitializeScheduleUpdate sm schedule
in
( model, Navigation.pushUrl model.navigationKey redirectTo )
|> Alerting.addToastIfUnique Alerts.successConfig AlertsUpdate (Alerts.Success "Success" alertMessage Nothing)
( { model | schedulesModel = updatedSchedulesModel }, Cmd.none )
|> updateScheduleResponseAlert schedule

Err error ->
( model, addError error )
Expand All @@ -1265,7 +1259,7 @@ update msg model =
Ok _ ->
let
alertMessage =
"Schedule Deleted"
sm.form.name ++ " removed from repo schedules."

redirectTo =
Routes.routeToUrl (Routes.Schedules sm.org sm.repo Nothing Nothing)
Expand Down Expand Up @@ -2161,6 +2155,34 @@ updateSecretResponseAlert secret =
Alerting.addToast Alerts.successConfig AlertsUpdate (Alerts.Success "Success" msg Nothing)


{-| addScheduleResponseAlert : takes schedule and produces Toasty alert for when adding a schedule
-}
addScheduleResponseAlert :
Schedule
-> ( { m | toasties : Stack Alert }, Cmd Msg )
-> ( { m | toasties : Stack Alert }, Cmd Msg )
addScheduleResponseAlert schedule =
let
msg =
schedule.name ++ " added to repo schedules."
in
Alerting.addToast Alerts.successConfig AlertsUpdate (Alerts.Success "Success" msg Nothing)


{-| updateScheduleResponseAlert : takes schedule and produces Toasty alert for when updating a schedule
-}
updateScheduleResponseAlert :
Schedule
-> ( { m | toasties : Stack Alert }, Cmd Msg )
-> ( { m | toasties : Stack Alert }, Cmd Msg )
updateScheduleResponseAlert schedule =
let
msg =
"Repo schedule " ++ schedule.name ++ " updated."
in
Alerting.addToast Alerts.successConfig AlertsUpdate (Alerts.Success "Success" msg Nothing)



-- SUBSCRIPTIONS

Expand Down