feat(employee): Added functionality to invite multiple emailaddresses. (TV-512)
Squashed commit of the following:
commit 04baa8e9398016ffb0cba618a5b857230dc4ea9e
Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se>
Date: Mon Sep 6 10:52:12 2021 +0200
moved email-regex
commit 0f54392c2e65386f4d0ae79493f6d33d84e313fe
Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se>
Date: Mon Sep 6 07:54:13 2021 +0200
Updated confirmation texts
commit 4557c8203cf826caccff7ac174e15b547f041993
Merge: ec932ec ec7b4fc
Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se>
Date: Mon Sep 6 07:37:56 2021 +0200
Merge branch 'develop' into feature/TV-512-inbjudningar
commit ec932ecad69b96504b2d25f937aa4b6def646f11
Author: Erik Tiekstra <erik.tiekstra@arbetsformedlingen.se>
Date: Fri Sep 3 16:08:22 2021 +0200
Now possible to add commaseparated list of emails
This commit is contained in:
@@ -15,4 +15,6 @@ export interface EmployeeInviteResponse {
|
||||
assignedUsers: ExistingUser[];
|
||||
invitedUsers: string[];
|
||||
existingUsersInCurrentOrg: ExistingUser[];
|
||||
failedInvite: string[];
|
||||
alreadyInvitedUsers: ExistingUser[];
|
||||
}
|
||||
|
||||
@@ -182,11 +182,9 @@ export class EmployeeService extends UnsubscribeDirective {
|
||||
);
|
||||
}
|
||||
|
||||
public postEmployeeInvitation(email: string): Observable<EmployeeInviteResponse> {
|
||||
public postEmployeeInvitation(emails: string[]): Observable<EmployeeInviteResponse> {
|
||||
return this.httpClient
|
||||
.patch<{ data: EmployeeInviteResponse }>(`${this._apiBaseUrl}/invite`, {
|
||||
emails: [email],
|
||||
})
|
||||
.patch<{ data: EmployeeInviteResponse }>(`${this._apiBaseUrl}/invite`, { emails })
|
||||
.pipe(
|
||||
take(1),
|
||||
map(({ data }) => data),
|
||||
|
||||
@@ -1,14 +1,37 @@
|
||||
import { AbstractControl, ValidatorFn } from '@angular/forms';
|
||||
import { ValidationError } from '@msfa-models/validation-error.model';
|
||||
|
||||
export function EmailValidator(label = 'Fältet'): ValidatorFn {
|
||||
const emailRegex = /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$/;
|
||||
const EMAIL_REGEX = /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$/;
|
||||
|
||||
export function EmailValidator(label = 'Fältet'): ValidatorFn {
|
||||
return (control: AbstractControl): ValidationError => {
|
||||
if (control && control.value && !emailRegex.test(control.value)) {
|
||||
if (control && control.value && !EMAIL_REGEX.test(control.value)) {
|
||||
return { type: 'invalid', message: `Ogiltig ${label}` };
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
export function CommaSeparatedEmailValidator(): ValidatorFn {
|
||||
return (control: AbstractControl): ValidationError => {
|
||||
if (control && control.value) {
|
||||
const values: string[] = (control.value as string).replaceAll(' ', '').split(',');
|
||||
const invalidEmailaddresses = [];
|
||||
|
||||
values.forEach(value => {
|
||||
if (value && !EMAIL_REGEX.test(value)) {
|
||||
invalidEmailaddresses.push(value);
|
||||
}
|
||||
});
|
||||
|
||||
if (invalidEmailaddresses.length) {
|
||||
const messagePrepend =
|
||||
invalidEmailaddresses.length > 1 ? 'Ogiltiga e-postadresser: ' : 'Ogiltig e-postadress: ';
|
||||
return { type: 'invalid', message: `${messagePrepend}${invalidEmailaddresses.join(', ')}` };
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user