ihp-1.4.0: Haskell Web Framework
Copyright(c) digitally induced GmbH 2020
Safe HaskellNone
LanguageGHC2021

IHP.FlashMessages

Description

 
Synopsis

Documentation

setSuccessMessage :: (?request :: Request) => Text -> IO () Source #

Sets a flash messages. This is shown to the user when the next view is rendered.

Will be rendered in a bootstrap alert, with the alert-success styling. Take a look at https://getbootstrap.com/docs/4.5/components/alerts/ for how this will look like.

This requires renderFlashMessages to be placed somewhere in the layout or page of the next view. For example:

myLayout view = [hsx|
    {renderFlashMessages}
    <main>{view}</main>
|]

setErrorMessage :: (?request :: Request) => Text -> IO () Source #

Sets a flash messages. This is shown to the user when the next view is rendered.

Will be rendered in a bootstrap alert, with the alert-danger styling. Take a look at https://getbootstrap.com/docs/4.5/components/alerts/ for how this will look like.

This requires renderFlashMessages to be placed somewhere in the layout or page of the next view. For example:

myLayout view = [hsx|
    {renderFlashMessages}
    <main>{view}</main>
|]

getSuccessMessage :: (?request :: Request) => IO (Maybe Text) Source #

Returns the flash message currently set

clearSuccessMessage :: (?request :: Request) => IO () Source #

Removes the current flash message

flashVaultKey :: Key [FlashMessage] Source #

requestFlashMessages :: Request -> [FlashMessage] Source #

renderFlashMessages :: (?request :: Request) => Html Source #

Displays the flash messages for the current request.

You can add a flash message to the next request by calling setSuccessMessage or setErrorMessage:

action CreateProjectAction = do
    ...
    setSuccessMessage "Your project has been created successfully"
    redirectTo ShowProjectAction { .. }
action CreateTeamAction = do
    unless userOnPaidPlan do
        setErrorMessage "This requires you to be on the paid plan"
        redirectTo NewTeamAction

    ...

For success messages, the text message is wrapped in a class="alert alert-success".../div, which is automatically styled by bootstrap. Errors flash messages are wraped in class="alert alert-danger".../div.

theFlashMessages :: (?request :: Request) => [FlashMessage] Source #