feat: add product management features and integrate role selection
- Added PRODUCTS_ROUTES to app routing. - Removed roles.const.ts and related references to central-auth-roles. - Updated login component to remove role selection logic. - Integrated ToastService for success notifications in customer, inventory, product brand, product category, supplier, and user forms. - Implemented product and category selection fields in product form. - Created reusable select components for product brands and categories. - Enhanced user form with password validation and role selection. - Established roles service for fetching roles from the API.
This commit is contained in:
@@ -3,7 +3,35 @@
|
||||
<app-input label="نام" [control]="form.controls.firstName" name="firstName" />
|
||||
<app-input label="نام خانوادگی" [control]="form.controls.lastName" name="lastName" />
|
||||
<app-input label="شماره موبایل" [control]="form.controls.mobileNumber" name="mobileNumber" type="mobile" />
|
||||
<app-input label="نقش" [control]="form.controls.roleId" name="roleId" />
|
||||
<catalog-roles-select [control]="form.controls.roleId" />
|
||||
<uikit-field label="رمز عبور" class="" [control]="form.get('password')">
|
||||
<p-password
|
||||
id="password1"
|
||||
name="password"
|
||||
formControlName="password"
|
||||
autocomplete="password"
|
||||
[toggleMask]="true"
|
||||
[fluid]="true"
|
||||
[feedback]="false"
|
||||
[invalid]="form.get('password')?.touched && form.get('password')?.invalid"
|
||||
/>
|
||||
<span class="text-xs mt-2 text-muted-color">
|
||||
رمز باید حداقل ۸ کاراکتر بوده و شامل حداقل یک حرف بزرگ، یک حرف کوچک، یک عدد و یک کاراکتر ویژه باشد.
|
||||
</span>
|
||||
</uikit-field>
|
||||
|
||||
<uikit-field label="تکرار رمز عبور" class="" [control]="form.get('confirmPassword')">
|
||||
<p-password
|
||||
id="confirmPassword"
|
||||
name="confirmPassword"
|
||||
formControlName="confirmPassword"
|
||||
autocomplete="new-password"
|
||||
[toggleMask]="true"
|
||||
[fluid]="true"
|
||||
[feedback]="false"
|
||||
[invalid]="form.get('confirmPassword')?.touched && form.get('confirmPassword')?.invalid"
|
||||
/>
|
||||
</uikit-field>
|
||||
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="form.disabled" (onCancel)="close()" />
|
||||
</form>
|
||||
</p-dialog>
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { mobileValidator } from '@/core/validators';
|
||||
import { ToastService } from '@/core/services/toast.service';
|
||||
import { mobileValidator, MustMatch, password } from '@/core/validators';
|
||||
import { CatalogRolesComponent } from '@/shared/catalog/roles';
|
||||
import { InputComponent } from '@/shared/components';
|
||||
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
|
||||
import { UikitFieldComponent } from '@/uikit';
|
||||
import { Component, effect, EventEmitter, inject, Input, Output, signal } from '@angular/core';
|
||||
import { Component, EventEmitter, inject, Input, Output, signal } from '@angular/core';
|
||||
import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { Dialog } from 'primeng/dialog';
|
||||
import { Password } from 'primeng/password';
|
||||
import { IUserRequest, IUserResponse } from '../models';
|
||||
import { UsersService } from '../services/main.service';
|
||||
|
||||
@@ -14,9 +17,11 @@ import { UsersService } from '../services/main.service';
|
||||
imports: [
|
||||
ReactiveFormsModule,
|
||||
Dialog,
|
||||
UikitFieldComponent,
|
||||
InputComponent,
|
||||
FormFooterActionsComponent,
|
||||
CatalogRolesComponent,
|
||||
UikitFieldComponent,
|
||||
Password,
|
||||
],
|
||||
})
|
||||
export class UserFormComponent {
|
||||
@@ -35,23 +40,33 @@ export class UserFormComponent {
|
||||
@Output() onSubmit = new EventEmitter<IUserResponse>();
|
||||
|
||||
private fb = inject(FormBuilder);
|
||||
constructor(private service: UsersService) {
|
||||
effect(() => {
|
||||
const v = this.visibleSignal();
|
||||
// this.visibleChange.emit(v);
|
||||
if (!v) this.form.reset();
|
||||
});
|
||||
constructor(
|
||||
private service: UsersService,
|
||||
private toastService: ToastService,
|
||||
) {
|
||||
// effect(() => {
|
||||
// const v = this.visibleSignal();
|
||||
// // this.visibleChange.emit(v);
|
||||
// if (!v) this.form.reset();
|
||||
// });
|
||||
}
|
||||
|
||||
form = this.fb.group({
|
||||
firstName: [this.initialValues?.firstName || null, [Validators.required]],
|
||||
lastName: [this.initialValues?.lastName || null, [Validators.required]],
|
||||
mobileNumber: [
|
||||
this.initialValues?.mobileNumber || null,
|
||||
[Validators.required, mobileValidator()],
|
||||
],
|
||||
roleId: [this.initialValues?.roleId || null, [Validators.required]],
|
||||
});
|
||||
form = this.fb.group(
|
||||
{
|
||||
firstName: [this.initialValues?.firstName || '', [Validators.required]],
|
||||
lastName: [this.initialValues?.lastName || '', [Validators.required]],
|
||||
mobileNumber: [
|
||||
this.initialValues?.mobileNumber || '',
|
||||
[Validators.required, mobileValidator()],
|
||||
],
|
||||
roleId: [this.initialValues?.role.id || null, [Validators.required]],
|
||||
password: ['', [Validators.required, password()]],
|
||||
confirmPassword: ['', [Validators.required]],
|
||||
},
|
||||
{
|
||||
validators: [MustMatch('password', 'confirmPassword')],
|
||||
},
|
||||
);
|
||||
|
||||
submitLoading = signal(false);
|
||||
|
||||
@@ -60,8 +75,13 @@ export class UserFormComponent {
|
||||
if (this.form.valid) {
|
||||
this.form.disable();
|
||||
this.submitLoading.set(true);
|
||||
this.service.create(this.form.value as IUserRequest).subscribe({
|
||||
const { confirmPassword, ...rest } = this.form.value;
|
||||
this.service.create(rest as IUserRequest).subscribe({
|
||||
next: (res) => {
|
||||
this.toastService.success({
|
||||
text: `کاربر ${this.form.value.firstName} با موفقیت ایجاد شد`,
|
||||
});
|
||||
this.close();
|
||||
this.submitLoading.set(false);
|
||||
this.form.enable();
|
||||
this.form.reset();
|
||||
|
||||
Vendored
+3
-1
@@ -1,9 +1,11 @@
|
||||
import { IRoleResponse } from '@/shared/catalog/roles';
|
||||
|
||||
export interface IUserRawResponse {
|
||||
mobileNumber: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
id: number;
|
||||
roleId: number;
|
||||
role: IRoleResponse;
|
||||
}
|
||||
export interface IUserResponse extends IUserRawResponse {}
|
||||
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
[showDetails]="true"
|
||||
[showAdd]="true"
|
||||
(onAdd)="openAddForm()"
|
||||
/>
|
||||
|
||||
>
|
||||
<ng-template #role let-data>
|
||||
<catalog-role-tag [role]="data.role" />
|
||||
</ng-template>
|
||||
</app-page-data-list>
|
||||
<user-form [(visible)]="visibleForm" (onSubmit)="refresh()" />
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
|
||||
import {
|
||||
IColumn,
|
||||
PageDataListComponent,
|
||||
} from '@/shared/components/pageDataList/page-data-list.component';
|
||||
import { Component, signal } from '@angular/core';
|
||||
import { Component, signal, TemplateRef, ViewChild } from '@angular/core';
|
||||
import { UserFormComponent } from '../components/form.component';
|
||||
import { IUserResponse } from '../models';
|
||||
import { UsersService } from '../services/main.service';
|
||||
@@ -10,20 +11,25 @@ import { UsersService } from '../services/main.service';
|
||||
@Component({
|
||||
selector: 'app-users',
|
||||
templateUrl: './list.component.html',
|
||||
imports: [PageDataListComponent, UserFormComponent],
|
||||
imports: [PageDataListComponent, UserFormComponent, CatalogRoleTagComponent],
|
||||
})
|
||||
export class UsersComponent {
|
||||
constructor(private userService: UsersService) {
|
||||
this.getData();
|
||||
}
|
||||
@ViewChild('role', { static: true }) roleTpl!: TemplateRef<any>;
|
||||
|
||||
columns = [
|
||||
{ field: 'id', header: 'شناسه' },
|
||||
{ field: 'firstName', header: 'نام' },
|
||||
{ field: 'lastName', header: 'نام خانوادگی' },
|
||||
{ field: 'mobileNumber', header: 'شماره موبایل' },
|
||||
{ field: 'roleId', header: 'نقش' },
|
||||
{ field: 'actions' },
|
||||
// { field: 'role', header: 'نقش', customDataModel: this.roleTpl },
|
||||
{
|
||||
field: 'role',
|
||||
header: 'نقش',
|
||||
customDataModel: (item: IUserResponse) => item.role.name ?? '-',
|
||||
},
|
||||
] as IColumn[];
|
||||
|
||||
loading = signal(false);
|
||||
|
||||
Reference in New Issue
Block a user