Flo
Flo

Reputation: 449

Trying to bring HSP and Acid-state together in a form with Happstack

I followed the Happstack Crash Course and now I am trying to bring different things together:

From "Type-Safe Form processing using reform" (http://happstack.com/docs/crashcourse/Reform.html#reform) I have coded this register form:

register :: AcidState UserBase -> ServerPart Response
register acid = unXMLGenT $
  appTemplate "register" () $
        reform (form "/register") "register" (insertAndRenderUser acid) Nothing registerForm

insertAndRenderUser :: (Monad m) => AcidState UserBase -> User -> AppT m XML
insertAndRenderUser acid user = 
    <dl>
      <dt>lastname:</dt>    <dd><% lastName user    %></dd>
      <dt>firstname:</dt>   <dd><% firstName user   %></dd>
      <dt>email:</dt> <dd><% email user %></dd>
      <dt>birthday:</dt> <dd><% show (birthday user) %></dd>
    </dl>


registerForm :: SimpleForm User
registerForm =
    User (UserId 0)
     <$> (errorList ++> label "Last name:"  ++>  (inputText "" `transformEither` required) <++ br)
     <*> (errorList ++> label "First name:" ++> (inputText "" `transformEither` required) <++ br)
     <*> (errorList ++> label "E-mail:"     ++> (inputText "" `transformEither` required) <++ br)
     <*> (errorList ++> label "Birthday:"   ++> (inputText "" `transformEither` requireDate) <++ br)
     <*  inputSubmit "Register"

Now I want to add the registered user when the form is successful. I have coded this UserBase with help of acid-state (http://happstack.com/docs/crashcourse/AcidState.html#ixset)

insertUser :: MonadIO m => AcidState (EventState InsertUserIntern) -> User -> m (EventResult InsertUserIntern)  
insertUser acid user = do
  update' acid (InsertUserIntern user)

The snippets work separately but where can I insert insertUser acid user in insertAndRenderUser ?

I hope you can help me
Thanks
Flo

Upvotes: 0

Views: 115

Answers (1)

Flo
Flo

Reputation: 449

got it myself

insertAndRenderUser acid user = do
  insertUser acid user 
  appTemplate "Your Registration" () $
    <dl>
      <dt>lastname:</dt>    <dd><% lastName user    %></dd>
      <dt>firstname:</dt>   <dd><% firstName user   %></dd>
      <dt>email:</dt> <dd><% email user %></dd>
      <dt>birthday:</dt> <dd><% show (birthday user) %></dd>
    </dl>

Upvotes: 1

Related Questions