Client-stepper: pre-fill existing KYC/address proofs in edit, fix identifier saves

Edit-mode now shows the previously selected KYC document type + uploaded file thumbnail
(loads from /clients/{id}/identifiers + /client_identifiers/{id}/documents). Same for
address proof on the India address step. Closes the gap where editing a client showed
an empty file picker even when proof had been uploaded on create.

Identifier-save hardened across all three callsites (create-client, edit-client,
identities-tab.createIdentifierWithDocs) - the KYC chip picker proofId is a CODE
string ('AADHAAR'), but backend ClientIdentifierRequest.documentTypeId is Long, which
Spring rejects with HttpMessageNotReadableException -> 400. resolveDocumentTypeId
helper looks up the code against /kyc/proof-types?type=id and substitutes the numeric
CodeValue id before posting. Skips silently for constitution-specific non-individual
docs that have no CodeValue mapping.

KYC payload normalises panNumber / enterprisePan / gstinNumber / cinNumber via
toUpperCase + whitespace strip so user-typed lowercase or trailing spaces don't trip
the backend regex (validation.msg.CLIENTKYC.panNumber.does.not.match.regexp).

State name match in client-address save now normalises both sides (lowercase, collapse
underscores + spaces) so legacy MADHYA_PRADESH resolves to 'Madhya Pradesh' returned
by api.postalpincode.in. Backed by tenant migration 0297.

Identities-tab resolver flattened - was returning identifiers before the per-row
forkJoin(getClientIdentificationDocuments) completed, so the view rendered empty
documents arrays. Now uses switchMap + forkJoin so the resolver awaits completion.

