Skip to content

Commit

Permalink
Merge pull request #2656 from MSt1ch/registration-form-bug
Browse files Browse the repository at this point in the history
* registration-form: add validation for agreed, add values in template for agreed and gender components

* chore: update domain name

---------

Co-authored-by: Alex Kanunnikov <lifeart92@gmail.com>
  • Loading branch information
lifeart authored Dec 11, 2024
2 parents a1d8520 + 2531ea1 commit 6ec1824
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 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
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"on:precommit": "lint-staged",
"local": "ember s --secure-proxy=false --proxy=http://localhost:8081",
"develop": "cross-env FIREBASE_PROJECT_ID=brainup-spb-dev-bb6d0 FIREBASE_AUTH_DOMAIN=brainup-spb-dev-bb6d0.firebaseapp.com FIREBASE_API_KEY=AIzaSyB03Q4ZCxdqaKuN7cJqCQGhkibYD4Q-qsc ember s --secure-proxy=false --proxy=http://localhost:8081",
"remote": "ember s --secure-proxy=true --proxy=https://brainup.site/",
"remote": "ember s --secure-proxy=true --proxy=https://www.brainup.site/",
"mirage": "ember s",
"postinstall": "patch-package"
},
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 6ec1824

Please sign in to comment.