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 @@ -5,7 +5,15 @@
<h2 class="page-title">Organization Details</h2>

<div class="header-actions" *ngIf="!isEditing">
<button type="button" class="edit-btn" (click)="startEdit()">
<button
type="button"
[ngClass]="{ 'disabled': !allowedUpdatePermissions }"
[disabled]="!allowedUpdatePermissions"
class="edit-btn"
(click)="startEdit()"
[matTooltip]="!allowedUpdatePermissions ? 'No permission' : ''"
matTooltipPosition="right"
>
<svg
class="btn-icon"
viewBox="0 0 24 24"
Expand Down Expand Up @@ -129,7 +137,7 @@ <h2 class="page-title">Organization Details</h2>
<mat-label>Email </mat-label>
<input matInput type="email" formControlName="email" placeholder="Enter email" />
<mat-error *ngIf="organizationForm.get('email')?.hasError('required')"> Email is required. </mat-error>
<mat-error *ngIf="organizationForm.get('email')?.hasError('email')">
<mat-error *ngIf="organizationForm.get('email')?.hasError('pattern')">
Please enter a valid email.
</mat-error>
</mat-form-field>
Expand All @@ -142,7 +150,7 @@ <h2 class="page-title">Organization Details</h2>
</mat-error>
</mat-form-field>

<mat-form-field appearance="outline" class="full-width">
<mat-form-field appearance="outline" class="full-width timezone-field">
<mat-label>Timezone</mat-label>
<mat-select
formControlName="timeZoneName"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,11 @@
color: #ffffff !important;
}
}
.disabled {
opacity: 0.5;
}
.timezone-field {
.mat-select-arrow-wrapper {
height: unset;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { BaseComponent } from 'libs/ui/base-component/src/lib/base-component/bas
import { OtpService } from '../service/otp.service';
import { finalize, takeUntil } from 'rxjs';
import { MatSnackBar } from '@angular/material/snack-bar';
import { EMAIL_REGEX } from '@proxy/regex';

@Component({
selector: 'organization-details',
Expand All @@ -19,7 +20,7 @@ export class OrganizationDetailsComponent extends BaseComponent implements OnIni

public organizationForm = new FormGroup({
companyName: new FormControl<string>('', [Validators.required, Validators.minLength(3)]),
email: new FormControl<string>('', [Validators.required, Validators.email]),
email: new FormControl<string>('', [Validators.required, Validators.pattern(EMAIL_REGEX)]),
phoneNumber: new FormControl<string>('', [Validators.pattern(/^$|^[0-9]{10,15}$/)]),
timezone: new FormControl<string>('', [Validators.required]),
timeZoneName: new FormControl<string>('', [Validators.required]),
Expand Down Expand Up @@ -49,6 +50,8 @@ export class OrganizationDetailsComponent extends BaseComponent implements OnIni
super();
}

public allowedUpdatePermissions: boolean = false;

ngOnInit(): void {
if (this.authToken) {
this.otpService
Expand All @@ -57,6 +60,8 @@ export class OrganizationDetailsComponent extends BaseComponent implements OnIni
.subscribe({
next: (res) => {
const company = res?.data?.[0]?.currentCompany;
this.allowedUpdatePermissions =
res?.data?.[0]?.currentCompany?.permissions?.includes('update_c_company');
if (company && typeof company === 'object') {
const timeZoneName =
company.timeZoneName ??
Expand Down Expand Up @@ -179,15 +184,29 @@ export class OrganizationDetailsComponent extends BaseComponent implements OnIni
// verticalPosition: 'top',
// panelClass: ['success-snackbar'],
// });
window.dispatchEvent(
new CustomEvent('organizationDetailsUpdateResponse', {
bubbles: true,
composed: true,
detail: { data: res?.data, error: false },
})
);
},
error: () => {
error: (error) => {
// Stay in edit mode so user can retry
// this.snackBar.open('Something went wrong', '✕', {
// duration: 3000,
// horizontalPosition: 'center',
// verticalPosition: 'top',
// panelClass: ['error-snackbar'],
// });
window.dispatchEvent(
new CustomEvent('organizationDetailsUpdateResponse', {
bubbles: true,
composed: true,
detail: { data: error?.error?.errors ?? error?.error ?? error, error: true },
})
);
},
});
}
Expand Down
Loading