manage preparer api integration updates
This commit is contained in:
parent
0b2d45e16d
commit
38021b8979
4
src/app/core/models/preparer/contact-login.ts
Normal file
4
src/app/core/models/preparer/contact-login.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export interface ContactLogin {
|
||||||
|
clientContactId: number;
|
||||||
|
password: string;
|
||||||
|
}
|
||||||
@ -15,6 +15,7 @@ export interface Contact {
|
|||||||
createdBy?: string | null;
|
createdBy?: string | null;
|
||||||
lastUpdatedBy?: string | null;
|
lastUpdatedBy?: string | null;
|
||||||
lastUpdatedDate?: Date | null;
|
lastUpdatedDate?: Date | null;
|
||||||
isInactive?: boolean | null; // TODO
|
isInactive?: boolean | null;
|
||||||
inactivatedDate?: Date | null; // TODO
|
inactivatedDate?: Date | null;
|
||||||
|
hasLogin?: boolean; // Indicates if the contact has a login
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,6 @@ export interface Location {
|
|||||||
createdBy?: string | null;
|
createdBy?: string | null;
|
||||||
lastUpdatedBy?: string | null;
|
lastUpdatedBy?: string | null;
|
||||||
lastUpdatedDate?: Date | null;
|
lastUpdatedDate?: Date | null;
|
||||||
isInactive?: boolean | null; // TODO
|
isInactive?: boolean | null;
|
||||||
inactivatedDate?: Date | null; // TODO
|
inactivatedDate?: Date | null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import { HttpClient } from '@angular/common/http';
|
|||||||
import { environment } from '../../../../environments/environment';
|
import { environment } from '../../../../environments/environment';
|
||||||
import { map, Observable, of } from 'rxjs';
|
import { map, Observable, of } from 'rxjs';
|
||||||
import { Contact } from '../../models/preparer/contact';
|
import { Contact } from '../../models/preparer/contact';
|
||||||
|
import { ContactLogin } from '../../models/preparer/contact-login';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
@ -38,7 +39,8 @@ export class ContactService {
|
|||||||
lastUpdatedBy: contact.LASTUPDATEDBY || null,
|
lastUpdatedBy: contact.LASTUPDATEDBY || null,
|
||||||
lastUpdatedDate: contact.LASTUPDATEDDATE || null,
|
lastUpdatedDate: contact.LASTUPDATEDDATE || null,
|
||||||
isInactive: contact.INACTIVEFLAG === 'Y' || false,
|
isInactive: contact.INACTIVEFLAG === 'Y' || false,
|
||||||
inactivatedDate: contact.INACTIVEDATE || null
|
inactivatedDate: contact.INACTIVEDATE || null,
|
||||||
|
hasLogin: contact.LOGINFLAG === 'Y' || false
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +83,23 @@ export class ContactService {
|
|||||||
return this.http.put(`${this.apiUrl}/${this.apiDb}/UpdateClientContacts`, contact);
|
return this.http.put(`${this.apiUrl}/${this.apiDb}/UpdateClientContacts`, contact);
|
||||||
}
|
}
|
||||||
|
|
||||||
// deleteContact(clientContactId: string): Observable<any> {
|
createContactLogin(data: ContactLogin): Observable<any> {
|
||||||
// return this.http.post(`${this.apiUrl}/${this.apiDb}/InactivateSPContact?p_clientcontactid=${clientContactId}`, null);
|
const contact = {
|
||||||
// }
|
P_SPID: this.userService.getUserSpid(),
|
||||||
|
P_CLIENTCONTACTID: data.clientContactId,
|
||||||
|
P_ENABLEPASSWORDPOLICY: 'Y',
|
||||||
|
P_PASSWORD: data.password,
|
||||||
|
P_USERID: this.userService.getUser()
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.http.post(`${this.apiUrl}/${this.apiDb}/CreateClientLogins`, contact);
|
||||||
|
}
|
||||||
|
|
||||||
|
inactivateContact(clientContactId: string): Observable<any> {
|
||||||
|
return this.http.patch(`${this.apiUrl}/${this.apiDb}/InactivateClientContacts/${this.userService.getUserSpid()}/${clientContactId}/${this.userService.getUser()}`, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
reactivateContact(clientContactId: string): Observable<any> {
|
||||||
|
return this.http.patch(`${this.apiUrl}/${this.apiDb}/ReactivateClientContacts/${this.userService.getUserSpid()}/${clientContactId}/${this.userService.getUser()}`, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -75,8 +75,4 @@ export class LocationService {
|
|||||||
|
|
||||||
return this.http.put(`${this.apiUrl}/${this.apiDb}/UpdateClientLocations`, location);
|
return this.http.put(`${this.apiUrl}/${this.apiDb}/UpdateClientLocations`, location);
|
||||||
}
|
}
|
||||||
|
|
||||||
// deleteLocation(clientContactId: string): Observable<any> {
|
|
||||||
// return this.http.post(`${this.apiUrl}/${this.apiDb}/InactivateSPContact?p_clientcontactid=${clientContactId}`, null);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,8 @@
|
|||||||
<mat-step [completed]="basicDetailsCompleted">
|
<mat-step [completed]="basicDetailsCompleted">
|
||||||
<ng-template matStepLabel>Basic Details</ng-template>
|
<ng-template matStepLabel>Basic Details</ng-template>
|
||||||
|
|
||||||
<app-basic-details [isEditMode]="isEditMode" (clientidCreated)="onBasicDetailsSaved($event)">
|
<app-basic-details [isEditMode]="isEditMode" (clientidCreated)="onBasicDetailsSaved($event)"
|
||||||
|
(showLocations)="onShowLocations($event)">
|
||||||
</app-basic-details>
|
</app-basic-details>
|
||||||
</mat-step>
|
</mat-step>
|
||||||
|
|
||||||
@ -20,7 +21,7 @@
|
|||||||
</mat-step>
|
</mat-step>
|
||||||
|
|
||||||
<!-- Location Step -->
|
<!-- Location Step -->
|
||||||
<mat-step [completed]="locationCompleted" [editable]="!!clientid && contactsCompleted">
|
<mat-step [completed]="locationCompleted" [editable]="!!clientid && contactsCompleted" *ngIf="showLocation">
|
||||||
<ng-template matStepLabel>Locations</ng-template>
|
<ng-template matStepLabel>Locations</ng-template>
|
||||||
|
|
||||||
<app-location *ngIf="clientid" [clientid]="clientid" (hasLocations)="onLocationSaved($event)"
|
<app-location *ngIf="clientid" [clientid]="clientid" (hasLocations)="onLocationSaved($event)"
|
||||||
|
|||||||
@ -24,6 +24,7 @@ export class AddPreparerComponent {
|
|||||||
basicDetailsCompleted: boolean = false;
|
basicDetailsCompleted: boolean = false;
|
||||||
contactsCompleted: boolean = false;
|
contactsCompleted: boolean = false;
|
||||||
locationCompleted: boolean = false;
|
locationCompleted: boolean = false;
|
||||||
|
showLocation: boolean = false;
|
||||||
|
|
||||||
constructor(userPrefenceService: UserPreferencesService) {
|
constructor(userPrefenceService: UserPreferencesService) {
|
||||||
this.userPreferences = userPrefenceService.getPreferences();
|
this.userPreferences = userPrefenceService.getPreferences();
|
||||||
@ -42,6 +43,10 @@ export class AddPreparerComponent {
|
|||||||
this.locationCompleted = event;
|
this.locationCompleted = event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onShowLocations(event: boolean): void {
|
||||||
|
this.showLocation = event;
|
||||||
|
}
|
||||||
|
|
||||||
onStepChange(event: StepperSelectionEvent): void {
|
onStepChange(event: StepperSelectionEvent): void {
|
||||||
this.currentStep = event.selectedIndex;
|
this.currentStep = event.selectedIndex;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -138,6 +138,14 @@
|
|||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Additional Locations -->
|
||||||
|
<div class="form-row" *ngIf="!isEditMode">
|
||||||
|
<mat-checkbox formControlName="hasAdditionalLocations"
|
||||||
|
(change)="onHasAdditionalLocationsChange($event)">
|
||||||
|
Do you have more branch offices?
|
||||||
|
</mat-checkbox>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<button mat-raised-button color="primary" type="submit" [disabled]="basicDetailsForm.invalid">
|
<button mat-raised-button color="primary" type="submit" [disabled]="basicDetailsForm.invalid">
|
||||||
Save
|
Save
|
||||||
|
|||||||
@ -12,6 +12,8 @@ import { ApiErrorHandlerService } from '../../core/services/common/api-error-han
|
|||||||
import { BasicDetailService } from '../../core/services/preparer/basic-detail.service';
|
import { BasicDetailService } from '../../core/services/preparer/basic-detail.service';
|
||||||
import { BasicDetail } from '../../core/models/preparer/basic-detail';
|
import { BasicDetail } from '../../core/models/preparer/basic-detail';
|
||||||
import { ZipCodeValidator } from '../../shared/validators/zipcode-validator';
|
import { ZipCodeValidator } from '../../shared/validators/zipcode-validator';
|
||||||
|
import { LocationService } from '../../core/services/preparer/location.service';
|
||||||
|
import { Location } from '../../core/models/preparer/location';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-basic-details',
|
selector: 'app-basic-details',
|
||||||
@ -24,6 +26,7 @@ export class BasicDetailsComponent implements OnInit, OnDestroy {
|
|||||||
@Input() clientid: number = 0;
|
@Input() clientid: number = 0;
|
||||||
@Output() clientidCreated = new EventEmitter<string>();
|
@Output() clientidCreated = new EventEmitter<string>();
|
||||||
@Output() clientName = new EventEmitter<string>();
|
@Output() clientName = new EventEmitter<string>();
|
||||||
|
@Output() showLocations = new EventEmitter<boolean>();
|
||||||
|
|
||||||
basicDetailsForm: FormGroup;
|
basicDetailsForm: FormGroup;
|
||||||
countries: Country[] = [];
|
countries: Country[] = [];
|
||||||
@ -39,6 +42,7 @@ export class BasicDetailsComponent implements OnInit, OnDestroy {
|
|||||||
private fb: FormBuilder,
|
private fb: FormBuilder,
|
||||||
private commonService: CommonService,
|
private commonService: CommonService,
|
||||||
private basicDetailService: BasicDetailService,
|
private basicDetailService: BasicDetailService,
|
||||||
|
private locationService: LocationService,
|
||||||
private notificationService: NotificationService,
|
private notificationService: NotificationService,
|
||||||
private errorHandler: ApiErrorHandlerService) {
|
private errorHandler: ApiErrorHandlerService) {
|
||||||
this.basicDetailsForm = this.createForm();
|
this.basicDetailsForm = this.createForm();
|
||||||
@ -83,7 +87,8 @@ export class BasicDetailsComponent implements OnInit, OnDestroy {
|
|||||||
country: ['', Validators.required],
|
country: ['', Validators.required],
|
||||||
zip: ['', [Validators.required, ZipCodeValidator('country')]],
|
zip: ['', [Validators.required, ZipCodeValidator('country')]],
|
||||||
carnetIssuingRegion: ['', Validators.required],
|
carnetIssuingRegion: ['', Validators.required],
|
||||||
revenueLocation: ['', Validators.required]
|
revenueLocation: ['', Validators.required],
|
||||||
|
hasAdditionalLocations: [false]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,11 +172,13 @@ export class BasicDetailsComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
if (this.isEditMode) {
|
if (this.isEditMode) {
|
||||||
this.basicDetailsForm.get('carnetIssuingRegion')?.disable();
|
this.basicDetailsForm.get('carnetIssuingRegion')?.disable();
|
||||||
|
this.basicDetailsForm.get('lookupCode')?.disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onCountryChange(country: string): void {
|
onCountryChange(country: string): void {
|
||||||
this.basicDetailsForm.get('state')?.reset();
|
this.basicDetailsForm.get('state')?.reset();
|
||||||
|
this.basicDetailsForm.get('revenueLocation')?.reset();
|
||||||
|
|
||||||
if (country) {
|
if (country) {
|
||||||
this.loadStates(country);
|
this.loadStates(country);
|
||||||
@ -180,6 +187,11 @@ export class BasicDetailsComponent implements OnInit, OnDestroy {
|
|||||||
this.basicDetailsForm.get('zip')?.updateValueAndValidity();
|
this.basicDetailsForm.get('zip')?.updateValueAndValidity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onHasAdditionalLocationsChange(event: any): void {
|
||||||
|
const hasAdditionalLocations = event.checked;
|
||||||
|
this.showLocations.emit(hasAdditionalLocations);
|
||||||
|
}
|
||||||
|
|
||||||
saveBasicDetails(): void {
|
saveBasicDetails(): void {
|
||||||
if (this.basicDetailsForm.invalid) {
|
if (this.basicDetailsForm.invalid) {
|
||||||
this.basicDetailsForm.markAllAsTouched();
|
this.basicDetailsForm.markAllAsTouched();
|
||||||
@ -195,6 +207,7 @@ export class BasicDetailsComponent implements OnInit, OnDestroy {
|
|||||||
// non editable fields values
|
// non editable fields values
|
||||||
if (this.isEditMode) {
|
if (this.isEditMode) {
|
||||||
basicDetailData.carnetIssuingRegion = this.basicDetailsForm.get('carnetIssuingRegion')?.value;
|
basicDetailData.carnetIssuingRegion = this.basicDetailsForm.get('carnetIssuingRegion')?.value;
|
||||||
|
basicDetailData.lookupCode = this.basicDetailsForm.get('lookupCode')?.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
const saveObservable = this.isEditMode && this.clientid > 0
|
const saveObservable = this.isEditMode && this.clientid > 0
|
||||||
@ -206,10 +219,11 @@ export class BasicDetailsComponent implements OnInit, OnDestroy {
|
|||||||
this.notificationService.showSuccess(`Basic details ${this.isEditMode ? 'updated' : 'added'} successfully`);
|
this.notificationService.showSuccess(`Basic details ${this.isEditMode ? 'updated' : 'added'} successfully`);
|
||||||
|
|
||||||
if (!this.isEditMode) {
|
if (!this.isEditMode) {
|
||||||
this.clientidCreated.emit(basicData.clientId);
|
this.clientidCreated.emit(basicData.CLIENTID);
|
||||||
|
this.saveLocation(basicData.CLIENTID, basicDetailData);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( this.isEditMode) {
|
if (this.isEditMode) {
|
||||||
this.clientName.emit(basicDetailData.name);
|
this.clientName.emit(basicDetailData.name);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -221,6 +235,31 @@ export class BasicDetailsComponent implements OnInit, OnDestroy {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
saveLocation(clientid: number, basicDetail: BasicDetail): void {
|
||||||
|
const locationData: Location = {
|
||||||
|
clientid: clientid,
|
||||||
|
name: basicDetail.name,
|
||||||
|
address1: basicDetail.address1,
|
||||||
|
address2: basicDetail.address2,
|
||||||
|
city: basicDetail.city,
|
||||||
|
country: basicDetail.country,
|
||||||
|
state: basicDetail.state,
|
||||||
|
zip: basicDetail.zip,
|
||||||
|
locationid: 0, // Default to 0 for new location
|
||||||
|
}
|
||||||
|
|
||||||
|
this.locationService.createLocation(clientid, locationData).subscribe({
|
||||||
|
next: () => {
|
||||||
|
//this.notificationService.showSuccess('Location added successfully');
|
||||||
|
},
|
||||||
|
error: (error) => {
|
||||||
|
let errorMessage = this.errorHandler.handleApiError(error, 'Failed to add location');
|
||||||
|
this.notificationService.showError(errorMessage);
|
||||||
|
console.error('Error saving location:', error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Convenience getter for easy access to form fields
|
// Convenience getter for easy access to form fields
|
||||||
get f() {
|
get f() {
|
||||||
return this.basicDetailsForm.controls;
|
return this.basicDetailsForm.controls;
|
||||||
|
|||||||
@ -68,17 +68,19 @@
|
|||||||
<button mat-icon-button color="primary" (click)="editContact(contact)" matTooltip="Edit">
|
<button mat-icon-button color="primary" (click)="editContact(contact)" matTooltip="Edit">
|
||||||
<mat-icon>edit</mat-icon>
|
<mat-icon>edit</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<button mat-icon-button color="primary" (click)="createLogin()" matTooltip="Login">
|
<button mat-icon-button color="primary" *ngIf="!contact.isInactive || !contact.hasLogin"
|
||||||
|
[hidden]="contact.isInactive || contact.hasLogin" (click)="createLogin(contact)"
|
||||||
|
matTooltip="Login">
|
||||||
<mat-icon>person</mat-icon>
|
<mat-icon>person</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<button mat-icon-button color="warn" *ngIf="!contact.defaultContact || !contact.isInactive" (click)="
|
<button mat-icon-button color="warn" *ngIf="!contact.defaultContact || !contact.isInactive" (click)="
|
||||||
deleteContact(contact.clientContactid)" [hidden]="contact.defaultContact || contact.isInactive"
|
inactivateContact(contact.clientContactId)"
|
||||||
matTooltip="Inactivate">
|
[hidden]="contact.defaultContact || contact.isInactive" matTooltip="Inactivate">
|
||||||
<mat-icon>delete</mat-icon>
|
<mat-icon>delete</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<button mat-icon-button color="warn" *ngIf="!contact.isInactive" (click)="
|
<button mat-icon-button color="warn" *ngIf="contact.isInactive" (click)="
|
||||||
deleteContact(contact.clientContactid)" [hidden]="contact.isInactive" matTooltip="Inactivate">
|
reactivateContact(contact.clientContactId)" [hidden]="!contact.isInactive" matTooltip="Reactivate">
|
||||||
<mat-icon>delete</mat-icon>
|
<mat-icon>how_to_reg</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<!-- <button mat-icon-button (click)="setDefaultContact(contact.contactId)"
|
<!-- <button mat-icon-button (click)="setDefaultContact(contact.contactId)"
|
||||||
[color]="contact.defaultContact ? 'primary' : ''" matTooltip="Set as default">
|
[color]="contact.defaultContact ? 'primary' : ''" matTooltip="Set as default">
|
||||||
@ -213,7 +215,7 @@
|
|||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<mat-checkbox formControlName="defaultContact">Default Contact</mat-checkbox>
|
<mat-checkbox formControlName="defaultContact">Default Contact</mat-checkbox>
|
||||||
</div> -->
|
</div> -->
|
||||||
<div *ngIf="isEditing" class="readonly-section">
|
<div *ngIf="isEditing" class="readonly-section top-divider">
|
||||||
<div class="readonly-fields">
|
<div class="readonly-fields">
|
||||||
<div class="field-column">
|
<div class="field-column">
|
||||||
<!-- Last Changed By -->
|
<!-- Last Changed By -->
|
||||||
@ -260,4 +262,45 @@
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Contact Login Form -->
|
||||||
|
<div class="form-container" *ngIf="showLoginForm">
|
||||||
|
<form [formGroup]="contactLoginForm" (ngSubmit)="saveLogin()">
|
||||||
|
<div class="form-header">
|
||||||
|
<h3>Create Login</h3>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div *ngIf="isEditing" class="readonly-section bottom-divider">
|
||||||
|
<div class="readonly-fields">
|
||||||
|
<div class="field-column">
|
||||||
|
<!-- Email -->
|
||||||
|
<div class="readonly-field">
|
||||||
|
<label>Email</label>
|
||||||
|
<div class="readonly-value">
|
||||||
|
{{contactLoginReadOnlyFields.email}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-row">
|
||||||
|
<mat-form-field appearance="outline">
|
||||||
|
<mat-label>Password</mat-label>
|
||||||
|
<input matInput formControlName="password" required>
|
||||||
|
<mat-icon matSuffix>lock</mat-icon>
|
||||||
|
<mat-error *ngIf="contactLoginForm.get('password')?.errors?.['required']">
|
||||||
|
Password is required
|
||||||
|
</mat-error>
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-actions">
|
||||||
|
<button mat-button type="button" (click)="cancelEdit()">Cancel</button>
|
||||||
|
<button mat-raised-button color="primary" type="submit" [disabled]="contactLoginForm.invalid">
|
||||||
|
Save
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -120,9 +120,17 @@
|
|||||||
margin-top: 16px;
|
margin-top: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.readonly-section {
|
.top-divider {
|
||||||
padding-top: 0.5rem;
|
padding-top: 0.5rem;
|
||||||
border-top: 1px solid #eee;
|
border-top: 1px solid #eee;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bottom-divider {
|
||||||
|
padding-bottom: 0.5rem;
|
||||||
|
border-bottom: 1px solid #eee;
|
||||||
|
}
|
||||||
|
|
||||||
|
.readonly-section {
|
||||||
|
|
||||||
.readonly-fields {
|
.readonly-fields {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import { MatDialog } from '@angular/material/dialog';
|
|||||||
import { ApiErrorHandlerService } from '../../core/services/common/api-error-handler.service';
|
import { ApiErrorHandlerService } from '../../core/services/common/api-error-handler.service';
|
||||||
import { Contact } from '../../core/models/preparer/contact';
|
import { Contact } from '../../core/models/preparer/contact';
|
||||||
import { ConfirmDialogComponent } from '../../shared/components/confirm-dialog/confirm-dialog.component';
|
import { ConfirmDialogComponent } from '../../shared/components/confirm-dialog/confirm-dialog.component';
|
||||||
|
import { ContactLogin } from '../../core/models/preparer/contact-login';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-contacts',
|
selector: 'app-contacts',
|
||||||
@ -29,10 +30,12 @@ export class ContactsComponent {
|
|||||||
displayedColumns: string[] = ['firstName', 'lastName', 'title', 'phone', 'mobile', 'email', 'defaultContact', 'actions'];
|
displayedColumns: string[] = ['firstName', 'lastName', 'title', 'phone', 'mobile', 'email', 'defaultContact', 'actions'];
|
||||||
dataSource = new MatTableDataSource<any>();
|
dataSource = new MatTableDataSource<any>();
|
||||||
contactForm: FormGroup;
|
contactForm: FormGroup;
|
||||||
|
contactLoginForm: FormGroup;
|
||||||
isEditing = false;
|
isEditing = false;
|
||||||
currentContactId: number | null = null;
|
currentContactId: number | null = null;
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
showForm = false;
|
showForm = false;
|
||||||
|
showLoginForm = false
|
||||||
showInactiveContacts = false;
|
showInactiveContacts = false;
|
||||||
contacts: Contact[] = [];
|
contacts: Contact[] = [];
|
||||||
contactReadOnlyFields: any = {
|
contactReadOnlyFields: any = {
|
||||||
@ -42,6 +45,10 @@ export class ContactsComponent {
|
|||||||
inactivatedDate: null
|
inactivatedDate: null
|
||||||
};
|
};
|
||||||
|
|
||||||
|
contactLoginReadOnlyFields: any = {
|
||||||
|
email: null
|
||||||
|
};
|
||||||
|
|
||||||
@Input() clientid: number = 0;
|
@Input() clientid: number = 0;
|
||||||
@Input() userPreferences: UserPreferences = {};
|
@Input() userPreferences: UserPreferences = {};
|
||||||
@Output() hasContacts = new EventEmitter<boolean>();
|
@Output() hasContacts = new EventEmitter<boolean>();
|
||||||
@ -64,6 +71,10 @@ export class ContactsComponent {
|
|||||||
email: ['', [Validators.required, Validators.email, Validators.maxLength(100)]],
|
email: ['', [Validators.required, Validators.email, Validators.maxLength(100)]],
|
||||||
defaultContact: [false]
|
defaultContact: [false]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.contactLoginForm = this.fb.group({
|
||||||
|
password: ['', [Validators.required]]
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
@ -95,6 +106,7 @@ export class ContactsComponent {
|
|||||||
|
|
||||||
addNewContact(): void {
|
addNewContact(): void {
|
||||||
this.showForm = true;
|
this.showForm = true;
|
||||||
|
this.showLoginForm = false;
|
||||||
this.isEditing = false;
|
this.isEditing = false;
|
||||||
this.currentContactId = null;
|
this.currentContactId = null;
|
||||||
this.contactForm.reset();
|
this.contactForm.reset();
|
||||||
@ -103,6 +115,7 @@ export class ContactsComponent {
|
|||||||
|
|
||||||
editContact(contact: Contact): void {
|
editContact(contact: Contact): void {
|
||||||
this.showForm = true;
|
this.showForm = true;
|
||||||
|
this.showLoginForm = false;
|
||||||
this.isEditing = true;
|
this.isEditing = true;
|
||||||
this.currentContactId = contact.clientContactId;
|
this.currentContactId = contact.clientContactId;
|
||||||
this.contactForm.patchValue({
|
this.contactForm.patchValue({
|
||||||
@ -165,42 +178,103 @@ export class ContactsComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteContact(contactId: string): void {
|
inactivateContact(contactId: string): void {
|
||||||
// const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
||||||
// width: '350px',
|
width: '350px',
|
||||||
// data: {
|
data: {
|
||||||
// title: 'Confirm Delete',
|
title: 'Confirm Inactivation',
|
||||||
// message: 'Are you sure you want to delete this contact?',
|
message: 'Are you sure you want to inactivate this contact?',
|
||||||
// confirmText: 'Delete',
|
confirmText: 'Yes',
|
||||||
// cancelText: 'Cancel'
|
cancelText: 'Cancel'
|
||||||
// }
|
}
|
||||||
// });
|
});
|
||||||
|
|
||||||
// dialogRef.afterClosed().subscribe(result => {
|
dialogRef.afterClosed().subscribe(result => {
|
||||||
// if (result) {
|
if (result) {
|
||||||
// this.contactService.deleteContact(contactId).subscribe({
|
this.contactService.inactivateContact(contactId).subscribe({
|
||||||
// next: () => {
|
next: () => {
|
||||||
// this.notificationService.showSuccess('Contact deleted successfully');
|
this.notificationService.showSuccess('Contact inactivated successfully');
|
||||||
// this.loadContacts();
|
this.loadContacts();
|
||||||
// },
|
},
|
||||||
// error: (error) => {
|
error: (error) => {
|
||||||
// let errorMessage = this.errorHandler.handleApiError(error, 'Failed to delete contact');
|
let errorMessage = this.errorHandler.handleApiError(error, 'Failed to inactivate contact');
|
||||||
// this.notificationService.showError(errorMessage);
|
this.notificationService.showError(errorMessage);
|
||||||
// console.error('Error deleting contact:', error);
|
console.error('Error inactivating contact:', error);
|
||||||
// }
|
}
|
||||||
// });
|
});
|
||||||
// }
|
}
|
||||||
// });
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
createLogin(): void {
|
reactivateContact(contactId: string): void {
|
||||||
|
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
||||||
|
width: '350px',
|
||||||
|
data: {
|
||||||
|
title: 'Confirm Reactivation',
|
||||||
|
message: 'Are you sure you want to reactivate this contact?',
|
||||||
|
confirmText: 'Yes',
|
||||||
|
cancelText: 'Cancel'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
dialogRef.afterClosed().subscribe(result => {
|
||||||
|
if (result) {
|
||||||
|
this.contactService.reactivateContact(contactId).subscribe({
|
||||||
|
next: () => {
|
||||||
|
this.notificationService.showSuccess('Contact reactivated successfully');
|
||||||
|
this.loadContacts();
|
||||||
|
},
|
||||||
|
error: (error) => {
|
||||||
|
let errorMessage = this.errorHandler.handleApiError(error, 'Failed to reactivate contact');
|
||||||
|
this.notificationService.showError(errorMessage);
|
||||||
|
console.error('Error reactivating contact:', error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
createLogin(contact: Contact): void {
|
||||||
|
this.showForm = false;
|
||||||
|
this.showLoginForm = true;
|
||||||
|
this.isEditing = true;
|
||||||
|
this.currentContactId = contact.clientContactId;
|
||||||
|
|
||||||
|
this.contactLoginReadOnlyFields.email = contact.email;
|
||||||
|
}
|
||||||
|
|
||||||
|
saveLogin(): void {
|
||||||
|
if (this.contactLoginForm.invalid) {
|
||||||
|
this.contactLoginForm.markAllAsTouched();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const contactLoginData: ContactLogin = {
|
||||||
|
clientContactId: this.currentContactId!,
|
||||||
|
password: this.contactLoginForm.value.password
|
||||||
|
};
|
||||||
|
|
||||||
|
this.contactService.createContactLogin(contactLoginData).subscribe({
|
||||||
|
next: () => {
|
||||||
|
this.notificationService.showSuccess(`Login created successfully`);
|
||||||
|
this.loadContacts();
|
||||||
|
this.cancelEdit();
|
||||||
|
},
|
||||||
|
error: (error) => {
|
||||||
|
let errorMessage = this.errorHandler.handleApiError(error, `Failed to create login`);
|
||||||
|
this.notificationService.showError(errorMessage);
|
||||||
|
console.error('Error saving login:', error);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
cancelEdit(): void {
|
cancelEdit(): void {
|
||||||
this.showForm = false;
|
this.showForm = false;
|
||||||
|
this.showLoginForm = false;
|
||||||
this.isEditing = false;
|
this.isEditing = false;
|
||||||
this.currentContactId = null;
|
this.currentContactId = null;
|
||||||
this.contactForm.reset();
|
this.contactForm.reset();
|
||||||
|
this.contactLoginForm.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
// setDefaultContact(contactId: string): void {
|
// setDefaultContact(contactId: string): void {
|
||||||
|
|||||||
@ -72,7 +72,7 @@
|
|||||||
<!-- Address Column -->
|
<!-- Address Column -->
|
||||||
<ng-container matColumnDef="address">
|
<ng-container matColumnDef="address">
|
||||||
<th mat-header-cell *matHeaderCellDef mat-sort-header>Address</th>
|
<th mat-header-cell *matHeaderCellDef mat-sort-header>Address</th>
|
||||||
<td mat-cell *matCellDef="let client">{{ getAddressLabel(client.address1, client.address2, client.zip)}}
|
<td mat-cell *matCellDef="let client">{{ getAddressLabel(client.address1, client.address2)}}
|
||||||
</td>
|
</td>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
|
|||||||
@ -162,14 +162,11 @@ export class ManagePreparerComponent implements OnInit, OnDestroy, AfterViewInit
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getAddressLabel(address1: string, address2?: string, zip?: string): string {
|
getAddressLabel(address1: string, address2?: string): string {
|
||||||
let addressLabel = address1;
|
let addressLabel = address1;
|
||||||
if (address2) {
|
if (address2) {
|
||||||
addressLabel += `, ${address2}`;
|
addressLabel += `, ${address2}`;
|
||||||
}
|
}
|
||||||
if (zip) {
|
|
||||||
addressLabel += `, ${zip}`;
|
|
||||||
}
|
|
||||||
return addressLabel;
|
return addressLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user