From 60635e26a75e1de8b6be6f22fb399377ef7472c8 Mon Sep 17 00:00:00 2001 From: Stanislau Matsiyeuski Date: Wed, 11 Dec 2024 21:10:25 +0300 Subject: [PATCH] registration-form: add validation for agreed, add values in template for agreed and gender components --- .../components/registration-form/component.ts | 27 ++++++++++++++++--- .../components/registration-form/template.hbs | 15 ++++++++++- frontend/translations/en-us.yaml | 1 + frontend/translations/ru-ru.yaml | 1 + 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/frontend/app/components/registration-form/component.ts b/frontend/app/components/registration-form/component.ts index 86878eb57..2f5e09885 100644 --- a/frontend/app/components/registration-form/component.ts +++ b/frontend/app/components/registration-form/component.ts @@ -32,6 +32,9 @@ export default class RegistrationFormComponent extends LoginFormComponent { @tracked gender!: 'MALE' | 'FEMALE'; @tracked agreed = false; + @tracked agreedStatusErrorMessage = ''; + @tracked serverErrorMessage = ''; + get warningPasswordsEquality() { if (this.repeatPassword === undefined) { return false; @@ -82,6 +85,7 @@ export default class RegistrationFormComponent extends LoginFormComponent { } get registrationInProgress() { + console.log('here') return ( this.loginInProgress || this.registrationTask.lastSuccessful || @@ -110,7 +114,7 @@ export default class RegistrationFormComponent extends LoginFormComponent { ) as FirebaseAuthenticator; yield auth.registerUser(user.email, user.password); } catch (e) { - this.errorMessage = e.message; + this.serverErrorMessage = e.message; yield this.registrationTask.cancelAll(); return; } @@ -139,6 +143,19 @@ export default class RegistrationFormComponent extends LoginFormComponent { @action onSubmit(e: SubmitEvent & any) { e.preventDefault(); + console.log('onSubmit') + console.log(this.agreed, 'this.agreed') + if (!this.agreed) { + this.agreedStatusErrorMessage = this.intl.t('registration_form.agree_terms'); + return; + } + + if (this.errorMessage) { + return; + } + + this.serverErrorMessage = '' + this.registrationTask.perform(); } @@ -150,6 +167,10 @@ export default class RegistrationFormComponent extends LoginFormComponent { @action setAgreedStatus(e: Document & any) { this.agreed = e.target.checked; + + if (this.agreed) { + this.agreedStatusErrorMessage = ''; + } } @action @@ -166,7 +187,7 @@ export default class RegistrationFormComponent extends LoginFormComponent { const isValid = allowedKeys.includes(key) || !isNaN(key as any); if (!isValid) { e.preventDefault(); - } - + } + } } diff --git a/frontend/app/components/registration-form/template.hbs b/frontend/app/components/registration-form/template.hbs index ae93973d8..7148182b6 100644 --- a/frontend/app/components/registration-form/template.hbs +++ b/frontend/app/components/registration-form/template.hbs @@ -56,6 +56,7 @@ type="radio" class="w-3 h-3 border-gray-300" id="female" + checked={{eq this.gender "FEMALE"}} {{on "change" this.setGender}} />