[AC-2244] Fix submitting member invite form (#8009)
* Fix invite member dialog not submitting on enter updateOn: onBlur is unnecessary with component library forms and was preventing the form from being submitted without deselecting the email field * Simplify name for validator
This commit is contained in:
parent
ed2bd7c900
commit
e0186b3a8e
|
@ -37,7 +37,7 @@ import {
|
||||||
} from "../../../shared/components/access-selector";
|
} from "../../../shared/components/access-selector";
|
||||||
|
|
||||||
import { commaSeparatedEmails } from "./validators/comma-separated-emails.validator";
|
import { commaSeparatedEmails } from "./validators/comma-separated-emails.validator";
|
||||||
import { orgWithoutAdditionalSeatLimitReachedWithUpgradePathValidator } from "./validators/org-without-additional-seat-limit-reached-with-upgrade-path.validator";
|
import { orgSeatLimitReachedValidator } from "./validators/org-seat-limit-reached.validator";
|
||||||
|
|
||||||
export enum MemberDialogTab {
|
export enum MemberDialogTab {
|
||||||
Role = 0,
|
Role = 0,
|
||||||
|
@ -84,7 +84,7 @@ export class MemberDialogComponent implements OnInit, OnDestroy {
|
||||||
protected groupAccessItems: AccessItemView[] = [];
|
protected groupAccessItems: AccessItemView[] = [];
|
||||||
protected tabIndex: MemberDialogTab;
|
protected tabIndex: MemberDialogTab;
|
||||||
protected formGroup = this.formBuilder.group({
|
protected formGroup = this.formBuilder.group({
|
||||||
emails: ["", { updateOn: "blur" }],
|
emails: [""],
|
||||||
type: OrganizationUserType.User,
|
type: OrganizationUserType.User,
|
||||||
externalId: this.formBuilder.control({ value: "", disabled: true }),
|
externalId: this.formBuilder.control({ value: "", disabled: true }),
|
||||||
accessAllCollections: false,
|
accessAllCollections: false,
|
||||||
|
@ -176,7 +176,7 @@ export class MemberDialogComponent implements OnInit, OnDestroy {
|
||||||
const emailsControlValidators = [
|
const emailsControlValidators = [
|
||||||
Validators.required,
|
Validators.required,
|
||||||
commaSeparatedEmails,
|
commaSeparatedEmails,
|
||||||
orgWithoutAdditionalSeatLimitReachedWithUpgradePathValidator(
|
orgSeatLimitReachedValidator(
|
||||||
this.organization,
|
this.organization,
|
||||||
this.params.allOrganizationUserEmails,
|
this.params.allOrganizationUserEmails,
|
||||||
this.i18nService.t("subscriptionUpgrade", organization.seats),
|
this.i18nService.t("subscriptionUpgrade", organization.seats),
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { OrganizationUserType } from "@bitwarden/common/admin-console/enums";
|
||||||
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
|
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
|
||||||
import { ProductType } from "@bitwarden/common/enums";
|
import { ProductType } from "@bitwarden/common/enums";
|
||||||
|
|
||||||
import { orgWithoutAdditionalSeatLimitReachedWithUpgradePathValidator } from "./org-without-additional-seat-limit-reached-with-upgrade-path.validator";
|
import { orgSeatLimitReachedValidator } from "./org-seat-limit-reached.validator";
|
||||||
|
|
||||||
const orgFactory = (props: Partial<Organization> = {}) =>
|
const orgFactory = (props: Partial<Organization> = {}) =>
|
||||||
Object.assign(
|
Object.assign(
|
||||||
|
@ -17,7 +17,7 @@ const orgFactory = (props: Partial<Organization> = {}) =>
|
||||||
props,
|
props,
|
||||||
);
|
);
|
||||||
|
|
||||||
describe("orgWithoutAdditionalSeatLimitReachedWithUpgradePathValidator", () => {
|
describe("orgSeatLimitReachedValidator", () => {
|
||||||
let organization: Organization;
|
let organization: Organization;
|
||||||
let allOrganizationUserEmails: string[];
|
let allOrganizationUserEmails: string[];
|
||||||
let validatorFn: (control: AbstractControl) => ValidationErrors | null;
|
let validatorFn: (control: AbstractControl) => ValidationErrors | null;
|
||||||
|
@ -27,7 +27,7 @@ describe("orgWithoutAdditionalSeatLimitReachedWithUpgradePathValidator", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return null when control value is empty", () => {
|
it("should return null when control value is empty", () => {
|
||||||
validatorFn = orgWithoutAdditionalSeatLimitReachedWithUpgradePathValidator(
|
validatorFn = orgSeatLimitReachedValidator(
|
||||||
organization,
|
organization,
|
||||||
allOrganizationUserEmails,
|
allOrganizationUserEmails,
|
||||||
"You cannot invite more than 2 members without upgrading your plan.",
|
"You cannot invite more than 2 members without upgrading your plan.",
|
||||||
|
@ -40,7 +40,7 @@ describe("orgWithoutAdditionalSeatLimitReachedWithUpgradePathValidator", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return null when control value is null", () => {
|
it("should return null when control value is null", () => {
|
||||||
validatorFn = orgWithoutAdditionalSeatLimitReachedWithUpgradePathValidator(
|
validatorFn = orgSeatLimitReachedValidator(
|
||||||
organization,
|
organization,
|
||||||
allOrganizationUserEmails,
|
allOrganizationUserEmails,
|
||||||
"You cannot invite more than 2 members without upgrading your plan.",
|
"You cannot invite more than 2 members without upgrading your plan.",
|
||||||
|
@ -57,7 +57,7 @@ describe("orgWithoutAdditionalSeatLimitReachedWithUpgradePathValidator", () => {
|
||||||
planProductType: ProductType.Free,
|
planProductType: ProductType.Free,
|
||||||
seats: 2,
|
seats: 2,
|
||||||
});
|
});
|
||||||
validatorFn = orgWithoutAdditionalSeatLimitReachedWithUpgradePathValidator(
|
validatorFn = orgSeatLimitReachedValidator(
|
||||||
organization,
|
organization,
|
||||||
allOrganizationUserEmails,
|
allOrganizationUserEmails,
|
||||||
"You cannot invite more than 2 members without upgrading your plan.",
|
"You cannot invite more than 2 members without upgrading your plan.",
|
||||||
|
@ -74,7 +74,7 @@ describe("orgWithoutAdditionalSeatLimitReachedWithUpgradePathValidator", () => {
|
||||||
planProductType: ProductType.TeamsStarter,
|
planProductType: ProductType.TeamsStarter,
|
||||||
seats: 10,
|
seats: 10,
|
||||||
});
|
});
|
||||||
validatorFn = orgWithoutAdditionalSeatLimitReachedWithUpgradePathValidator(
|
validatorFn = orgSeatLimitReachedValidator(
|
||||||
organization,
|
organization,
|
||||||
allOrganizationUserEmails,
|
allOrganizationUserEmails,
|
||||||
"You cannot invite more than 10 members without upgrading your plan.",
|
"You cannot invite more than 10 members without upgrading your plan.",
|
||||||
|
@ -102,7 +102,7 @@ describe("orgWithoutAdditionalSeatLimitReachedWithUpgradePathValidator", () => {
|
||||||
seats: 2,
|
seats: 2,
|
||||||
});
|
});
|
||||||
const errorMessage = "You cannot invite more than 2 members without upgrading your plan.";
|
const errorMessage = "You cannot invite more than 2 members without upgrading your plan.";
|
||||||
validatorFn = orgWithoutAdditionalSeatLimitReachedWithUpgradePathValidator(
|
validatorFn = orgSeatLimitReachedValidator(
|
||||||
organization,
|
organization,
|
||||||
allOrganizationUserEmails,
|
allOrganizationUserEmails,
|
||||||
"You cannot invite more than 2 members without upgrading your plan.",
|
"You cannot invite more than 2 members without upgrading your plan.",
|
||||||
|
@ -120,7 +120,7 @@ describe("orgWithoutAdditionalSeatLimitReachedWithUpgradePathValidator", () => {
|
||||||
planProductType: ProductType.Enterprise,
|
planProductType: ProductType.Enterprise,
|
||||||
seats: 100,
|
seats: 100,
|
||||||
});
|
});
|
||||||
validatorFn = orgWithoutAdditionalSeatLimitReachedWithUpgradePathValidator(
|
validatorFn = orgSeatLimitReachedValidator(
|
||||||
organization,
|
organization,
|
||||||
allOrganizationUserEmails,
|
allOrganizationUserEmails,
|
||||||
"You cannot invite more than 2 members without upgrading your plan.",
|
"You cannot invite more than 2 members without upgrading your plan.",
|
|
@ -11,7 +11,7 @@ import { ProductType } from "@bitwarden/common/enums";
|
||||||
* @param errorMessage A localized string to display if validation fails
|
* @param errorMessage A localized string to display if validation fails
|
||||||
* @returns A function that validates an `AbstractControl` and returns `ValidationErrors` or `null`
|
* @returns A function that validates an `AbstractControl` and returns `ValidationErrors` or `null`
|
||||||
*/
|
*/
|
||||||
export function orgWithoutAdditionalSeatLimitReachedWithUpgradePathValidator(
|
export function orgSeatLimitReachedValidator(
|
||||||
organization: Organization,
|
organization: Organization,
|
||||||
allOrganizationUserEmails: string[],
|
allOrganizationUserEmails: string[],
|
||||||
errorMessage: string,
|
errorMessage: string,
|
Loading…
Reference in New Issue