Commit e8e5625e authored by Darya Rednikina's avatar Darya Rednikina
Browse files

Set up error handling on registration and made fields `alive`

parent c48341ef
......@@ -10920,10 +10920,161 @@ var $author$project$Login$update = F2(
return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none);
}
});
var $author$project$Register$updateForm = F2(
function (transform, model) {
return _Utils_Tuple2(
_Utils_update(
model,
{
form: transform(model.form)
}),
$elm$core$Platform$Cmd$none);
});
var $author$project$Register$Email = {$: 'Email'};
var $author$project$Register$Login = {$: 'Login'};
var $author$project$Register$Name = {$: 'Name'};
var $author$project$Register$Password = {$: 'Password'};
var $author$project$Register$fieldsToValidate = _List_fromArray(
[$author$project$Register$Email, $author$project$Register$Password, $author$project$Register$Login, $author$project$Register$Name]);
var $author$project$Register$Trimmed = function (a) {
return {$: 'Trimmed', a: a};
};
var $elm$core$String$trim = _String_trim;
var $author$project$Register$trimFields = function (form) {
return $author$project$Register$Trimmed(
{
email: $elm$core$String$trim(form.email),
login: $elm$core$String$trim(form.login),
name: $elm$core$String$trim(form.name),
password: $elm$core$String$trim(form.password)
});
};
var $author$project$Register$InvalidEntry = F2(
function (a, b) {
return {$: 'InvalidEntry', a: a, b: b};
});
var $author$project$Register$validateField = F2(
function (_v0, field) {
var form = _v0.a;
var lengthValidation = F3(
function (str, p, msg) {
return p(
$elm$core$String$length(str)) ? _List_Nil : _List_fromArray(
[msg]);
});
var emptyValidation = F2(
function (str, msg) {
return $elm$core$String$isEmpty(str) ? _List_fromArray(
[msg]) : _List_Nil;
});
var passwordValidation = function (pswd) {
var errLength = A3(
lengthValidation,
pswd,
function (x) {
return x > 8;
},
'password must be > 8.');
var errEmpty = A2(emptyValidation, pswd, 'password can\'t be empty.');
return A2($elm$core$List$append, errEmpty, errLength);
};
return A2(
$elm$core$List$map,
$author$project$Register$InvalidEntry(field),
function () {
switch (field.$) {
case 'Email':
return A2(emptyValidation, form.email, 'email can\'t be blank.');
case 'Password':
return passwordValidation(form.password);
case 'Login':
return A2(emptyValidation, form.login, 'login can\'t be blank.');
default:
return A2(emptyValidation, form.name, 'name can\'t be blank.');
}
}());
});
var $author$project$Register$validate = function (form) {
var trimmedForm = $author$project$Register$trimFields(form);
var _v0 = A2(
$elm$core$List$concatMap,
$author$project$Register$validateField(trimmedForm),
$author$project$Register$fieldsToValidate);
if (!_v0.b) {
return $elm$core$Result$Ok(trimmedForm);
} else {
var problems = _v0;
return $elm$core$Result$Err(problems);
}
};
var $author$project$Register$update = F2(
function (msg, model) {
switch (msg.$) {
case 'EnteredEmail':
var email = msg.a;
return A2(
$author$project$Register$updateForm,
function (form) {
return _Utils_update(
form,
{email: email});
},
model);
case 'EnteredPassword':
var psw = msg.a;
return A2(
$author$project$Register$updateForm,
function (form) {
return _Utils_update(
form,
{password: psw});
},
model);
case 'EnteredLogin':
var login = msg.a;
return A2(
$author$project$Register$updateForm,
function (form) {
return _Utils_update(
form,
{login: login});
},
model);
case 'EnteredName':
var name = msg.a;
return A2(
$author$project$Register$updateForm,
function (form) {
return _Utils_update(
form,
{name: name});
},
model);
case 'SubmittedForm':
var _v1 = $author$project$Register$validate(model.form);
if (_v1.$ === 'Ok') {
var validForm = _v1.a;
return _Utils_Tuple2(
_Utils_update(
model,
{problems: _List_Nil}),
$elm$core$Platform$Cmd$none);
} else {
var problems = _v1.a;
return _Utils_Tuple2(
_Utils_update(
model,
{problems: problems}),
$elm$core$Platform$Cmd$none);
}
default:
return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none);
}
});
var $author$project$Main$update = F2(
function (msg, model) {
var _v0 = _Utils_Tuple2(msg, model.page);
_v0$3:
_v0$4:
while (true) {
switch (_v0.a.$) {
case 'LoginMsg':
......@@ -10942,7 +11093,25 @@ var $author$project$Main$update = F2(
A2($elm$core$Platform$Cmd$map, $author$project$Main$LoginMsg, updatedCmd));
return m1;
} else {
break _v0$3;
break _v0$4;
}
case 'RegisterMsg':
if (_v0.b.$ === 'RegisterPage') {
var registerMsg = _v0.a.a;
var m = _v0.b.a;
var _v2 = A2($author$project$Register$update, registerMsg, m);
var updatedPageModel = _v2.a;
var updatedCmd = _v2.b;
var m1 = _Utils_Tuple2(
_Utils_update(
model,
{
page: $author$project$Main$RegisterPage(updatedPageModel)
}),
A2($elm$core$Platform$Cmd$map, $author$project$Main$RegisterMsg, updatedCmd));
return m1;
} else {
break _v0$4;
}
case 'LinkClicked':
var urlReq = _v0.a.a;
......@@ -10960,7 +11129,7 @@ var $author$project$Main$update = F2(
model,
$elm$browser$Browser$Navigation$load(url));
}
case 'UrlChanged':
default:
var url = _v0.a.a;
var newRoute = $author$project$Route$parseUrl(url);
return $author$project$Main$initCurrentPage(
......@@ -10969,8 +11138,6 @@ var $author$project$Main$update = F2(
model,
{route: newRoute}),
$elm$core$Platform$Cmd$none));
default:
break _v0$3;
}
}
return _Utils_Tuple2(model, $elm$core$Platform$Cmd$none);
......@@ -11307,7 +11474,7 @@ var $author$project$Register$viewProblem = function (problem) {
var errorMessage = function () {
if (problem.$ === 'InvalidEntry') {
var msg = problem.b;
return 'вв';
return msg;
} else {
var str = problem.a;
return str;
......
......@@ -54,6 +54,18 @@ update msg model =
in
m1
( RegisterMsg registerMsg, RegisterPage m ) ->
let
( updatedPageModel, updatedCmd ) =
Register.update registerMsg m
m1 =
( { model | page = RegisterPage updatedPageModel }
, Cmd.map RegisterMsg updatedCmd
)
in
m1
( LinkClicked urlReq, _ ) ->
case urlReq of
Browser.Internal url ->
......
......@@ -261,7 +261,7 @@ viewProblem problem =
errorMessage =
case problem of
InvalidEntry _ msg ->
"вв"
msg
ServerError str ->
str
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment