Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,11 @@ <h2 id="org-edit-dialog-title" class="w-dialog-title">Edit Organization</h2>
</p>
} @else if (
organizationForm.get('companyName')?.touched &&
organizationForm.get('companyName')?.hasError('minlength')
organizationForm.get('companyName')?.hasError('pattern')
) {
<p id="org-company-name-error" role="alert" class="w-field-error">
Company name must be at least 3 characters.
Company name must start with a letter or number and contain only letters, numbers,
underscores, or spaces.
</p>
}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { BaseComponent } from 'libs/ui/base-component/src/lib/base-component/bas
import { OtpService } from '../service/otp.service';
import { WidgetThemeService } from '../service/widget-theme.service';
import { finalize, takeUntil } from 'rxjs';
import { EMAIL_REGEX } from '@proxy/regex';
import { COMPANY_NAME_REGEX, EMAIL_REGEX } from '@proxy/regex';

@Component({
selector: 'organization-details',
Expand All @@ -43,7 +43,7 @@ export class OrganizationDetailsComponent extends BaseComponent implements OnIni
readonly isDark = computed(() => this.themeService.isDark$());

public organizationForm = new FormGroup({
companyName: new FormControl<string>('', [Validators.required, Validators.minLength(3)]),
companyName: new FormControl<string>('', [Validators.required, Validators.pattern(COMPANY_NAME_REGEX)]),
email: new FormControl<string>('', [Validators.required, Validators.pattern(EMAIL_REGEX)]),
phoneNumber: new FormControl<string>('', [Validators.pattern(/^$|^[0-9]{10,15}$/)]),
timezone: new FormControl<string>(''),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { WidgetTheme } from '@proxy/constant';
import { WidgetDialogRef } from '../service/widget-dialog.service';
import { ToastService } from '../service/toast.service';
import { ToastComponent } from '../service/toast.component';
import { NAME_REGEX } from '@proxy/regex';

/**
* Standalone Add-User dialog.
Expand Down Expand Up @@ -179,7 +180,7 @@ export class AddUserDialogComponent implements OnInit, OnDestroy {

ngOnInit(): void {
this.form = this.fb.group({
name: ['', [Validators.required, Validators.pattern(/^[\p{L}\s'-]+$/u)]],
name: ['', [Validators.required, Validators.pattern(NAME_REGEX)]],
email: ['', [Validators.required, Validators.email]],
mobileNumber: ['', [Validators.pattern(/^(\+?[1-9]\d{1,14}|[0-9]{10})$/)]],
role: [''],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { CommonModule } from '@angular/common';
import { ToastService } from '../service/toast.service';
import { ToastComponent } from '../service/toast.component';
import { WidgetTheme } from '@proxy/constant';
import { UPDATE_REGEX } from '@proxy/regex';
import { NAME_REGEX } from '@proxy/regex';
import { FormsModule, ReactiveFormsModule, FormBuilder, FormGroup, Validators } from '@angular/forms';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { Actions, ofType } from '@ngrx/effects';
Expand All @@ -42,6 +42,7 @@ import {
updateRoleData,
updateUserPermissionData,
updateUserRoleData,
deleteUserData,
} from '../store/selectors';
import { isEqual } from 'lodash-es';
import { WidgetThemeService } from '../service/widget-theme.service';
Expand Down Expand Up @@ -276,6 +277,17 @@ export class UserManagementComponent implements OnInit, AfterViewInit, OnDestroy
}
});

this.store
.pipe(select(deleteUserData), distinctUntilChanged(isEqual), takeUntilDestroyed(this.destroyRef))
.subscribe((res) => {
if (res) {
this.getCompanyUsers();
const message = res?.data?.message || res?.message || 'User removed successfully.';
this.toastService.success(message);
this.cdr.markForCheck();
}
});

this.actions$
.pipe(
ofType(
Expand All @@ -286,7 +298,8 @@ export class UserManagementComponent implements OnInit, AfterViewInit, OnDestroy
otpActions.addUserError,
otpActions.updateCompanyUserError,
otpActions.updateUserRoleError,
otpActions.updateUserPermissionError
otpActions.updateUserPermissionError,
otpActions.deleteUserError
),
takeUntilDestroyed(this.destroyRef)
)
Expand All @@ -310,7 +323,7 @@ export class UserManagementComponent implements OnInit, AfterViewInit, OnDestroy
});

this.addUserForm = this.fb.group({
name: ['', [Validators.required, Validators.pattern(UPDATE_REGEX)]],
name: ['', [Validators.required, Validators.pattern(NAME_REGEX)]],
email: ['', [Validators.required, Validators.email]],
mobileNumber: ['', [Validators.pattern(/^(\+?[1-9]\d{1,14}|[0-9]{10})$/)]],
role: [''],
Expand Down Expand Up @@ -400,8 +413,6 @@ export class UserManagementComponent implements OnInit, AfterViewInit, OnDestroy
public confirmDelete(): void {
if (this.pendingDeleteUser) {
const userId = (this.pendingDeleteUser as any).user_id;
this.userData = this.userData.filter((u: any) => u.user_id !== userId);
this.totalUsers = Math.max(0, this.totalUsers - 1);
this.store.dispatch(otpActions.deleteUser({ companyId: userId, authToken: this.userToken() }));
}
this.cancelDelete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
} from '../store/selectors';
import { BaseComponent } from '@proxy/ui/base-component';
import { isEqual } from 'lodash-es';
import { UPDATE_REGEX } from '@proxy/regex';
import { NAME_REGEX } from '@proxy/regex';
import { WidgetTheme } from '@proxy/constant';
import { WidgetThemeService } from '../service/widget-theme.service';
@Component({
Expand Down Expand Up @@ -88,7 +88,7 @@ export class UserProfileComponent extends BaseComponent implements OnInit, After
// authToken: string = '';

clientForm = new FormGroup({
name: new FormControl('', [Validators.required, Validators.pattern(UPDATE_REGEX)]),
name: new FormControl('', [Validators.required, Validators.pattern(NAME_REGEX)]),
mobile: new FormControl({ value: '', disabled: true }),
email: new FormControl({ value: '', disabled: true }),
});
Expand Down
5 changes: 2 additions & 3 deletions libs/regex/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ export const CAMPAIGN_NAME_REGEX = /^[a-zA-Z0-9][a-zA-Z0-9_\s]+$/;
export const ALPHANUMERIC_WITH_DASH_CAPS_AND_STARTS_WITH_ALPHABET_REGEX = /^[A-Za-z][A-Za-z0-9\-\_]*$/;
export const PERMISSION_NAME_REGEX = /^[a-zA-Z0-9_\s]+$/;
export const NON_ASCII_PRINTABLE_CHARACTERS_REGEX = /[^\t\r\n\x20-\x7E]/;
export const FULL_NAME_REGEX = /^([\w])+\s+([\w\s])+$/i;
export const PASSWORD_REGEX = /(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[\W_]).*/; // Should Contain at least one lowercase letter, one uppercase letter, one number and one symbol
export const NAME_REGEX = /^([a-zA-Z]+\s)*[a-zA-Z]+$/i;
export const NAME_REGEX = /^[a-zA-Z][a-zA-Z\s]{2,49}$/;
export const EMAIL_OR_MOBILE_REGEX =
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$|^[0-9]{7,15}$/;
export const UPDATE_REGEX = /^[a-zA-Z0-9][a-zA-Z0-9_\s]+$/;
export const COMPANY_NAME_REGEX = /^[a-zA-Z0-9][a-zA-Z0-9_\s]+$/;
Loading