fix: validate tenant and lease contact details
This commit is contained in:
1 parent
8603b98714
commit
bf6d8e6bb6
27 files changed
+444
-54
No files matched your search
@@ -3,6 +3,7 @@ import { FormsModule } from '@angular/forms';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { isValidEmail, isValidPhone } from '../../shared/contact-validation';
|
||||
import { Tenant, TenantAttachment } from '../../services/tenant.service';
|
||||
|
||||
export interface TenantSaveRequest {
|
||||
@@ -23,6 +24,7 @@ export interface TenantAttachmentRequest {
|
||||
})
|
||||
export class TenantsPage {
|
||||
readonly tenants = input.required<Tenant[]>();
|
||||
readonly attachmentError = input('');
|
||||
readonly tenantSaved = output<TenantSaveRequest>();
|
||||
readonly deleteRequested = output<string>();
|
||||
readonly attachmentUploadRequested = output<{ tenantId: string; file: File }>();
|
||||
@@ -36,6 +38,7 @@ export class TenantsPage {
|
||||
readonly phone = signal('');
|
||||
readonly address = signal('');
|
||||
readonly error = signal('');
|
||||
readonly attachmentUploadError = signal('');
|
||||
|
||||
constructor() {
|
||||
effect(() => this.fillForm(this.editingTenant()));
|
||||
@@ -62,6 +65,14 @@ export class TenantsPage {
|
||||
this.error.set('Le prénom, le nom et l’e-mail sont obligatoires.');
|
||||
return;
|
||||
}
|
||||
if (!isValidEmail(this.email())) {
|
||||
this.error.set('Saisissez une adresse e-mail valide.');
|
||||
return;
|
||||
}
|
||||
if (!isValidPhone(this.phone())) {
|
||||
this.error.set('Saisissez un numéro français ou international valide.');
|
||||
return;
|
||||
}
|
||||
this.tenantSaved.emit({
|
||||
tenant: {
|
||||
firstName: this.firstName().trim(),
|
||||
@@ -77,7 +88,10 @@ export class TenantsPage {
|
||||
|
||||
selectFile(tenant: Tenant, event: Event): void {
|
||||
const file = (event.target as HTMLInputElement).files?.item(0);
|
||||
if (tenant.id && file) {
|
||||
if (file && file.size > 250 * 1024 * 1024) {
|
||||
this.attachmentUploadError.set('Une pièce jointe ne peut pas dépasser 250 Mo.');
|
||||
} else if (tenant.id && file) {
|
||||
this.attachmentUploadError.set('');
|
||||
this.attachmentUploadRequested.emit({ tenantId: tenant.id, file });
|
||||
}
|
||||
(event.target as HTMLInputElement).value = '';
|
||||
|
||||
Reference in new issue
Block a user