feat: Implement product categories, stores, suppliers, and users management features
- Added ProductCategoriesService for handling product category API interactions. - Created components for listing and viewing product categories. - Implemented UI for managing product categories with a data list component. - Developed StoresService for managing store-related API calls. - Created components for listing and viewing stores with appropriate UI. - Added SuppliersService for handling supplier API interactions. - Implemented components for managing suppliers with a data list component. - Developed UsersService for managing user-related API calls. - Created components for listing and viewing users with appropriate UI. - Enhanced not found page with improved layout and navigation options.
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
<p-dialog header="فرم کاربر" [(visible)]="visible" [modal]="true" [style]="{ width: '500px' }" [closable]="true">
|
||||
<form [formGroup]="form" (submit)="submit()" class="flex flex-col gap-4">
|
||||
<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" />
|
||||
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="form.disabled" (onCancel)="close()" />
|
||||
</form>
|
||||
</p-dialog>
|
||||
@@ -0,0 +1,81 @@
|
||||
import { mobileValidator } from '@/core/validators';
|
||||
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 { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { Dialog } from 'primeng/dialog';
|
||||
import { IUserRequest, IUserResponse } from '../models';
|
||||
import { UsersService } from '../services/main.service';
|
||||
|
||||
@Component({
|
||||
selector: 'user-form',
|
||||
templateUrl: './form.component.html',
|
||||
imports: [
|
||||
ReactiveFormsModule,
|
||||
Dialog,
|
||||
UikitFieldComponent,
|
||||
InputComponent,
|
||||
FormFooterActionsComponent,
|
||||
],
|
||||
})
|
||||
export class UserFormComponent {
|
||||
@Input() initialValues?: IUserResponse;
|
||||
|
||||
@Input()
|
||||
set visible(v: boolean) {
|
||||
this.visibleSignal.set(!!v);
|
||||
}
|
||||
get visible() {
|
||||
return this.visibleSignal();
|
||||
}
|
||||
private visibleSignal = signal(false);
|
||||
|
||||
@Output() visibleChange = new EventEmitter<boolean>();
|
||||
@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();
|
||||
});
|
||||
}
|
||||
|
||||
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]],
|
||||
});
|
||||
|
||||
submitLoading = signal(false);
|
||||
|
||||
submit() {
|
||||
this.form.markAllAsTouched();
|
||||
if (this.form.valid) {
|
||||
this.form.disable();
|
||||
this.submitLoading.set(true);
|
||||
this.service.create(this.form.value as IUserRequest).subscribe({
|
||||
next: (res) => {
|
||||
this.submitLoading.set(false);
|
||||
this.form.enable();
|
||||
this.form.reset();
|
||||
this.onSubmit.emit(res);
|
||||
},
|
||||
error: () => {
|
||||
this.submitLoading.set(false);
|
||||
this.form.enable();
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
close() {
|
||||
this.visibleChange.emit(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
const baseUrl = '/api/v1/users';
|
||||
|
||||
export const USERS_API_ROUTES = {
|
||||
list: () => `${baseUrl}`,
|
||||
single: (userId: string) => `${baseUrl}/${userId}`,
|
||||
};
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './apiRoutes';
|
||||
export * from './routes';
|
||||
@@ -0,0 +1,25 @@
|
||||
import { NamedRoutes } from '@/core';
|
||||
import { Routes } from '@angular/router';
|
||||
|
||||
export type TUsersRouteNames = 'users' | 'user';
|
||||
|
||||
export const usersNamedRoutes: NamedRoutes<TUsersRouteNames> = {
|
||||
users: {
|
||||
path: 'users',
|
||||
loadComponent: () => import('../../views/list.component').then((m) => m.UsersComponent),
|
||||
meta: {
|
||||
title: 'کاربران',
|
||||
pagePath: () => '/users',
|
||||
},
|
||||
},
|
||||
user: {
|
||||
path: 'users/:userId',
|
||||
loadComponent: () => import('../../views/single.component').then((m) => m.UserComponent),
|
||||
meta: {
|
||||
title: 'کاربر',
|
||||
pagePath: () => '/users/:userId',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const USERS_ROUTES: Routes = Object.values(usersNamedRoutes);
|
||||
@@ -0,0 +1 @@
|
||||
export * from './io';
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
export interface IUserRawResponse {
|
||||
mobileNumber: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
id: number;
|
||||
roleId: number;
|
||||
}
|
||||
export interface IUserResponse extends IUserRawResponse {}
|
||||
|
||||
export interface IUserRequest {
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
mobileNumber: string;
|
||||
roleId: number;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { USERS_API_ROUTES } from '../constants';
|
||||
import { IUserRawResponse, IUserRequest, IUserResponse } from '../models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class UsersService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
private apiRoutes = USERS_API_ROUTES;
|
||||
|
||||
getAll(): Observable<IUserResponse[]> {
|
||||
return this.http.get<IUserRawResponse[]>(this.apiRoutes.list());
|
||||
}
|
||||
getSingle(userId: string): Observable<IUserResponse> {
|
||||
return this.http.get<IUserRawResponse>(this.apiRoutes.single(userId));
|
||||
}
|
||||
|
||||
create(userData: IUserRequest): Observable<IUserResponse> {
|
||||
return this.http.post<IUserResponse>(this.apiRoutes.list(), userData);
|
||||
}
|
||||
|
||||
update(userId: string, userData: IUserRequest): Observable<IUserResponse> {
|
||||
return this.http.patch<IUserResponse>(this.apiRoutes.single(userId), userData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './list.component';
|
||||
export * from './single.component';
|
||||
@@ -0,0 +1,15 @@
|
||||
<app-page-data-list
|
||||
[pageTitle]="'مدیریت کاربران'"
|
||||
[addNewCtaLabel]="'افزودن کاربر جدید'"
|
||||
[columns]="columns"
|
||||
[showAdd]="true"
|
||||
emptyPlaceholderTitle="کاربری یافت نشد"
|
||||
emptyPlaceholderDescription="برای افزودن کاربر جدید، روی دکمهٔ بالا کلیک کنید."
|
||||
[items]="[]"
|
||||
[loading]="loading()"
|
||||
[showDetails]="true"
|
||||
[showAdd]="true"
|
||||
(onAdd)="openAddForm()"
|
||||
/>
|
||||
|
||||
<user-form [(visible)]="visibleForm" (onSubmit)="refresh()" />
|
||||
@@ -0,0 +1,48 @@
|
||||
import {
|
||||
IColumn,
|
||||
PageDataListComponent,
|
||||
} from '@/shared/components/pageDataList/page-data-list.component';
|
||||
import { Component, signal } from '@angular/core';
|
||||
import { UserFormComponent } from '../components/form.component';
|
||||
import { IUserResponse } from '../models';
|
||||
import { UsersService } from '../services/main.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-users',
|
||||
templateUrl: './list.component.html',
|
||||
imports: [PageDataListComponent, UserFormComponent],
|
||||
})
|
||||
export class UsersComponent {
|
||||
constructor(private userService: UsersService) {
|
||||
this.getData();
|
||||
}
|
||||
|
||||
columns = [
|
||||
{ field: 'id', header: 'شناسه' },
|
||||
{ field: 'firstName', header: 'نام' },
|
||||
{ field: 'lastName', header: 'نام خانوادگی' },
|
||||
{ field: 'mobileNumber', header: 'شماره موبایل' },
|
||||
{ field: 'roleId', header: 'نقش' },
|
||||
{ field: 'actions' },
|
||||
] as IColumn[];
|
||||
|
||||
loading = signal(false);
|
||||
items = signal<IUserResponse[]>([]);
|
||||
visibleForm = signal(false);
|
||||
|
||||
refresh() {
|
||||
this.getData();
|
||||
}
|
||||
|
||||
getData() {
|
||||
this.loading.set(true);
|
||||
this.userService.getAll().subscribe((res) => {
|
||||
this.loading.set(false);
|
||||
this.items.set(res);
|
||||
});
|
||||
}
|
||||
|
||||
openAddForm() {
|
||||
this.visibleForm.set(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<div class=""></div>
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-user',
|
||||
templateUrl: './single.component.html',
|
||||
})
|
||||
export class UserComponent {
|
||||
constructor() {}
|
||||
}
|
||||
Reference in New Issue
Block a user