Skip to content

Commit

Permalink
Applied changes in client edit compoonent
Browse files Browse the repository at this point in the history
  • Loading branch information
amahdysancsoft committed May 15, 2024
1 parent 3214d72 commit b8c34de
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 45 deletions.
63 changes: 25 additions & 38 deletions src/angular/hq/src/app/clients/client-edit/client-edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ interface Form {
templateUrl: './client-edit.component.html'
})

export class ClientEditComponent implements OnInit{
export class ClientEditComponent implements OnInit {
clientId?: string;
ngOnInit() {
this.route.paramMap.subscribe(params => {
this.clientId = params.get('clientId') ?? undefined
console.log(this.clientId)
this.getClient();
})

constructor(private hqService: HQService, private router: Router, private route: ActivatedRoute) { }

async ngOnInit() {
this.clientId = await (await firstValueFrom(this.route.paramMap.pipe())).get('clientId') ?? undefined
this.getClient();
}
apiErrors?: string[];

Expand All @@ -52,59 +52,46 @@ export class ClientEditComponent implements OnInit{
}),
});

constructor(private hqService: HQService, private router: Router, private route: ActivatedRoute) {
// this.clientId = route.snapshot.params['clientId']
// console.log(this.clientId);
// this.form.get('name') ?.setValue("Test 2");

}

private async getClient() {
try
{
const request = {"id": this.clientId}
const response = await firstValueFrom(this.hqService.getClientV1(request));
try {
const request = { "id": this.clientId }
const response = await firstValueFrom(this.hqService.getClientsV1(request));
const client = response.records[0]
this.form.get('name') ?.setValue(client.name);
this.form.get('officialName') ?.setValue(client.officialName ?? null);
this.form.get('billingEmail') ?.setValue(client.billingEmail ?? null);
this.form.get('hourlyRate') ?.setValue(client.hourlyRate ?? null);

this.form.setValue({
name: client.name,
officialName: client.officialName ?? null,
billingEmail: client.billingEmail ?? null,
hourlyRate: client.hourlyRate ?? null
})
}
catch(err)
{
if(err instanceof APIError)
{
catch (err) {
if (err instanceof APIError) {
this.apiErrors = err.errors;
}
else
{
else {
this.apiErrors = ['An unexpected error has occurred.'];
}
}
}

async submit() {
this.form.markAsTouched();
if(this.form.invalid) {
if (this.form.invalid) {
return;
}

try
{
var request = {id: this.clientId, ... this.form.value}
try {
var request = { id: this.clientId, ... this.form.value }
const response = await firstValueFrom(this.hqService.upsertClientV1(request));
this.router.navigate(['../', response.id], { relativeTo: this.route });
}
catch(err)
{
catch (err) {
console.log(err);
if(err instanceof APIError)
{
if (err instanceof APIError) {
this.apiErrors = err.errors;
}
else
{
else {
this.apiErrors = ['An unexpected error has occurred.'];
}
}
Expand Down
8 changes: 1 addition & 7 deletions src/angular/hq/src/app/services/hq.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@ export class HQService {

constructor(private http: HttpClient, private appSettings: AppSettingsService) { }

getClientsV1(request: GetClientRequestV1) {
return this.appSettings.apiUrl$.pipe(
switchMap(apiUrl => this.http.post<GetClientResponseV1>(`${apiUrl}/v1/Clients/GetClientsV1`, request))
);
}

getClientV1(request: Partial<GetClientRequestV1>) {
getClientsV1(request: Partial<GetClientRequestV1>) {
return this.appSettings.apiUrl$.pipe(
switchMap(apiUrl => this.http.post<GetClientResponseV1>(`${apiUrl}/v1/Clients/GetClientsV1`, request))
);
Expand Down

0 comments on commit b8c34de

Please sign in to comment.