Also bundles concurrent work-in-progress on letter-mgmt, organization, users,
bank-calendar, shell, nominee/notes/identifier dialogs, and theming.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Aditya
2026-05-20 12:40:58 +05:30
co-authored by Claude Opus 4.7
parent 325228c514
commit 83ea57ccf0
84 changed files with 10281 additions and 1194 deletions
@@ -0,0 +1,186 @@
<!--
Copyright since 2025 Mifos Initiative
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
-->
<div class="ufd-root">
<div class="ufd-head">
<div class="ufd-head__left">
<fa-icon [icon]="isEdit ? 'pencil-alt' : 'user-plus'" class="ufd-head__ic"></fa-icon>
<div>
<h2 class="ufd-head__title">{{ isEdit ? 'Edit User' : 'Create User' }}</h2>
<div class="ufd-head__sub">
{{ isEdit ? 'Update the details for this user.' : 'Add a new operator or self-service user.' }}
</div>
</div>
</div>
<button class="ufd-x" (click)="cancel()" matTooltip="Close">
<fa-icon icon="times"></fa-icon>
</button>
</div>
@if (loadingTemplate || loadingUser) {
<div class="ufd-loading">
<fa-icon icon="spinner" class="fa-spin"></fa-icon>
Loading…
</div>
} @else {
<form class="ufd-body" [formGroup]="form" (ngSubmit)="submit()">
<!-- Identity -->
<div class="ufd-section">
<div class="ufd-section__title">Identity</div>
<div class="ufd-grid">
<div class="ufd-field">
<label>Login Name *</label>
<input type="text" formControlName="username" autocomplete="username" placeholder="e.g. arao" />
@if (form.get('username')?.touched && form.get('username')?.errors?.['required']) {
<div class="ufd-err">Login name is required.</div>
}
</div>
<div class="ufd-field">
<label>Email *</label>
<input type="email" formControlName="email" placeholder="user@bank.com" />
@if (form.get('email')?.touched && form.get('email')?.errors) {
<div class="ufd-err">A valid email is required.</div>
}
</div>
<div class="ufd-field">
<label>First Name *</label>
<input type="text" formControlName="firstname" placeholder="First name" />
@if (form.get('firstname')?.touched && form.get('firstname')?.errors) {
<div class="ufd-err">First name must start with a letter.</div>
}
</div>
<div class="ufd-field">
<label>Last Name *</label>
<input type="text" formControlName="lastname" placeholder="Last name" />
@if (form.get('lastname')?.touched && form.get('lastname')?.errors) {
<div class="ufd-err">Last name must start with a letter.</div>
}
</div>
<div class="ufd-field">
<label>Mobile *</label>
<div class="ufd-input-prefix">
<span class="ufd-prefix">+91</span>
<input type="tel" maxlength="10" formControlName="mobileNo" placeholder="10-digit mobile" />
</div>
@if (form.get('mobileNo')?.touched && form.get('mobileNo')?.errors) {
<div class="ufd-err">Mobile must be 10 digits.</div>
}
</div>
</div>
</div>
<!-- Office mapping -->
<div class="ufd-section">
<div class="ufd-section__title">Office &amp; Staff</div>
<div class="ufd-grid">
<div class="ufd-field">
<label>Office *</label>
<select formControlName="officeId">
<option [ngValue]="''">Select an office</option>
@for (o of offices; track o.id) {
<option [ngValue]="o.id">{{ o.name }}</option>
}
</select>
@if (form.get('officeId')?.touched && form.get('officeId')?.errors?.['required']) {
<div class="ufd-err">Office is required.</div>
}
</div>
<div class="ufd-field">
<label>Staff (optional)</label>
<select formControlName="staffId">
<option [ngValue]="''">— Not linked —</option>
@for (s of staff; track s.id) {
<option [ngValue]="s.id">{{ s.displayName }}</option>
}
</select>
</div>
</div>
</div>
<!-- Roles -->
<div class="ufd-section">
<div class="ufd-section__title">Roles *</div>
<div class="ufd-roles">
@for (r of roles; track r.id) {
<button type="button" class="ufd-role" [class.active]="isRoleSelected(r.id)" (click)="toggleRole(r.id)">
<fa-icon [icon]="isRoleSelected(r.id) ? 'check' : 'plus'"></fa-icon>
{{ r.name }}
</button>
}
</div>
@if (form.get('roles')?.touched && form.get('roles')?.errors?.['required']) {
<div class="ufd-err">Pick at least one role.</div>
}
</div>
<!-- Security (create-only) -->
@if (!isEdit) {
<div class="ufd-section">
<div class="ufd-section__title">Security</div>
<label class="ufd-check">
<input type="checkbox" formControlName="sendPasswordToEmail" />
<span>Send the auto-generated password to the user's email</span>
</label>
<label class="ufd-check">
<input type="checkbox" formControlName="passwordNeverExpires" />
<span>Password never expires</span>
</label>
@if (!form.get('sendPasswordToEmail')?.value) {
<div class="ufd-grid">
<div class="ufd-field">
<label>Password *</label>
<input type="password" formControlName="password" autocomplete="new-password" />
@if (form.get('password')?.touched && form.get('password')?.invalid) {
<div class="ufd-err">Min 8 chars · 1 upper · 1 lower · 1 digit · 1 special.</div>
}
</div>
<div class="ufd-field">
<label>Confirm Password *</label>
<input type="password" formControlName="repeatPassword" autocomplete="new-password" />
@if (form.get('repeatPassword')?.touched && form.get('repeatPassword')?.invalid) {
<div class="ufd-err">Passwords don't match.</div>
}
</div>
</div>
}
</div>
} @else {
<div class="ufd-section">
<div class="ufd-section__title">Security</div>
<label class="ufd-check">
<input type="checkbox" formControlName="passwordNeverExpires" />
<span>Password never expires</span>
</label>
<div class="ufd-hint">
<fa-icon icon="info-circle"></fa-icon>
To change the password, open the user from the list and use "Change Password".
</div>
</div>
}
@if (serverError) {
<div class="ufd-server-err">
<fa-icon icon="exclamation-triangle"></fa-icon>
{{ serverError }}
</div>
}
<div class="ufd-actions">
<button type="button" class="ufd-btn ghost" (click)="cancel()" [disabled]="submitting">Cancel</button>
<button type="submit" class="ufd-btn primary" [disabled]="form.invalid || submitting">
<fa-icon
[icon]="submitting ? 'spinner' : isEdit ? 'check' : 'user-plus'"
[class.fa-spin]="submitting"
></fa-icon>
{{ submitting ? 'Saving…' : isEdit ? 'Save Changes' : 'Create User' }}
</button>
</div>
</form>
}
</div>
@@ -0,0 +1,357 @@
/**
* Copyright since 2025 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
$navy: #0d1b2a;
$blue: #1e88e5;
$blue-d: #1e40af;
$green: #10b981;
$red: #ef4444;
$amber: #f59e0b;
$purple: #7c3aed;
:host {
display: block;
}
.ufd-root {
background: #fff;
width: 720px;
max-width: 96vw;
max-height: 90vh;
display: flex;
flex-direction: column;
}
.ufd-head {
display: flex;
align-items: center;
justify-content: space-between;
padding: 14px 20px;
border-bottom: 1px solid #e2e8f0;
background: linear-gradient(180deg, #f8fafc 0%, #fff 100%);
&__left {
display: flex;
align-items: center;
gap: 12px;
}
&__ic {
width: 38px;
height: 38px;
display: inline-flex;
align-items: center;
justify-content: center;
border-radius: 10px;
background: linear-gradient(135deg, $blue 0%, $purple 100%);
color: #fff;
font-size: 14px;
box-shadow: 0 2px 6px -2px rgb(29 78 216 / 35%);
}
&__title {
margin: 0;
font-size: 16px;
font-weight: 800;
color: $navy;
line-height: 1.1;
}
&__sub {
margin-top: 2px;
font-size: 11.5px;
color: #64748b;
}
}
.ufd-x {
width: 32px;
height: 32px;
border-radius: 999px;
border: 1px solid #e2e8f0;
background: #fff;
color: #64748b;
cursor: pointer;
display: inline-flex;
align-items: center;
justify-content: center;
&:hover {
background: #fef2f2;
color: $red;
border-color: #fecaca;
}
}
.ufd-loading {
display: flex;
align-items: center;
gap: 10px;
padding: 40px 24px;
color: #64748b;
font-size: 13px;
}
.ufd-body {
flex: 1;
overflow-y: auto;
padding: 16px 20px 20px;
display: flex;
flex-direction: column;
gap: 14px;
}
.ufd-section {
background: #f8fafc;
border: 1px solid #e2e8f0;
border-radius: 10px;
padding: 12px 14px;
&__title {
font-size: 10.5px;
text-transform: uppercase;
letter-spacing: 0.06em;
font-weight: 700;
color: $blue-d;
margin-bottom: 10px;
}
}
.ufd-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px 14px;
}
.ufd-field {
display: flex;
flex-direction: column;
gap: 4px;
label {
font-size: 11px;
font-weight: 600;
color: #475569;
}
input,
select {
height: 36px;
padding: 0 10px;
border: 1px solid #cbd5e1;
border-radius: 7px;
background: #fff;
color: $navy;
font-size: 13px;
transition: all 0.12s;
&:focus {
outline: none;
border-color: $blue;
box-shadow: 0 0 0 3px rgb(30 136 229 / 14%);
}
}
select {
appearance: none;
background-image:
linear-gradient(45deg, transparent 50%, #64748b 50%), linear-gradient(135deg, #64748b 50%, transparent 50%);
background-position:
calc(100% - 14px) 50%,
calc(100% - 9px) 50%;
background-size:
5px 5px,
5px 5px;
background-repeat: no-repeat;
padding-right: 28px;
}
}
.ufd-input-prefix {
display: flex;
align-items: stretch;
border: 1px solid #cbd5e1;
border-radius: 7px;
background: #fff;
overflow: hidden;
height: 36px;
&:focus-within {
border-color: $blue;
box-shadow: 0 0 0 3px rgb(30 136 229 / 14%);
}
.ufd-prefix {
display: inline-flex;
align-items: center;
padding: 0 10px;
background: #f1f5f9;
color: #475569;
font-size: 12px;
font-weight: 600;
border-right: 1px solid #cbd5e1;
}
input {
flex: 1;
border: none;
padding: 0 10px;
font-size: 13px;
outline: none;
color: $navy;
}
}
.ufd-err {
font-size: 10.5px;
color: $red;
font-weight: 600;
margin-top: 1px;
}
.ufd-roles {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
.ufd-role {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 6px 12px;
border: 1px solid #cbd5e1;
background: #fff;
border-radius: 999px;
color: #475569;
font-size: 12px;
font-weight: 600;
cursor: pointer;
transition: all 0.12s;
fa-icon {
font-size: 9px;
}
&:hover {
border-color: #94a3b8;
color: $navy;
}
&.active {
background: linear-gradient(135deg, $blue 0%, $blue-d 100%);
border-color: $blue-d;
color: #fff;
box-shadow: 0 1px 4px -1px rgb(30 64 175 / 35%);
}
}
.ufd-check {
display: flex;
align-items: center;
gap: 8px;
font-size: 12.5px;
color: $navy;
margin: 4px 0;
cursor: pointer;
// stylelint-disable-next-line selector-no-qualifying-type
input[type='checkbox'] {
width: 16px;
height: 16px;
accent-color: $blue;
}
}
.ufd-hint {
display: flex;
align-items: center;
gap: 8px;
margin-top: 8px;
font-size: 11.5px;
color: #64748b;
fa-icon {
color: $amber;
}
}
.ufd-server-err {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 14px;
border: 1px solid #fecaca;
background: #fef2f2;
border-radius: 8px;
color: $red;
font-size: 12.5px;
font-weight: 600;
}
.ufd-actions {
display: flex;
justify-content: flex-end;
gap: 10px;
border-top: 1px solid #e2e8f0;
margin-top: 4px;
padding-top: 14px;
}
.ufd-btn {
display: inline-flex;
align-items: center;
gap: 8px;
height: 38px;
padding: 0 18px;
border-radius: 8px;
font-size: 13px;
font-weight: 700;
cursor: pointer;
transition: all 0.15s;
border: 1px solid transparent;
fa-icon {
font-size: 11px;
}
&.ghost {
background: #fff;
border-color: #d0d5dd;
color: #475569;
&:hover:not(:disabled) {
background: #f8fafc;
border-color: #94a3b8;
color: $navy;
}
}
&.primary {
background: linear-gradient(135deg, $blue 0%, $blue-d 100%);
border-color: $blue-d;
color: #fff;
box-shadow: 0 2px 6px -2px rgb(30 64 175 / 35%);
&:hover:not(:disabled) {
box-shadow: 0 4px 12px -3px rgb(30 64 175 / 45%);
transform: translateY(-1px);
}
}
&:disabled {
opacity: 0.55;
cursor: not-allowed;
}
}
@media (width <= 600px) {
.ufd-grid {
grid-template-columns: 1fr;
}
}
@@ -0,0 +1,251 @@
/**
* Copyright since 2025 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import { Component, OnInit, inject } from '@angular/core';
import { CommonModule } from '@angular/common';
import {
UntypedFormBuilder,
UntypedFormControl,
UntypedFormGroup,
ReactiveFormsModule,
Validators
} from '@angular/forms';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { MatTooltip } from '@angular/material/tooltip';
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
import { UsersService } from '../users.service';
import { PasswordsUtility } from 'app/core/utils/passwords-utility';
export interface UserFormDialogData {
mode: 'create' | 'edit';
userId?: string | number;
}
/**
* User form dialog — drives BOTH create and edit through a single dialog.
*
* The dialog loads the users template (offices + roles) on init and, for edit
* mode, fetches the full user record so all fields pre-fill correctly. On
* submit it calls createUser / editUser and closes with `true` on success.
*/
@Component({
selector: 'mifosx-user-form-dialog',
templateUrl: './user-form-dialog.component.html',
styleUrls: ['./user-form-dialog.component.scss'],
imports: [
...STANDALONE_SHARED_IMPORTS,
CommonModule,
ReactiveFormsModule,
FaIconComponent,
MatTooltip
]
})
export class UserFormDialogComponent implements OnInit {
private fb = inject(UntypedFormBuilder);
private usersService = inject(UsersService);
private passwordsUtility = inject(PasswordsUtility);
public dialogRef = inject(MatDialogRef<UserFormDialogComponent>);
public data = inject<UserFormDialogData>(MAT_DIALOG_DATA);
form!: UntypedFormGroup;
offices: any[] = [];
roles: any[] = [];
staff: any[] = [];
loadingTemplate = true;
loadingUser = false;
submitting = false;
/** Server-side error to surface in the dialog when the API rejects submit. */
serverError: string | null = null;
/** Cached existing user payload (edit mode only). */
private existing: any = null;
get isEdit(): boolean {
return this.data.mode === 'edit';
}
ngOnInit(): void {
this.buildEmptyForm();
this.usersService.getUsersTemplate().subscribe({
next: (tpl: any) => {
this.offices = tpl?.allowedOffices || [];
this.roles = tpl?.availableRoles || [];
this.loadingTemplate = false;
// After template arrives, edit-mode user loading is what triggers the
// pre-fill — see loadExistingUser().
if (this.isEdit) this.loadExistingUser();
},
error: () => {
this.loadingTemplate = false;
this.serverError = 'Could not load office / role list. Please retry.';
}
});
this.form.get('officeId')!.valueChanges.subscribe((officeId: any) => {
this.staff = [];
if (officeId == null || officeId === '') return;
this.usersService.getStaff(officeId).subscribe((s: any) => (this.staff = s || []));
});
// Toggle password fields based on "Send password to email" checkbox.
// Edit mode hides these entirely (password is changed separately).
if (!this.isEdit) {
this.form.get('sendPasswordToEmail')!.valueChanges.subscribe((send: boolean) => {
if (send) {
this.form.removeControl('password');
this.form.removeControl('repeatPassword');
} else {
this.form.addControl('password', new UntypedFormControl('', this.passwordsUtility.getPasswordValidators()));
this.form.addControl(
'repeatPassword',
new UntypedFormControl('', [
Validators.required,
this.passwordsUtility.confirmPassword('password')
])
);
}
});
}
}
private buildEmptyForm(): void {
this.form = this.fb.group({
username: [
'',
Validators.required
],
firstname: [
'',
[
Validators.required,
Validators.pattern('(^[A-z]).*')
]
],
lastname: [
'',
[
Validators.required,
Validators.pattern('(^[A-z]).*')
]
],
email: [
'',
[
Validators.required,
Validators.email,
Validators.pattern(/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/)
]
],
mobileNo: [
'',
[
Validators.required,
Validators.pattern(/^\d{10}$/)
]
],
officeId: [
'',
Validators.required
],
staffId: [''],
roles: [
[] as number[],
Validators.required
],
passwordNeverExpires: [false],
sendPasswordToEmail: [true]
});
}
private loadExistingUser(): void {
if (!this.data.userId) return;
this.loadingUser = true;
this.usersService.getUser(String(this.data.userId)).subscribe({
next: (u: any) => {
this.existing = u;
const staffId = u?.staff?.id ?? null;
const selectedRoleIds = (u?.selectedRoles || []).map((r: any) => r.id);
// Edit mode never asks about password — strip those controls.
this.form.removeControl('sendPasswordToEmail');
this.form.patchValue({
username: u.username,
firstname: u.firstname,
lastname: u.lastname,
email: u.email,
mobileNo: u.mobileNo || '',
officeId: u.officeId,
staffId,
roles: selectedRoleIds,
passwordNeverExpires: !!u.passwordNeverExpires
});
this.loadingUser = false;
},
error: () => {
this.loadingUser = false;
this.serverError = 'Could not load this user. Please retry.';
}
});
}
/** Toggle a role chip on/off in the multi-select chip group. */
toggleRole(roleId: number): void {
const ctrl = this.form.get('roles')!;
const current: number[] = ctrl.value || [];
const next = current.includes(roleId) ? current.filter((id) => id !== roleId) : [
...current,
roleId
];
ctrl.setValue(next);
ctrl.markAsTouched();
}
isRoleSelected(roleId: number): boolean {
return (this.form.get('roles')?.value || []).includes(roleId);
}
submit(): void {
if (this.form.invalid || this.submitting) {
this.form.markAllAsTouched();
return;
}
this.submitting = true;
this.serverError = null;
const payload: any = { ...this.form.value };
if (payload.staffId == null || payload.staffId === '') delete payload.staffId;
const req$ = this.isEdit
? this.usersService.editUser(String(this.existing?.id ?? this.data.userId), payload)
: this.usersService.createUser(payload);
req$.subscribe({
next: (response: any) => {
this.submitting = false;
this.dialogRef.close({
ok: true,
userId: response?.resourceId ?? this.existing?.id ?? this.data.userId,
username: payload.username
});
},
error: (err: any) => {
this.submitting = false;
this.serverError =
err?.error?.errors?.[0]?.defaultUserMessage ||
err?.error?.defaultUserMessage ||
err?.error?.developerMessage ||
(this.isEdit ? 'Failed to update user.' : 'Failed to create user.');
}
});
}
cancel(): void {
this.dialogRef.close();
}
}