Skip to content

Commit

Permalink
registration-form: add validation for agreed, add values in template …
Browse files Browse the repository at this point in the history
…for agreed and gender components
  • Loading branch information
MSt1ch committed Dec 11, 2024
1 parent a1d8520 commit 5e641be
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
24 changes: 21 additions & 3 deletions frontend/app/components/registration-form/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -110,7 +113,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;
}
Expand Down Expand Up @@ -139,6 +142,17 @@ export default class RegistrationFormComponent extends LoginFormComponent {
@action
onSubmit(e: SubmitEvent & any) {
e.preventDefault();
if (!this.agreed) {
this.agreedStatusErrorMessage = this.intl.t('registration_form.agree_terms');
return;
}

if (this.errorMessage) {
return;
}

this.serverErrorMessage = ''

this.registrationTask.perform();
}

Expand All @@ -150,6 +164,10 @@ export default class RegistrationFormComponent extends LoginFormComponent {
@action
setAgreedStatus(e: Document & any) {
this.agreed = e.target.checked;

if (this.agreed) {
this.agreedStatusErrorMessage = '';
}
}

@action
Expand All @@ -166,7 +184,7 @@ export default class RegistrationFormComponent extends LoginFormComponent {
const isValid = allowedKeys.includes(key) || !isNaN(key as any);
if (!isValid) {
e.preventDefault();
}
}

}
}
15 changes: 14 additions & 1 deletion frontend/app/components/registration-form/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
/>
<label class="ml-1 text-sm text-gray-500" for="female">
Expand All @@ -68,6 +69,7 @@
value="MALE"
class="w-3 h-3 ml-4"
id="male"
checked={{eq this.gender "MALE"}}
{{on "change" this.setGender}}
/>
<label class="ml-1 text-sm text-gray-500" for="male">
Expand Down Expand Up @@ -120,12 +122,18 @@
{{this.errorMessage}}
</p>
{{/if}}
{{#if this.serverErrorMessage}}
<p data-test-form-error class="mt-2 text-xs text-red-500">
{{this.serverErrorMessage}}
</p>
{{/if}}
</div>
<div class="flex mb-4">
<input
id="agreement"
name="agreement"
type="checkbox"
checked={{this.agreed}}
{{on "change" this.setAgreedStatus}}
/>
<label class="block ml-2 text-sm" for="agreement">
Expand All @@ -138,11 +146,16 @@
</LinkTo>
</label>
</div>
{{#if this.agreedStatusErrorMessage}}
<p data-test-form-error class="mt-2 text-xs text-red-500">
{{this.agreedStatusErrorMessage}}
</p>
{{/if}}
<div class="flex mb-4">
<Ui::Button
@type="submit"
class="w-full"
disabled={{not this.agreed}}
disabled={{false}}
data-test-submit-form
@title={{t "registration_form.registration"}}
/>
Expand Down
1 change: 1 addition & 0 deletions frontend/translations/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ registration_form:
invalid_date: Invalid date
empty_gender: Empty gender
empty_lastname: Empty LastName
agree_terms: You must agree to the terms before registering
gender: Gender
gender_female: Female
gender_male: Male
Expand Down
1 change: 1 addition & 0 deletions frontend/translations/ru-ru.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ registration_form:
empty_gender: Пол не указан
empty_lastname: Фамилия не Указана
warning_enter_credentials: Пожалуйста, введите логин и пароль.
agree_terms: Вы должны согласиться с условиями перед регистрацией
gender: Пол
gender_female: Женский
gender_male: Мужской
Expand Down

0 comments on commit 5e641be

Please sign in to comment.