refactor user accounts structure
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
<p-dialog
|
||||
header="فرم کاربر"
|
||||
[(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]="form.disabled" (onCancel)="close()" />
|
||||
</form>
|
||||
</p-dialog>
|
||||
@@ -0,0 +1,25 @@
|
||||
import { AbstractFormDialog } from '@/shared/abstractClasses';
|
||||
import { InputComponent } from '@/shared/components';
|
||||
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
|
||||
import { Component, inject } from '@angular/core';
|
||||
import { ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { Dialog } from 'primeng/dialog';
|
||||
import { ILicenseRequest, ILicenseResponse } from '../models';
|
||||
import { LicensesService } from '../services/main.service';
|
||||
|
||||
@Component({
|
||||
selector: 'license-form',
|
||||
templateUrl: './form.component.html',
|
||||
imports: [ReactiveFormsModule, Dialog, InputComponent, FormFooterActionsComponent],
|
||||
})
|
||||
export class LicenseFormComponent extends AbstractFormDialog<ILicenseRequest, ILicenseResponse> {
|
||||
private service = inject(LicensesService);
|
||||
|
||||
form = this.fb.group({
|
||||
name: [this.initialValues?.name || '', [Validators.required]],
|
||||
});
|
||||
|
||||
override submitForm(payload: ILicenseRequest) {
|
||||
return this.service.create(payload);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
const baseUrl = '/api/v1/admin/partners';
|
||||
|
||||
export const LICENSES_API_ROUTES = {
|
||||
list: () => `${baseUrl}`,
|
||||
single: (id: string) => `${baseUrl}/${id}`,
|
||||
};
|
||||
@@ -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 TLicensesRouteNames = 'licenses' | 'license';
|
||||
|
||||
export const licensesNamedRoutes: NamedRoutes<TLicensesRouteNames> = {
|
||||
licenses: {
|
||||
path: 'licenses',
|
||||
loadComponent: () => import('../../views/list.component').then((m) => m.LicensesComponent),
|
||||
meta: {
|
||||
title: 'لایسنسها',
|
||||
pagePath: () => '/super_admin/licenses',
|
||||
},
|
||||
},
|
||||
license: {
|
||||
path: 'licenses/:licenseId',
|
||||
loadComponent: () => import('../../views/single.component').then((m) => m.LicenseComponent),
|
||||
meta: {
|
||||
title: 'لایسنس',
|
||||
pagePath: () => '/super_admin/licenses/:licenseId',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const LICENSES_ROUTES: Routes = Object.values(licensesNamedRoutes);
|
||||
@@ -0,0 +1 @@
|
||||
export * from './io';
|
||||
@@ -0,0 +1,9 @@
|
||||
export interface ILicenseRawResponse {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
export interface ILicenseResponse extends ILicenseRawResponse {}
|
||||
|
||||
export interface ILicenseRequest {
|
||||
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 { LICENSES_API_ROUTES } from '../constants';
|
||||
import { ILicenseRawResponse, ILicenseRequest, ILicenseResponse } from '../models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class LicensesService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
private apiRoutes = LICENSES_API_ROUTES;
|
||||
|
||||
getAll(): Observable<IPaginatedResponse<ILicenseResponse>> {
|
||||
return this.http.get<IPaginatedResponse<ILicenseRawResponse>>(this.apiRoutes.list());
|
||||
}
|
||||
getSingle(userId: string): Observable<ILicenseResponse> {
|
||||
return this.http.get<ILicenseRawResponse>(this.apiRoutes.single(userId));
|
||||
}
|
||||
|
||||
create(userData: ILicenseRequest): Observable<ILicenseResponse> {
|
||||
return this.http.post<ILicenseResponse>(this.apiRoutes.list(), userData);
|
||||
}
|
||||
|
||||
update(userId: string, userData: ILicenseRequest): Observable<ILicenseResponse> {
|
||||
return this.http.patch<ILicenseResponse>(this.apiRoutes.single(userId), userData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './list.component';
|
||||
export * from './single.component';
|
||||
@@ -0,0 +1,18 @@
|
||||
<app-page-data-list
|
||||
[pageTitle]="'مدیریت لایسنسها'"
|
||||
[addNewCtaLabel]="'افزودن لایسنس جدید'"
|
||||
[columns]="columns"
|
||||
[showAdd]="true"
|
||||
emptyPlaceholderTitle="لایسنسی یافت نشد"
|
||||
emptyPlaceholderDescription="برای افزودن لایسنس جدید، روی دکمهٔ بالا کلیک کنید."
|
||||
[items]="items()"
|
||||
[loading]="loading()"
|
||||
[showDetails]="true"
|
||||
[showAdd]="true"
|
||||
(onAdd)="openAddForm()"
|
||||
>
|
||||
<!-- <ng-template #role let-data>
|
||||
<catalog-role-tag [role]="data.role" />
|
||||
</ng-template> -->
|
||||
</app-page-data-list>
|
||||
<license-form [(visible)]="visibleForm" (onSubmit)="refresh()" />
|
||||
@@ -0,0 +1,31 @@
|
||||
// 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 { LicenseFormComponent } from '../components/form.component';
|
||||
import { ILicenseResponse } from '../models';
|
||||
import { LicensesService } from '../services/main.service';
|
||||
|
||||
@Component({
|
||||
selector: 'admin-licenses',
|
||||
templateUrl: './list.component.html',
|
||||
imports: [PageDataListComponent, LicenseFormComponent],
|
||||
})
|
||||
export class LicensesComponent extends AbstractList<ILicenseResponse> {
|
||||
private readonly service = inject(LicensesService);
|
||||
|
||||
override setColumns(): void {
|
||||
this.columns = [
|
||||
{ field: 'id', header: 'شناسه' },
|
||||
{
|
||||
field: 'created_at',
|
||||
header: 'تاریخ ایجاد',
|
||||
type: 'date',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
override getDataRequest() {
|
||||
return this.service.getAll();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<div class=""></div>
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Component } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'admin-license',
|
||||
templateUrl: './single.component.html',
|
||||
})
|
||||
export class LicenseComponent {
|
||||
constructor() {}
|
||||
}
|
||||
Reference in New Issue
Block a user