From 4e2e17dc0550894d2f27ec5eddc68b4f6613fc59 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Mon, 5 Oct 2020 11:45:49 +0300 Subject: [PATCH] Signup FormErrors: cleanup the naming. --- src/SignupPage.tsx | 49 +++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/src/SignupPage.tsx b/src/SignupPage.tsx index 4961352..8c45f3c 100644 --- a/src/SignupPage.tsx +++ b/src/SignupPage.tsx @@ -25,13 +25,12 @@ import { login } from "./store/actions"; import { Link } from "react-router-dom"; interface FormErrors { - errorUsername?: string; - errorEmail?: string; - errorPassword?: string; - errorEncryptionPassword?: string; - errorServer?: string; + username?: string; + email?: string; + password?: string; + server?: string; - errorGeneral?: string; + general?: string; } export default function SignupPage() { @@ -58,23 +57,23 @@ export default function SignupPage() { const errors: FormErrors = {}; const fieldRequired = "This field is required!"; if (!username) { - errors.errorUsername = fieldRequired; + errors.username = fieldRequired; } if (!email) { - errors.errorEmail = fieldRequired; + errors.email = fieldRequired; } if (!password) { - errors.errorPassword = fieldRequired; + errors.password = fieldRequired; } else { const passwordRulesError = enforcePasswordRules(password); if (passwordRulesError) { - errors.errorPassword = passwordRulesError; + errors.password = passwordRulesError; } } if (process.env.NODE_ENV !== "development") { if (showAdvanced && !server.startsWith("https://")) { - errors.errorServer = "Server URI must start with https://"; + errors.server = "Server URI must start with https://"; } } @@ -100,20 +99,20 @@ export default function SignupPage() { if (e.content.errors) { for (const field of e.content.errors) { if (field.field === "user.username") { - errors.errorUsername = field.detail; + errors.username = field.detail; found = true; } else if (!field.field) { - errors.errorGeneral = field.detail; + errors.general = field.detail; found = true; } } } if (!found) { - errors.errorGeneral = e.content.detail ?? e.toString(); + errors.general = e.content.detail ?? e.toString(); } } else { - errors.errorGeneral = e.toString(); + errors.general = e.toString(); } setErrors(errors); } finally { @@ -150,8 +149,8 @@ export default function SignupPage() { {advancedSettings} - {errors.errorGeneral && ( - {errors.errorGeneral} + {errors.general && ( + {errors.general} )}