about summary refs log tree commit diff
path: root/users/wpcarro/assessments/tt/client/src/Login.elm
blob: b1a436098afd95c0fe7da342e85a15c466ece589 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
module Login exposing (render)

import Common
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import State
import Tailwind
import UI
import Utils


googleSignIn : Html State.Msg
googleSignIn =
    div
        [ class "g-signin2"
        , attribute "onsuccess" "onSignIn"
        , onClick State.GoogleSignIn
        ]
        []


loginForm : State.Model -> Html State.Msg
loginForm model =
    div
        [ [ "w-full"
          , "max-w-xs"
          , "mx-auto"
          ]
            |> Tailwind.use
            |> class
        ]
        [ div
            [ [ "bg-white"
              , "shadow-md"
              , "rounded"
              , "px-8"
              , "pt-6"
              , "pb-8"
              , "mb-4"
              , "text-left"
              ]
                |> Tailwind.use
                |> class
            ]
            [ div [ [ "text-center", "pb-6" ] |> Tailwind.use |> class ]
                [ UI.textButton
                    { handleClick = State.ToggleLoginForm
                    , label =
                        case model.loginTab of
                            State.LoginForm ->
                                "Switch to sign up"

                            State.SignUpForm ->
                                "Switch to login"
                    }
                ]
            , div
                [ [ "mb-4" ] |> Tailwind.use |> class ]
                [ UI.label_ { for_ = "username", text_ = "Username" }
                , UI.textField
                    { inputId = "Username"
                    , pholder = "Username"
                    , handleInput = State.UpdateUsername
                    , inputValue = model.username
                    }
                ]
            , case model.loginTab of
                State.LoginForm ->
                    text ""

                State.SignUpForm ->
                    div
                        [ [ "mb-4" ] |> Tailwind.use |> class ]
                        [ UI.label_ { for_ = "email", text_ = "Email" }
                        , input
                            [ [ "shadow"
                              , "appearance-none"
                              , "border"
                              , "rounded"
                              , "w-full"
                              , "py-2"
                              , "px-3"
                              , "text-gray-700"
                              , "leading-tight"
                              , "focus:outline-none"
                              , "focus:shadow-outline"
                              ]
                                |> Tailwind.use
                                |> class
                            , id "email"
                            , placeholder "who@domain.tld"
                            , onInput State.UpdateEmail
                            ]
                            []
                        ]
            , div
                [ [ "mb-4" ] |> Tailwind.use |> class ]
                [ UI.label_ { for_ = "password", text_ = "Password" }
                , input
                    [ [ "shadow"
                      , "appearance-none"
                      , "border"
                      , "rounded"
                      , "w-full"
                      , "py-2"
                      , "px-3"
                      , "text-gray-700"
                      , "leading-tight"
                      , "focus:outline-none"
                      , "focus:shadow-outline"
                      ]
                        |> Tailwind.use
                        |> class
                    , id "password"
                    , type_ "password"
                    , placeholder "******************"
                    , onInput State.UpdatePassword
                    ]
                    []
                ]
            , case model.loginTab of
                State.LoginForm ->
                    div [ [ "flex", "space-around" ] |> Tailwind.use |> class ]
                        [ UI.simpleButton
                            { handleClick = State.AttemptLogin
                            , label = "Login"
                            }
                        , div [ [ "pl-4" ] |> Tailwind.use |> class ] [ googleSignIn ]
                        ]

                State.SignUpForm ->
                    if
                        List.all identity
                            [ String.length model.username > 0
                            , String.length model.email > 0
                            , String.length model.password > 0
                            ]
                    then
                        div []
                            [ UI.simpleButton
                                { handleClick = State.AttemptSignUp
                                , label = "Sign up"
                                }
                            ]

                    else
                        UI.disabledButton { label = "Sign up" }
            ]
        ]


login :
    State.Model
    -> Html State.Msg
login model =
    div
        [ [ "text-center"
          , "py-20"
          , "bg-gray-200"
          , "h-screen"
          ]
            |> Tailwind.use
            |> class
        ]
        [ UI.header 3 "Welcome to Trip Planner"
        , loginForm model
        , Common.allErrors model
        ]


logout : State.Model -> Html State.Msg
logout model =
    div
        [ [ "text-center"
          , "py-20"
          , "bg-gray-200"
          , "h-screen"
          ]
            |> Tailwind.use
            |> class
        ]
        [ UI.header 3 "Looks like you're already signed in..."
        , UI.simpleButton
            { label = "Logout"
            , handleClick = State.AttemptLogout
            }
        , Common.allErrors model
        ]


render : State.Model -> Html State.Msg
render model =
    case model.session of
        Nothing ->
            login model

        Just x ->
            logout model