From e59c3a14af20347de9fe3584282875161e006671 Mon Sep 17 00:00:00 2001 From: Jaanu423 Date: Tue, 23 Jun 2026 10:40:00 +0530 Subject: [PATCH] feat(create-client): auto-link family member after client creation - After creating a client from 'Create as Client' button, automatically call PUT /clients/{parentId}/familymembers/{memberId} with the new linkedClientId to link the family member record - Show snackbar feedback on success or failure of the auto-link - nomination-apply now also passes familyMemberId and parentClientId in prefill state so auto-link works from the nomination page too Co-Authored-By: Claude Sonnet 4.6 --- .../create-client/create-client.component.ts | 30 ++++++++++++++++++- .../nomination-apply.component.ts | 4 ++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/app/clients/create-client/create-client.component.ts b/src/app/clients/create-client/create-client.component.ts index 152b51804..3b58d01bd 100644 --- a/src/app/clients/create-client/create-client.component.ts +++ b/src/app/clients/create-client/create-client.component.ts @@ -35,6 +35,7 @@ import { FaIconComponent } from '@fortawesome/angular-fontawesome'; import { MatProgressSpinner } from '@angular/material/progress-spinner'; import { MatProgressBarModule } from '@angular/material/progress-bar'; import { MatDialog, MAT_DIALOG_DATA, MatDialogClose } from '@angular/material/dialog'; +import { MatSnackBar } from '@angular/material/snack-bar'; import { MatTooltip } from '@angular/material/tooltip'; import { Inject } from '@angular/core'; import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module'; @@ -71,6 +72,7 @@ export class CreateClientComponent { private clientsService = inject(ClientsService); private settingsService = inject(SettingsService); private dialog = inject(MatDialog); + private snackBar = inject(MatSnackBar); @ViewChild(ClientGeneralStepComponent) clientGeneralStep: ClientGeneralStepComponent; @ViewChild('clientAddress') clientAddressStep: ClientAddressStepComponent; @@ -520,7 +522,7 @@ export class CreateClientComponent { * Finalize: upload photo/signature, save KYC, save addresses, then navigate. */ private finalizeClient(clientId: string) { - const navigateToClient = () => + const doNavigate = () => this.router.navigate( [ '../', @@ -529,6 +531,32 @@ export class CreateClientComponent { { relativeTo: this.route } ); + const navigateToClient = () => { + const fm = this.prefillData; + if (fm?.familyMemberId && fm?.parentClientId) { + this.clientsService + .editFamilyMember(fm.parentClientId.toString(), fm.familyMemberId.toString(), { + linkedClientId: Number(clientId) + }) + .subscribe({ + next: () => { + this.snackBar.open('Family member linked to this client successfully.', 'Close', { duration: 4000 }); + doNavigate(); + }, + error: () => { + this.snackBar.open( + 'Client created, but family member could not be auto-linked. Please link manually.', + 'Close', + { duration: 6000 } + ); + doNavigate(); + } + }); + } else { + doNavigate(); + } + }; + // Upload photo if selected if (this.clientKycStep?.photographFile) { this.clientsService diff --git a/src/app/election/components/nomination-apply/nomination-apply.component.ts b/src/app/election/components/nomination-apply/nomination-apply.component.ts index 550fc2df5..99e5f9034 100644 --- a/src/app/election/components/nomination-apply/nomination-apply.component.ts +++ b/src/app/election/components/nomination-apply/nomination-apply.component.ts @@ -135,7 +135,9 @@ export class NominationApplyComponent implements OnInit { mobileNo: member.mobileNumber || '', dateOfBirth: member.dateOfBirth || null, panNumber: member.panNumber || '', - aadhaarNumber: member.aadhaarNumber || '' + aadhaarNumber: member.aadhaarNumber || '', + familyMemberId: member.id, + parentClientId: this.selectedMemberId }; this.router.navigate( [