| init : (Model, Cmd Message) | |
| init = | |
| ( { form = Form.initial initialFields validate | |
| , showPassword = False | |
| , emailTaken = False | |
| , userMaybe = Nothing } | |
| , output (Dict.toList designerRoleOptions) ) | |
| update : Message -> Model -> (Model, Cmd Message) | |
| update message ({ form } as model) = | |
| case message of | |
| NoOp -> | |
| ( model, Cmd.none ) | |
| ValidateEmailUniqueness response -> | |
| case response of | |
| Ok _ -> | |
| ( model, Cmd.none ) | |
| Err _ -> | |
| ( { model | emailTaken = True }, Cmd.none ) | |
| FormMsg formMsg -> | |
| let | |
| form_ = Form.update validate formMsg form | |
| user_ = Form.getOutput form_ | |
| _ = Debug.log "FORM" formMsg | |
| in | |
| case formMsg of | |
| Form.Input "user[type]" Form.Radio (Form.Field.String userType) -> | |
| ({ model | form = Form.update validate formMsg form_ }, switchToUserType userType ) | |
| Form.Input "user[email]" Form.Text (Form.Field.String string) -> | |
| let | |
| emailField = Form.getFieldAsString "user[email]" form_ | |
| request = emailValidationRequest emailField.value | |
| in | |
| case emailField.error of | |
| Nothing -> | |
| (model, Http.send ValidateEmailUniqueness request) | |
| _ -> | |
| (model, Cmd.none) | |
| Form.Input "togglePassword" Form.Checkbox string -> | |
| ({ model | showPassword = not model.showPassword }, Cmd.none ) | |
| _ -> | |
| ({ model | form = form_, userMaybe = user_ }, Cmd.none) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment