Random Bugs (#2531)

This commit is contained in:
Joe Milazzo 2024-01-06 10:33:56 -06:00 committed by GitHub
parent 0c70e80420
commit 4e1c66331f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 232 additions and 178 deletions

View file

@ -29,14 +29,22 @@
<div *ngFor="let error of errors">{{error}}</div>
</div>
<form [formGroup]="form">
@if(!hasValidEmail) {
<div class="alert alert-warning" role="alert">
{{t('has-invalid-email')}}
</div>
}
<div class="mb-3">
<label for="email" class="form-label visually-hidden">{{t('email-label')}}</label>
<input class="form-control custom-input" type="email" id="email" formControlName="email"
[class.is-invalid]="form.get('email')?.invalid && form.get('email')?.touched">
<div id="email-validations" class="invalid-feedback" *ngIf="form.dirty || form.touched">
<div id="email-validations" class="invalid-feedback" *ngIf="form.get('email')?.errors">
<div *ngIf="form.get('email')?.errors?.required">
{{t('required-field')}}
</div>
<div *ngIf="form.get('email')?.errors?.email">
{{t('valid-email')}}
</div>
</div>
</div>

View file

@ -2,13 +2,12 @@ import {ChangeDetectionStrategy, ChangeDetectorRef, Component, DestroyRef, injec
import { FormControl, FormGroup, Validators, ReactiveFormsModule } from '@angular/forms';
import {ToastrService} from 'ngx-toastr';
import {shareReplay, take} from 'rxjs';
import {UpdateEmailResponse} from 'src/app/_models/auth/update-email-response';
import {User} from 'src/app/_models/user';
import {AccountService} from 'src/app/_services/account.service';
import {takeUntilDestroyed} from "@angular/core/rxjs-interop";
import { ApiKeyComponent } from '../api-key/api-key.component';
import { NgbTooltip, NgbCollapse } from '@ng-bootstrap/ng-bootstrap';
import { NgIf, NgFor } from '@angular/common';
import {NgIf, NgFor, JsonPipe} from '@angular/common';
import {translate, TranslocoDirective} from "@ngneat/transloco";
@Component({
@ -17,17 +16,20 @@ import {translate, TranslocoDirective} from "@ngneat/transloco";
styleUrls: ['./change-email.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [NgIf, NgbTooltip, NgbCollapse, NgFor, ReactiveFormsModule, ApiKeyComponent, TranslocoDirective]
imports: [NgIf, NgbTooltip, NgbCollapse, NgFor, ReactiveFormsModule, ApiKeyComponent, TranslocoDirective, JsonPipe]
})
export class ChangeEmailComponent implements OnInit {
private readonly destroyRef = inject(DestroyRef);
form: FormGroup = new FormGroup({});
user: User | undefined = undefined;
errors: string[] = [];
isViewMode: boolean = true;
emailLink: string = '';
emailConfirmed: boolean = true;
private readonly destroyRef = inject(DestroyRef);
hasValidEmail: boolean = true;
public get email() { return this.form.get('email'); }
@ -45,6 +47,10 @@ export class ChangeEmailComponent implements OnInit {
this.emailConfirmed = confirmed;
this.cdRef.markForCheck();
});
this.accountService.isEmailValid().subscribe(isValid => {
this.hasValidEmail = isValid;
this.cdRef.markForCheck();
});
});
}
@ -59,13 +65,14 @@ export class ChangeEmailComponent implements OnInit {
const model = this.form.value;
this.errors = [];
this.accountService.updateEmail(model.email, model.password).subscribe((updateEmailResponse: UpdateEmailResponse) => {
this.accountService.updateEmail(model.email, model.password).subscribe(updateEmailResponse => {
if (updateEmailResponse.invalidEmail) {
this.toastr.success(translate('toasts.email-sent-to-no-existing', {email: model.email}));
}
if (updateEmailResponse.emailSent) {
if (updateEmailResponse.hadNoExistingEmail) {
this.toastr.success(translate('toasts.email-sent-to-no-existing', {email: model.email}));
} else {
this.toastr.success(translate('toasts.email-sent-to'));
}
this.toastr.success(translate('toasts.email-sent-to'));
} else {
this.toastr.success(translate('toasts.change-email-private'));
}