feat: update POS and account components to use new field names and improve form handling
This commit is contained in:
@@ -8,10 +8,39 @@
|
||||
>
|
||||
<form [formGroup]="form" (submit)="submit()" class="flex flex-col gap-4">
|
||||
<app-input label="عنوان" [control]="form.controls.name" name="name" />
|
||||
<!-- <app-input label="مدل دستگاه" [control]="form.controls.model" name="model" /> -->
|
||||
<app-enum-select [control]="form.controls.pos_type" type="posType" name="pos_type" />
|
||||
|
||||
@if (!editMode) {
|
||||
<app-input label="نام کاربری" [control]="form.controls.username" name="username" [isLtrInput]="true" />
|
||||
<uikit-field label="رمز عبور" [control]="form.controls.password">
|
||||
<p-password
|
||||
id="password"
|
||||
name="password"
|
||||
formControlName="password"
|
||||
autocomplete="new-password"
|
||||
styleClass="w-full"
|
||||
[toggleMask]="true"
|
||||
[feedback]="false"
|
||||
[invalid]="form.controls.password.touched && form.controls.password.invalid"
|
||||
/>
|
||||
</uikit-field>
|
||||
|
||||
<uikit-field label="تکرار رمز عبور" [control]="form.controls.confirmPassword">
|
||||
<p-password
|
||||
id="confirmPassword"
|
||||
name="confirmPassword"
|
||||
formControlName="confirmPassword"
|
||||
autocomplete="new-password"
|
||||
styleClass="w-full"
|
||||
[toggleMask]="true"
|
||||
[feedback]="false"
|
||||
[invalid]="form.controls.confirmPassword.touched && form.controls.confirmPassword.invalid"
|
||||
/>
|
||||
</uikit-field>
|
||||
}
|
||||
|
||||
@if (form.controls.pos_type.value === "PSP") {
|
||||
<app-input label="سریال دستگاه" [control]="form.controls.serial" name="serial" />
|
||||
<app-input label="سریال دستگاه" [control]="form.controls.serial_number" name="serial_number" />
|
||||
<catalog-device-select [control]="form.controls.device_id" />
|
||||
<catalog-provider-select [control]="form.controls.provider_id" />
|
||||
}
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
// import { CatalogRolesComponent } from '@/shared/catalog/roles';
|
||||
import { MustMatch } from '@/core/validators';
|
||||
import { AbstractFormDialog } from '@/shared/abstractClasses';
|
||||
import { EnumSelectComponent } from '@/shared/apiEnum/select.component';
|
||||
import { CatalogProviderSelectComponent } from '@/shared/catalog';
|
||||
import { CatalogDeviceSelectComponent } from '@/shared/catalog/devices';
|
||||
import { InputComponent } from '@/shared/components';
|
||||
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
|
||||
import { UikitFieldComponent } from '@/uikit';
|
||||
import { Component, inject, Input } from '@angular/core';
|
||||
import { ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { Dialog } from 'primeng/dialog';
|
||||
import { Password } from 'primeng/password';
|
||||
import { IPosRequest, IPosResponse } from '../../models';
|
||||
import { PartnerPosesService } from '../../services/poses.service';
|
||||
|
||||
@@ -22,6 +25,8 @@ import { PartnerPosesService } from '../../services/poses.service';
|
||||
CatalogDeviceSelectComponent,
|
||||
CatalogProviderSelectComponent,
|
||||
EnumSelectComponent,
|
||||
UikitFieldComponent,
|
||||
Password,
|
||||
],
|
||||
})
|
||||
export class ConsumerPosFormComponent extends AbstractFormDialog<IPosRequest, IPosResponse> {
|
||||
@@ -35,44 +40,74 @@ export class ConsumerPosFormComponent extends AbstractFormDialog<IPosRequest, IP
|
||||
initForm = () => {
|
||||
const form = this.fb.group({
|
||||
name: [this.initialValues?.name || '', [Validators.required]],
|
||||
serial: [this.initialValues?.serial || '', [Validators.required]],
|
||||
// model: [this.initialValues?.model || '', [Validators.required]],
|
||||
pos_type: [this.initialValues?.pos_type || '', [Validators.required]],
|
||||
serial_number: [this.initialValues?.serial_number || ''],
|
||||
device_id: [this.initialValues?.device?.id || ''],
|
||||
provider_id: [this.initialValues?.provider?.id || ''],
|
||||
username: [''],
|
||||
password: [''],
|
||||
confirmPassword: [''],
|
||||
});
|
||||
|
||||
form.controls.pos_type.valueChanges.subscribe((value) => {
|
||||
if (value === 'PSP') {
|
||||
form.addControl(
|
||||
'serial',
|
||||
this.fb.control<string>(this.initialValues?.serial ?? '', {
|
||||
nonNullable: true,
|
||||
validators: [Validators.required],
|
||||
}),
|
||||
);
|
||||
form.addControl(
|
||||
'device_id',
|
||||
this.fb.control<string>(this.initialValues?.device?.id ?? '', {
|
||||
nonNullable: true,
|
||||
validators: [Validators.required],
|
||||
}),
|
||||
);
|
||||
form.addControl(
|
||||
'provider_id',
|
||||
this.fb.control<string>(this.initialValues?.provider?.id ?? '', {
|
||||
nonNullable: true,
|
||||
validators: [Validators.required],
|
||||
}),
|
||||
);
|
||||
form.controls.serial_number.setValidators([Validators.required]);
|
||||
form.controls.device_id.setValidators([Validators.required]);
|
||||
form.controls.provider_id.setValidators([Validators.required]);
|
||||
form.controls.serial_number.enable({ emitEvent: false });
|
||||
form.controls.device_id.enable({ emitEvent: false });
|
||||
form.controls.provider_id.enable({ emitEvent: false });
|
||||
} else {
|
||||
// @ts-ignore
|
||||
form.removeControl('serial');
|
||||
// @ts-ignore
|
||||
form.removeControl('device_id');
|
||||
// @ts-ignore
|
||||
form.removeControl('provider_id');
|
||||
form.controls.serial_number.clearValidators();
|
||||
form.controls.device_id.clearValidators();
|
||||
form.controls.provider_id.clearValidators();
|
||||
form.controls.serial_number.reset('');
|
||||
form.controls.device_id.reset('');
|
||||
form.controls.provider_id.reset('');
|
||||
form.controls.serial_number.disable({ emitEvent: false });
|
||||
form.controls.device_id.disable({ emitEvent: false });
|
||||
form.controls.provider_id.disable({ emitEvent: false });
|
||||
}
|
||||
|
||||
form.controls.serial_number.updateValueAndValidity({ emitEvent: false });
|
||||
form.controls.device_id.updateValueAndValidity({ emitEvent: false });
|
||||
form.controls.provider_id.updateValueAndValidity({ emitEvent: false });
|
||||
});
|
||||
form.controls.pos_type.updateValueAndValidity({ emitEvent: true });
|
||||
|
||||
if (this.editMode) {
|
||||
// @ts-ignore
|
||||
form.removeControl('username');
|
||||
// @ts-ignore
|
||||
form.removeControl('password');
|
||||
// @ts-ignore
|
||||
form.removeControl('confirmPassword');
|
||||
form.removeValidators([MustMatch('password', 'confirmPassword')]);
|
||||
} else {
|
||||
form.addControl(
|
||||
'username',
|
||||
this.fb.control<string>('', {
|
||||
nonNullable: true,
|
||||
validators: [Validators.required],
|
||||
}),
|
||||
);
|
||||
form.addControl(
|
||||
'password',
|
||||
this.fb.control<string>('', {
|
||||
nonNullable: true,
|
||||
validators: [Validators.required],
|
||||
}),
|
||||
);
|
||||
form.addControl(
|
||||
'confirmPassword',
|
||||
this.fb.control<string>('', {
|
||||
nonNullable: true,
|
||||
validators: [Validators.required],
|
||||
}),
|
||||
);
|
||||
form.addValidators([MustMatch('password', 'confirmPassword')]);
|
||||
}
|
||||
|
||||
return form;
|
||||
};
|
||||
|
||||
@@ -87,10 +122,11 @@ export class ConsumerPosFormComponent extends AbstractFormDialog<IPosRequest, IP
|
||||
}
|
||||
|
||||
submitForm() {
|
||||
const formValue = this.form.value as IPosRequest;
|
||||
const formValue = this.form.value as IPosRequest & { confirmPassword?: string };
|
||||
if (this.editMode) {
|
||||
return this.service.update(this.businessActivityId, this.complexId, this.posId, formValue);
|
||||
}
|
||||
return this.service.create(this.businessActivityId, this.complexId, formValue);
|
||||
const { confirmPassword, ...rest } = formValue;
|
||||
return this.service.create(this.businessActivityId, this.complexId, rest);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import ISummary from '@/core/models/summary';
|
||||
export interface IPosRawResponse {
|
||||
id: string;
|
||||
name: string;
|
||||
serial: string;
|
||||
serial_number?: string;
|
||||
model?: string;
|
||||
status: string;
|
||||
pos_type: string;
|
||||
@@ -15,10 +15,10 @@ export interface IPosResponse extends IPosRawResponse {}
|
||||
|
||||
export interface IPosRequest {
|
||||
name: string;
|
||||
serial: string;
|
||||
model?: string;
|
||||
status: string;
|
||||
serial_number: string;
|
||||
pos_type: string;
|
||||
device_id: string;
|
||||
provider_id: string;
|
||||
device_id?: string;
|
||||
provider_id?: string;
|
||||
username?: string;
|
||||
password?: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user