feat: refactor password input handling across multiple components
- Replaced individual password and confirm password fields with a shared-password-input component in the following components: - Partner Account Password Form - Consumer Account Form - Consumer User Form - Consumer Pos Form - Super Admin Consumer Account Form - Super Admin Partner Account Form - Super Admin Provider Form - Super Admin User Account Form - Modify Login Info Page - Introduced a new SharedPasswordInputComponent to encapsulate password input logic and validation messages. - Updated form handling to utilize reactive forms with shared components for better maintainability and consistency. - Added a ChangePasswordFormDialogComponent for changing passwords with validation. - Created API routes for business activity goods in the consumer module.
This commit is contained in:
+17
@@ -0,0 +1,17 @@
|
||||
<p-dialog
|
||||
[header]="dialogHeader"
|
||||
[(visible)]="visible"
|
||||
[modal]="true"
|
||||
[style]="{ width: '500px' }"
|
||||
[closable]="true"
|
||||
(onHide)="close()"
|
||||
>
|
||||
<form [formGroup]="form" (submit)="submit()" class="flex flex-col gap-4">
|
||||
<shared-password-input
|
||||
[passwordControl]="form.controls.password"
|
||||
[confirmPasswordControl]="form.controls.confirmPassword"
|
||||
/>
|
||||
|
||||
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="loading()" (onCancel)="close()" />
|
||||
</form>
|
||||
</p-dialog>
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
import { MustMatch, password } from '@/core/validators';
|
||||
import { AbstractDialog } from '@/shared/abstractClasses/abstract-dialog';
|
||||
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
|
||||
import { Component, EventEmitter, Output, input } from '@angular/core';
|
||||
import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { Dialog } from 'primeng/dialog';
|
||||
import { SharedPasswordInputComponent } from '../passwordInput/password-input.component';
|
||||
|
||||
export interface IChangePasswordSubmitPayload {
|
||||
password: string;
|
||||
confirmPassword: string;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'shared-change-password-form-dialog',
|
||||
templateUrl: './change-password-form-dialog.component.html',
|
||||
imports: [ReactiveFormsModule, Dialog, FormFooterActionsComponent, SharedPasswordInputComponent],
|
||||
})
|
||||
export class ChangePasswordFormDialogComponent extends AbstractDialog {
|
||||
title = input<string>('');
|
||||
loading = input<boolean>(false);
|
||||
|
||||
@Output() onSubmit = new EventEmitter<IChangePasswordSubmitPayload>();
|
||||
|
||||
private readonly fb = new FormBuilder();
|
||||
|
||||
form = this.fb.group(
|
||||
{
|
||||
password: ['', [Validators.required, password()]],
|
||||
confirmPassword: ['', [Validators.required]],
|
||||
},
|
||||
{
|
||||
validators: [MustMatch('password', 'confirmPassword')],
|
||||
},
|
||||
);
|
||||
|
||||
get dialogHeader() {
|
||||
return this.title() ? `تغییر گذرواژهی ${this.title()}` : 'تغییر گذرواژه';
|
||||
}
|
||||
|
||||
submit() {
|
||||
this.form.markAllAsTouched();
|
||||
if (this.form.invalid) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.onSubmit.emit(this.form.getRawValue() as IChangePasswordSubmitPayload);
|
||||
}
|
||||
|
||||
override close() {
|
||||
this.form.reset();
|
||||
super.close();
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
// export * from './abstract-select.component';
|
||||
export * from './breadcrumb.component';
|
||||
export * from './card-data.component';
|
||||
export * from './changePasswordFormDialog/change-password-form-dialog.component';
|
||||
export * from './inlineConfirmation/inline-confirmation.component';
|
||||
export * from './inlineEdit/inline-edit.component';
|
||||
export * from './input/input.component';
|
||||
export * from './key-value.component/key-value.component';
|
||||
export * from './passwordInput/password-input.component';
|
||||
export * from './table-action-row.component';
|
||||
|
||||
@@ -1,28 +1,30 @@
|
||||
<uikit-field label="رمز عبور" class="" [control]="passwordControl">
|
||||
<uikit-field label="رمز عبور" [pSize]="size" [control]="passwordControl">
|
||||
<p-password
|
||||
id="password1"
|
||||
name="password"
|
||||
formControlName="password"
|
||||
autocomplete="password"
|
||||
[toggleMask]="true"
|
||||
[fluid]="true"
|
||||
[fluid]="fluid"
|
||||
[feedback]="false"
|
||||
[size]="size"
|
||||
[invalid]="passwordControl.touched && passwordControl.invalid"
|
||||
/>
|
||||
<span class="text-xs mt-1 mb-3 text-muted-color">
|
||||
رمز باید حداقل ۸ کاراکتر بوده و شامل حداقل یک حرف بزرگ، یک حرف کوچک، یک عدد و یک کاراکتر ویژه باشد.
|
||||
{{ hint }}
|
||||
</span>
|
||||
</uikit-field>
|
||||
|
||||
<uikit-field label="تکرار رمز عبور" class="" [control]="confirmPasswordControl">
|
||||
<uikit-field label="تکرار رمز عبور" [pSize]="size" [control]="confirmPasswordControl">
|
||||
<p-password
|
||||
id="confirmPassword"
|
||||
name="confirmPassword"
|
||||
formControlName="confirmPassword"
|
||||
autocomplete="new-password"
|
||||
[toggleMask]="true"
|
||||
[fluid]="true"
|
||||
[fluid]="fluid"
|
||||
[feedback]="false"
|
||||
[size]="size"
|
||||
[invalid]="confirmPasswordControl.touched && confirmPasswordControl.invalid"
|
||||
/>
|
||||
</uikit-field>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { UikitFieldComponent } from '@/uikit';
|
||||
import { Component, Input } from '@angular/core';
|
||||
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
|
||||
import { FormControl, ReactiveFormsModule } from '@angular/forms';
|
||||
import { Password } from 'primeng/password';
|
||||
|
||||
@Component({
|
||||
@@ -11,5 +11,8 @@ import { Password } from 'primeng/password';
|
||||
export class SharedPasswordInputComponent {
|
||||
@Input({ required: true }) passwordControl = new FormControl<string>('');
|
||||
@Input({ required: true }) confirmPasswordControl = new FormControl<string>('');
|
||||
@Input({ required: true }) formGroup!: FormGroup<any>;
|
||||
@Input() hint: string =
|
||||
'رمز باید حداقل ۸ کاراکتر بوده و شامل حداقل یک حرف بزرگ، یک حرف کوچک، یک عدد و یک کاراکتر ویژه باشد.';
|
||||
@Input() fluid: boolean = true;
|
||||
@Input() size: 'small' | 'large' = 'small';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user