refactor user accounts structure
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
<p-dialog
|
||||
[header]="preparedTitle()"
|
||||
[(visible)]="visible"
|
||||
[modal]="true"
|
||||
[style]="{ width: '500px' }"
|
||||
[closable]="true"
|
||||
(onHide)="close()"
|
||||
>
|
||||
<form [formGroup]="form" (submit)="submit()" class="flex flex-col gap-4">
|
||||
<app-input label="عنوان" [control]="form.controls.name" name="name" />
|
||||
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="submitLoading()" (onCancel)="close()" />
|
||||
</form>
|
||||
</p-dialog>
|
||||
@@ -0,0 +1,44 @@
|
||||
import { AbstractFormDialog } from '@/shared/abstractClasses';
|
||||
import { InputComponent } from '@/shared/components';
|
||||
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
|
||||
import { Component, computed, inject, Input } from '@angular/core';
|
||||
import { ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { Dialog } from 'primeng/dialog';
|
||||
import { IDeviceBrandRequest, IDeviceBrandResponse } from '../models';
|
||||
import { DeviceBrandsService } from '../services/main.service';
|
||||
|
||||
@Component({
|
||||
selector: 'deviceBrand-form',
|
||||
templateUrl: './form.component.html',
|
||||
imports: [ReactiveFormsModule, Dialog, InputComponent, FormFooterActionsComponent],
|
||||
})
|
||||
export class DeviceBrandFormComponent extends AbstractFormDialog<
|
||||
IDeviceBrandRequest,
|
||||
IDeviceBrandResponse
|
||||
> {
|
||||
@Input() brandId?: string;
|
||||
private service = inject(DeviceBrandsService);
|
||||
|
||||
form = this.fb.group({
|
||||
name: this.fb.control<string>(this.initialValues?.name || '', {
|
||||
nonNullable: true,
|
||||
validators: [Validators.required],
|
||||
}),
|
||||
});
|
||||
|
||||
preparedTitle = computed(() => `${this.editMode ? 'ویرایش' : 'ایجاد'} برند دستگاه`);
|
||||
|
||||
override ngOnChanges() {
|
||||
this.form.patchValue(this.initialValues ?? {});
|
||||
if (this.editMode && !this.brandId) {
|
||||
throw 'missing some arguments';
|
||||
}
|
||||
}
|
||||
|
||||
override submitForm(payload: IDeviceBrandRequest) {
|
||||
if (this.editMode) {
|
||||
return this.service.update(this.brandId!, payload);
|
||||
}
|
||||
return this.service.create(payload);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
const baseUrl = '/api/v1/admin/device_brands';
|
||||
|
||||
export const DEVICE_BRANDS_API_ROUTES = {
|
||||
list: () => `${baseUrl}`,
|
||||
single: (id: string) => `${baseUrl}/${id}`,
|
||||
};
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './apiRoutes';
|
||||
export * from './routes';
|
||||
@@ -0,0 +1,17 @@
|
||||
import { NamedRoutes } from '@/core';
|
||||
import { Routes } from '@angular/router';
|
||||
|
||||
export type TDeviceBrandsRouteNames = 'deviceBrands';
|
||||
|
||||
export const deviceBrandsNamedRoutes: NamedRoutes<TDeviceBrandsRouteNames> = {
|
||||
deviceBrands: {
|
||||
path: 'device_brands',
|
||||
loadComponent: () => import('../../views/list.component').then((m) => m.DeviceBrandsComponent),
|
||||
meta: {
|
||||
title: 'برندها',
|
||||
pagePath: () => '/super_admin/deviceBrands',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const DEVICE_BRANDS_ROUTES: Routes = Object.values(deviceBrandsNamedRoutes);
|
||||
@@ -0,0 +1 @@
|
||||
export * from './io';
|
||||
@@ -0,0 +1,9 @@
|
||||
export interface IDeviceBrandRawResponse {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
export interface IDeviceBrandResponse extends IDeviceBrandRawResponse {}
|
||||
|
||||
export interface IDeviceBrandRequest {
|
||||
name: string;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { IPaginatedResponse } from '@/core/models/service.model';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { DEVICE_BRANDS_API_ROUTES } from '../constants';
|
||||
import { IDeviceBrandRawResponse, IDeviceBrandRequest, IDeviceBrandResponse } from '../models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class DeviceBrandsService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
private apiRoutes = DEVICE_BRANDS_API_ROUTES;
|
||||
|
||||
getAll(): Observable<IPaginatedResponse<IDeviceBrandResponse>> {
|
||||
return this.http.get<IPaginatedResponse<IDeviceBrandRawResponse>>(this.apiRoutes.list());
|
||||
}
|
||||
// getSingle(userId: string): Observable<IDeviceBrandResponse> {
|
||||
// return this.http.get<IDeviceBrandRawResponse>(this.apiRoutes.single(userId));
|
||||
// }
|
||||
|
||||
create(userData: IDeviceBrandRequest): Observable<IDeviceBrandResponse> {
|
||||
return this.http.post<IDeviceBrandResponse>(this.apiRoutes.list(), userData);
|
||||
}
|
||||
|
||||
update(userId: string, userData: IDeviceBrandRequest): Observable<IDeviceBrandResponse> {
|
||||
return this.http.patch<IDeviceBrandResponse>(this.apiRoutes.single(userId), userData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from './list.component';
|
||||
@@ -0,0 +1,21 @@
|
||||
<app-page-data-list
|
||||
pageTitle="مدیریت برند دستگاهها"
|
||||
[addNewCtaLabel]="'افزودن برند دستگاه جدید'"
|
||||
[columns]="columns"
|
||||
[showAdd]="true"
|
||||
emptyPlaceholderTitle="برند دستگاه یافت نشد"
|
||||
emptyPlaceholderDescription="برای افزودن برند دستگاه جدید، روی دکمهٔ بالا کلیک کنید."
|
||||
[items]="items()"
|
||||
[loading]="loading()"
|
||||
[showAdd]="true"
|
||||
[showEdit]="true"
|
||||
(onAdd)="openAddForm()"
|
||||
(onEdit)="onEditClick($event)"
|
||||
/>
|
||||
<deviceBrand-form
|
||||
[(visible)]="visibleForm"
|
||||
[editMode]="editMode()"
|
||||
[brandId]="selectedItemForEdit()?.id"
|
||||
[initialValues]="selectedItemForEdit() || undefined"
|
||||
(onSubmit)="refresh()"
|
||||
/>
|
||||
@@ -0,0 +1,36 @@
|
||||
// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
|
||||
import { AbstractList } from '@/shared/abstractClasses/abstract-list';
|
||||
import { PageDataListComponent } from '@/shared/components/pageDataList/page-data-list.component';
|
||||
import { Component, inject } from '@angular/core';
|
||||
import { DeviceBrandFormComponent } from '../components/form.component';
|
||||
import { IDeviceBrandResponse } from '../models';
|
||||
import { DeviceBrandsService } from '../services/main.service';
|
||||
|
||||
@Component({
|
||||
selector: 'superAdmin-deviceBrands',
|
||||
templateUrl: './list.component.html',
|
||||
imports: [PageDataListComponent, DeviceBrandFormComponent],
|
||||
})
|
||||
export class DeviceBrandsComponent extends AbstractList<IDeviceBrandResponse> {
|
||||
private readonly service = inject(DeviceBrandsService);
|
||||
|
||||
override setColumns(): void {
|
||||
this.columns = [
|
||||
{ field: 'id', header: 'شناسه' },
|
||||
{ field: 'name', header: 'عنوان' },
|
||||
{
|
||||
field: 'created_at',
|
||||
header: 'تاریخ ایجاد',
|
||||
type: 'date',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
override getDataRequest() {
|
||||
return this.service.getAll();
|
||||
}
|
||||
|
||||
// toSinglePage(partner: IDeviceBrandResponse) {
|
||||
// this.router.navigateByUrl(partnersNamedRoutes.partner.meta.pagePath!(partner.id));
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user