refactor user accounts structure
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<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.username" name="username" />
|
||||
<app-enum-select [control]="form.controls.type" name="type" type="accountType" />
|
||||
<uikit-field label="رمز عبور" class="" [control]="form.controls.password">
|
||||
<p-password
|
||||
id="password1"
|
||||
name="password"
|
||||
formControlName="password"
|
||||
autocomplete="password"
|
||||
[toggleMask]="true"
|
||||
[fluid]="true"
|
||||
[feedback]="false"
|
||||
[invalid]="form.controls.password.touched && form.controls.password.invalid"
|
||||
/>
|
||||
<span class="text-xs mt-2 text-muted-color">
|
||||
رمز باید حداقل ۸ کاراکتر بوده و شامل حداقل یک حرف بزرگ، یک حرف کوچک، یک عدد و یک کاراکتر ویژه باشد.
|
||||
</span>
|
||||
</uikit-field>
|
||||
|
||||
<uikit-field label="تکرار رمز عبور" class="" [control]="form.controls.confirmPassword">
|
||||
<p-password
|
||||
id="confirmPassword"
|
||||
name="confirmPassword"
|
||||
formControlName="confirmPassword"
|
||||
autocomplete="new-password"
|
||||
[toggleMask]="true"
|
||||
[fluid]="true"
|
||||
[feedback]="false"
|
||||
[invalid]="form.controls.confirmPassword.touched && form.controls.confirmPassword.invalid"
|
||||
/>
|
||||
</uikit-field>
|
||||
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="submitLoading()" (onCancel)="close()" />
|
||||
</form>
|
||||
</p-dialog>
|
||||
@@ -0,0 +1,66 @@
|
||||
import { MustMatch, password } from '@/core/validators';
|
||||
// import { CatalogRolesComponent } from '@/shared/catalog/roles';
|
||||
import { AbstractFormDialog } from '@/shared/abstractClasses';
|
||||
import { EnumSelectComponent } from '@/shared/apiEnum/select.component';
|
||||
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 { IPartnerAccountRequest, IPartnerAccountResponse } from '../../models';
|
||||
import { AdminPartnerAccountsService } from '../../services/accounts.service';
|
||||
|
||||
@Component({
|
||||
selector: 'superAdmin-partner-account-form',
|
||||
templateUrl: './form.component.html',
|
||||
imports: [
|
||||
ReactiveFormsModule,
|
||||
Dialog,
|
||||
InputComponent,
|
||||
FormFooterActionsComponent,
|
||||
UikitFieldComponent,
|
||||
Password,
|
||||
EnumSelectComponent,
|
||||
],
|
||||
})
|
||||
export class PartnerAccountFormComponent extends AbstractFormDialog<
|
||||
IPartnerAccountRequest,
|
||||
IPartnerAccountResponse
|
||||
> {
|
||||
private readonly service = inject(AdminPartnerAccountsService);
|
||||
|
||||
@Input({ required: true }) partnerId!: string;
|
||||
@Input() accountId!: string;
|
||||
|
||||
initForm = () => {
|
||||
return this.fb.group(
|
||||
{
|
||||
username: [this.initialValues?.username || '', [Validators.required]],
|
||||
type: ['', [Validators.required]],
|
||||
password: ['', [Validators.required, password()]],
|
||||
confirmPassword: ['', [Validators.required]],
|
||||
},
|
||||
{
|
||||
validators: [MustMatch('password', 'confirmPassword')],
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
form = this.initForm();
|
||||
|
||||
override ngOnChanges(): void {
|
||||
this.form = this.initForm();
|
||||
}
|
||||
|
||||
submitForm() {
|
||||
const formValue = this.form.value as IPartnerAccountRequest;
|
||||
// @ts-ignore
|
||||
const { confirmPassword, ...rest } = formValue;
|
||||
if (this.editMode) {
|
||||
return this.service.update(this.partnerId, this.accountId, rest);
|
||||
}
|
||||
return this.service.create(this.partnerId, rest);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<app-page-data-list
|
||||
pageTitle="مدیریت حسابهای کاربری"
|
||||
[addNewCtaLabel]="'افزودن حساب کاربری جدید'"
|
||||
[columns]="columns"
|
||||
[showAdd]="true"
|
||||
emptyPlaceholderTitle="حساب کاربریای یافت نشد."
|
||||
emptyPlaceholderDescription="برای افزودن حساب کاربری جدید، روی دکمهٔ بالا کلیک کنید."
|
||||
[items]="items()"
|
||||
[loading]="loading()"
|
||||
[showDetails]="true"
|
||||
[showAdd]="true"
|
||||
(onAdd)="openAddForm()"
|
||||
>
|
||||
</app-page-data-list>
|
||||
<superAdmin-partner-account-form
|
||||
[(visible)]="visibleForm"
|
||||
[editMode]="editMode()"
|
||||
[partnerId]="partnerId"
|
||||
[accountId]="selectedItemForEdit()?.id || ''"
|
||||
[initialValues]="selectedItemForEdit() || undefined"
|
||||
(onSubmit)="refresh()"
|
||||
/>
|
||||
@@ -0,0 +1,50 @@
|
||||
// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
|
||||
import { AbstractList } from '@/shared/abstractClasses/abstract-list';
|
||||
import {
|
||||
IColumn,
|
||||
PageDataListComponent,
|
||||
} from '@/shared/components/pageDataList/page-data-list.component';
|
||||
import { Component, inject, Input } from '@angular/core';
|
||||
import { IPartnerAccountResponse } from '../../models';
|
||||
import { AdminPartnerAccountsService } from '../../services/accounts.service';
|
||||
import { PartnerAccountFormComponent } from './form.component';
|
||||
|
||||
@Component({
|
||||
selector: 'superAdmin-partner-account-list',
|
||||
templateUrl: './list.component.html',
|
||||
imports: [PageDataListComponent, PartnerAccountFormComponent],
|
||||
})
|
||||
export class ConsumerAccountListComponent extends AbstractList<IPartnerAccountResponse> {
|
||||
@Input({ required: true }) partnerId!: string;
|
||||
@Input() fullHeight?: boolean;
|
||||
@Input() header: IColumn[] = [
|
||||
{ field: 'id', header: 'شناسه' },
|
||||
{
|
||||
field: 'username',
|
||||
header: 'نام کاربری',
|
||||
type: 'nested',
|
||||
nestedPath: 'account.username',
|
||||
},
|
||||
{ field: 'role', header: 'نوع حساب' },
|
||||
{
|
||||
field: 'status',
|
||||
header: 'وضعیت',
|
||||
type: 'nested',
|
||||
nestedPath: 'account.status',
|
||||
},
|
||||
{
|
||||
field: 'created_at',
|
||||
header: 'تاریخ ایجاد',
|
||||
type: 'date',
|
||||
},
|
||||
];
|
||||
private readonly service = inject(AdminPartnerAccountsService);
|
||||
|
||||
override setColumns(): void {
|
||||
this.columns = this.header;
|
||||
}
|
||||
|
||||
override getDataRequest() {
|
||||
return this.service.getAll(this.partnerId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<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-input label="کد" [control]="form.controls.code" name="code" />
|
||||
<app-input
|
||||
label="تعداد لایسنسهای رزرو"
|
||||
[control]="form.controls.license_quota"
|
||||
name="license_quota"
|
||||
type="number"
|
||||
[min]="0"
|
||||
/>
|
||||
@if (!editMode) {
|
||||
<p-divider align="center"> اطلاعات ورود </p-divider>
|
||||
<!-- @ts-ignore -->
|
||||
<app-input label="نام کاربری" [control]="form.controls.username" name="username" [isLtrInput]="true" />
|
||||
<uikit-field label="رمز عبور" class="" [control]="form.controls.password">
|
||||
<p-password
|
||||
id="password1"
|
||||
name="password"
|
||||
formControlName="password"
|
||||
autocomplete="password"
|
||||
[toggleMask]="true"
|
||||
[fluid]="true"
|
||||
[feedback]="false"
|
||||
[invalid]="form.controls.password.touched && form.controls.password.invalid"
|
||||
/>
|
||||
<span class="text-xs mt-1 text-muted-color">
|
||||
رمز باید حداقل ۸ کاراکتر بوده و شامل حداقل یک حرف بزرگ، یک حرف کوچک، یک عدد و یک کاراکتر ویژه باشد.
|
||||
</span>
|
||||
</uikit-field>
|
||||
|
||||
<uikit-field label="تکرار رمز عبور" class="" [control]="form.controls.confirmPassword">
|
||||
<p-password
|
||||
id="confirmPassword"
|
||||
name="confirmPassword"
|
||||
formControlName="confirmPassword"
|
||||
autocomplete="new-password"
|
||||
[toggleMask]="true"
|
||||
[fluid]="true"
|
||||
[feedback]="false"
|
||||
[invalid]="form.controls.confirmPassword.touched && form.controls.confirmPassword.invalid"
|
||||
/>
|
||||
</uikit-field>
|
||||
}
|
||||
|
||||
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="submitLoading()" (onCancel)="close()" />
|
||||
</form>
|
||||
</p-dialog>
|
||||
@@ -0,0 +1,97 @@
|
||||
import { MustMatch } from '@/core/validators';
|
||||
import { AbstractFormDialog } from '@/shared/abstractClasses';
|
||||
import { InputComponent } from '@/shared/components';
|
||||
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
|
||||
import { UikitFieldComponent } from '@/uikit';
|
||||
import { Component, computed, inject, Input } from '@angular/core';
|
||||
import { ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { Dialog } from 'primeng/dialog';
|
||||
import { Divider } from 'primeng/divider';
|
||||
import { Password } from 'primeng/password';
|
||||
import { IPartnerRequest, IPartnerResponse } from '../models';
|
||||
import { PartnersService } from '../services/main.service';
|
||||
|
||||
@Component({
|
||||
selector: 'partner-form',
|
||||
templateUrl: './form.component.html',
|
||||
imports: [
|
||||
ReactiveFormsModule,
|
||||
Dialog,
|
||||
InputComponent,
|
||||
FormFooterActionsComponent,
|
||||
Divider,
|
||||
UikitFieldComponent,
|
||||
Password,
|
||||
],
|
||||
})
|
||||
export class GuildFormComponent extends AbstractFormDialog<IPartnerRequest, IPartnerResponse> {
|
||||
@Input() partnerId?: string;
|
||||
private service = inject(PartnersService);
|
||||
|
||||
private initForm() {
|
||||
const form = this.fb.group({
|
||||
name: [this.initialValues?.name, [Validators.required]],
|
||||
code: [this.initialValues?.code, [Validators.required]],
|
||||
license_quota: [this.initialValues?.license_quota || 0, [Validators.required]],
|
||||
username: [''],
|
||||
password: [''],
|
||||
confirmPassword: [''],
|
||||
});
|
||||
|
||||
if (!this.editMode) {
|
||||
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')]);
|
||||
} else {
|
||||
// @ts-ignore
|
||||
form.removeControl('username');
|
||||
// @ts-ignore
|
||||
form.removeControl('password');
|
||||
// @ts-ignore
|
||||
form.removeControl('confirmPassword');
|
||||
form.removeValidators([MustMatch('password', 'confirmPassword')]);
|
||||
}
|
||||
|
||||
return form;
|
||||
}
|
||||
|
||||
form = this.initForm();
|
||||
|
||||
preparedTitle = computed(() => `${this.editMode ? 'ویرایش' : 'ایجاد'} شریک تجاری`);
|
||||
|
||||
override ngOnChanges() {
|
||||
this.form.patchValue(this.initialValues ?? {});
|
||||
if (this.editMode && !this.partnerId) {
|
||||
throw 'missing some arguments';
|
||||
}
|
||||
this.initForm();
|
||||
}
|
||||
|
||||
override submitForm(payload: IPartnerRequest) {
|
||||
if (this.editMode) {
|
||||
return this.service.update(this.partnerId!, payload);
|
||||
}
|
||||
// @ts-ignore
|
||||
const { confirmPassword, ...rest } = payload;
|
||||
return this.service.create(rest);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
@if (loading()) {
|
||||
<shared-page-loading />
|
||||
} @else {
|
||||
<router-outlet></router-outlet>
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import { PageLoadingComponent } from '@/shared/components/page-loading.component';
|
||||
import { Component, computed, inject, signal } from '@angular/core';
|
||||
import { ActivatedRoute, RouterOutlet } from '@angular/router';
|
||||
import { PartnerStore } from '../store/partner.store';
|
||||
|
||||
@Component({
|
||||
selector: 'superAdmin-guild-layout',
|
||||
templateUrl: './layout.component.html',
|
||||
imports: [PageLoadingComponent, RouterOutlet],
|
||||
})
|
||||
export class GuildLayoutComponent {
|
||||
private readonly store = inject(PartnerStore);
|
||||
private readonly route = inject(ActivatedRoute);
|
||||
|
||||
readonly partnerId = signal<string>(this.route.snapshot.paramMap.get('partnerId')!);
|
||||
|
||||
readonly loading = computed(() => this.store.loading());
|
||||
readonly partner = computed(() => this.store.entity());
|
||||
|
||||
getData() {
|
||||
this.store.getData(this.partnerId());
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.getData();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
const baseUrl = (partnerId: string) => `/api/v1/admin/partners/${partnerId}/accounts`;
|
||||
|
||||
export const PARTNER_ACCOUNTS_API_ROUTES = {
|
||||
list: (partnerId: string) => `${baseUrl(partnerId)}`,
|
||||
single: (partnerId: string, accountId: string) => `${baseUrl(partnerId)}/${accountId}`,
|
||||
};
|
||||
@@ -0,0 +1,8 @@
|
||||
export * from './accounts';
|
||||
|
||||
const baseUrl = '/api/v1/admin/partners';
|
||||
|
||||
export const PARTNERS_API_ROUTES = {
|
||||
list: () => `${baseUrl}`,
|
||||
single: (id: string) => `${baseUrl}/${id}`,
|
||||
};
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './apiRoutes';
|
||||
export * from './routes';
|
||||
@@ -0,0 +1,39 @@
|
||||
import { NamedRoutes } from '@/core';
|
||||
import { Routes } from '@angular/router';
|
||||
|
||||
export type TPartnersRouteNames = 'partners' | 'partner';
|
||||
|
||||
export const superAdminPartnersNamedRoutes: NamedRoutes<TPartnersRouteNames> = {
|
||||
partners: {
|
||||
path: 'partners',
|
||||
loadComponent: () => import('../../views/list.component').then((m) => m.PartnersComponent),
|
||||
meta: {
|
||||
title: 'شرکای تجاری',
|
||||
pagePath: () => '/super_admin/partners',
|
||||
},
|
||||
},
|
||||
partner: {
|
||||
path: 'partners/:partnerId',
|
||||
loadComponent: () => import('../../views/single.component').then((m) => m.PartnerComponent),
|
||||
meta: {
|
||||
title: 'شریک تجاری',
|
||||
pagePath: (guildId: string) => `/super_admin/partners/${guildId}`,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const SUPER_ADMIN_PARTNERS_ROUTES: Routes = [
|
||||
superAdminPartnersNamedRoutes.partners,
|
||||
{
|
||||
path: 'partners/:partnerId',
|
||||
loadComponent: () =>
|
||||
import('../../components/layout.component').then((m) => m.GuildLayoutComponent),
|
||||
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
loadComponent: () => import('../../views/single.component').then((m) => m.PartnerComponent),
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,13 @@
|
||||
import { TAccountType } from '@/core/constants/accountTypes.const';
|
||||
|
||||
export interface IPartnerAccountRawResponse {
|
||||
username: string;
|
||||
id: string;
|
||||
}
|
||||
export interface IPartnerAccountResponse extends IPartnerAccountRawResponse {}
|
||||
|
||||
export interface IPartnerAccountRequest {
|
||||
username: string;
|
||||
password?: string;
|
||||
type: TAccountType;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './accounts_io';
|
||||
export * from './io';
|
||||
@@ -0,0 +1,14 @@
|
||||
export interface IPartnerRawResponse {
|
||||
id: string;
|
||||
name: string;
|
||||
code: string;
|
||||
remained_license: number;
|
||||
license_quota: number;
|
||||
}
|
||||
export interface IPartnerResponse extends IPartnerRawResponse {}
|
||||
|
||||
export interface IPartnerRequest {
|
||||
name: string;
|
||||
code: string;
|
||||
license_quota: number;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { IPaginatedResponse } from '@/core/models/service.model';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { PARTNER_ACCOUNTS_API_ROUTES } from '../constants';
|
||||
import {
|
||||
IPartnerAccountRawResponse,
|
||||
IPartnerAccountRequest,
|
||||
IPartnerAccountResponse,
|
||||
} from '../models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class AdminPartnerAccountsService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
private apiRoutes = PARTNER_ACCOUNTS_API_ROUTES;
|
||||
|
||||
getAll(partnerId: string): Observable<IPaginatedResponse<IPartnerAccountResponse>> {
|
||||
return this.http.get<IPaginatedResponse<IPartnerAccountRawResponse>>(
|
||||
this.apiRoutes.list(partnerId),
|
||||
);
|
||||
}
|
||||
getSingle(partnerId: string, accountId: string): Observable<IPartnerAccountResponse> {
|
||||
return this.http.get<IPartnerAccountRawResponse>(this.apiRoutes.single(partnerId, accountId));
|
||||
}
|
||||
|
||||
create(partnerId: string, data: IPartnerAccountRequest): Observable<IPartnerAccountResponse> {
|
||||
return this.http.post<IPartnerAccountResponse>(this.apiRoutes.list(partnerId), data);
|
||||
}
|
||||
|
||||
update(
|
||||
partnerId: string,
|
||||
accountId: string,
|
||||
data: IPartnerAccountRequest,
|
||||
): Observable<IPartnerAccountResponse> {
|
||||
return this.http.patch<IPartnerAccountResponse>(
|
||||
this.apiRoutes.single(partnerId, accountId),
|
||||
data,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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 { PARTNERS_API_ROUTES } from '../constants';
|
||||
import { IPartnerRawResponse, IPartnerRequest, IPartnerResponse } from '../models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class PartnersService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
private apiRoutes = PARTNERS_API_ROUTES;
|
||||
|
||||
getAll(): Observable<IPaginatedResponse<IPartnerResponse>> {
|
||||
return this.http.get<IPaginatedResponse<IPartnerRawResponse>>(this.apiRoutes.list());
|
||||
}
|
||||
getSingle(userId: string): Observable<IPartnerResponse> {
|
||||
return this.http.get<IPartnerRawResponse>(this.apiRoutes.single(userId));
|
||||
}
|
||||
|
||||
create(userData: IPartnerRequest): Observable<IPartnerResponse> {
|
||||
return this.http.post<IPartnerResponse>(this.apiRoutes.list(), userData);
|
||||
}
|
||||
|
||||
update(userId: string, userData: IPartnerRequest): Observable<IPartnerResponse> {
|
||||
return this.http.patch<IPartnerResponse>(this.apiRoutes.single(userId), userData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<uikit-field [label]="label" [control]="control" [showLabel]="showLabel" [showErrors]="showErrors">
|
||||
<p-select
|
||||
[loading]="loading()"
|
||||
[options]="items()"
|
||||
optionLabel="name"
|
||||
[optionValue]="selectOptionValue"
|
||||
placeholder="انتخاب شریک تجاری"
|
||||
[formControl]="control"
|
||||
[showClear]="showClear"
|
||||
[filter]="true"
|
||||
appendTo="body"
|
||||
>
|
||||
@if (canInsert) {
|
||||
<ng-template #footer>
|
||||
<div class="p-3">
|
||||
<p-button
|
||||
label="افزودن شریک تجاری"
|
||||
fluid
|
||||
severity="secondary"
|
||||
text
|
||||
size="small"
|
||||
icon="pi pi-plus"
|
||||
(onClick)="onOpenForm()"
|
||||
/>
|
||||
</div>
|
||||
</ng-template>
|
||||
}
|
||||
</p-select>
|
||||
<partner-form [(visible)]="isOpenFormDialog" (onSubmit)="refresh()" />
|
||||
</uikit-field>
|
||||
@@ -0,0 +1,32 @@
|
||||
import { IPaginatedResponse } from '@/core/models/service.model';
|
||||
import { AbstractSelectComponent } from '@/shared/abstractClasses';
|
||||
import { UikitFieldComponent } from '@/uikit';
|
||||
import { Component, inject, Input } from '@angular/core';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { Button } from 'primeng/button';
|
||||
import { Select } from 'primeng/select';
|
||||
import { GuildFormComponent } from '../components/form.component';
|
||||
import { IPartnerResponse } from '../models';
|
||||
import { PartnersService } from '../services/main.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-partner-select',
|
||||
templateUrl: './select.component.html',
|
||||
imports: [UikitFieldComponent, Select, Button, ReactiveFormsModule, GuildFormComponent],
|
||||
})
|
||||
export class PartnerSelectComponent extends AbstractSelectComponent<
|
||||
IPartnerResponse,
|
||||
IPaginatedResponse<IPartnerResponse>
|
||||
> {
|
||||
@Input() override showClear: boolean = false;
|
||||
@Input() label: string = '';
|
||||
private readonly service = inject(PartnersService);
|
||||
|
||||
ngOnInit() {
|
||||
this.getData();
|
||||
}
|
||||
|
||||
getDataService() {
|
||||
return this.service.getAll();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { EntityState, EntityStore } from '@/core/state';
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { catchError, finalize, throwError } from 'rxjs';
|
||||
import { IPartnerResponse } from '../models';
|
||||
import { PartnersService } from '../services/main.service';
|
||||
|
||||
interface PartnerState extends EntityState<IPartnerResponse> {}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class PartnerStore extends EntityStore<IPartnerResponse, PartnerState> {
|
||||
private readonly service = inject(PartnersService);
|
||||
constructor() {
|
||||
super({
|
||||
loading: false,
|
||||
error: null,
|
||||
entity: null,
|
||||
initialized: false,
|
||||
isRefreshing: false,
|
||||
});
|
||||
}
|
||||
|
||||
getData(partnerId: string) {
|
||||
this.patchState({ loading: true });
|
||||
this.service
|
||||
.getSingle(partnerId)
|
||||
.pipe(
|
||||
finalize(() => {
|
||||
this.patchState({ loading: false });
|
||||
}),
|
||||
catchError(() => {
|
||||
this.patchState({
|
||||
error: '',
|
||||
});
|
||||
return throwError('');
|
||||
}),
|
||||
)
|
||||
.subscribe((entity) => {
|
||||
this.patchState({ entity });
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from './list.component';
|
||||
@@ -0,0 +1 @@
|
||||
<superAdmin-partner-account-list [partnerId]="partnerId()" />
|
||||
@@ -0,0 +1,41 @@
|
||||
// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
|
||||
import { BreadcrumbService } from '@/core/services';
|
||||
import { Component, inject, signal } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { superAdminConsumerAccountsNamedRoutes } from '../../../consumers/constants/routes/accounts';
|
||||
import { ConsumerAccountListComponent } from '../../components/accounts/list.component';
|
||||
import { superAdminPartnersNamedRoutes } from '../../constants';
|
||||
import { PartnerStore } from '../../store/partner.store';
|
||||
|
||||
@Component({
|
||||
selector: 'superAdmin-partner-accounts',
|
||||
templateUrl: './list.component.html',
|
||||
imports: [ConsumerAccountListComponent],
|
||||
})
|
||||
export class ConsumerAccountsComponent {
|
||||
private readonly route = inject(ActivatedRoute);
|
||||
private readonly breadcrumbService = inject(BreadcrumbService);
|
||||
private readonly store = inject(PartnerStore);
|
||||
|
||||
partnerId = signal<string>(this.route.snapshot.params['partnerId']);
|
||||
|
||||
ngOnInit() {
|
||||
this.setBreadcrumb();
|
||||
}
|
||||
|
||||
setBreadcrumb() {
|
||||
this.breadcrumbService.setItems([
|
||||
{
|
||||
...superAdminPartnersNamedRoutes.partners.meta,
|
||||
routerLink: superAdminPartnersNamedRoutes.partners.meta.pagePath!(),
|
||||
},
|
||||
{
|
||||
title: this.store.entity()?.name,
|
||||
routerLink: superAdminPartnersNamedRoutes.partner.meta.pagePath!(this.partnerId()),
|
||||
},
|
||||
{
|
||||
title: superAdminConsumerAccountsNamedRoutes.accounts.meta.title,
|
||||
},
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export * from './accounts';
|
||||
export * from './list.component';
|
||||
export * from './single.component';
|
||||
@@ -0,0 +1,23 @@
|
||||
<app-page-data-list
|
||||
pageTitle="مدیریت شرکای تجاری"
|
||||
[addNewCtaLabel]="'افزودن شریک تجاری جدید'"
|
||||
[columns]="columns"
|
||||
[showAdd]="true"
|
||||
emptyPlaceholderTitle="شریک تجاریای یافت نشد"
|
||||
emptyPlaceholderDescription="برای افزودن شریک تجاری جدید، روی دکمهٔ بالا کلیک کنید."
|
||||
[items]="items()"
|
||||
[loading]="loading()"
|
||||
[showDetails]="true"
|
||||
[showAdd]="true"
|
||||
[showEdit]="true"
|
||||
(onAdd)="openAddForm()"
|
||||
(onDetails)="toSinglePage($event)"
|
||||
(onEdit)="onEditClick($event)"
|
||||
/>
|
||||
<partner-form
|
||||
[(visible)]="visibleForm"
|
||||
[editMode]="editMode()"
|
||||
[partnerId]="selectedItemForEdit()?.id"
|
||||
[initialValues]="selectedItemForEdit() || undefined"
|
||||
(onSubmit)="refresh()"
|
||||
/>
|
||||
@@ -0,0 +1,41 @@
|
||||
// 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 { Router } from '@angular/router';
|
||||
import { GuildFormComponent } from '../components/form.component';
|
||||
import { superAdminPartnersNamedRoutes } from '../constants';
|
||||
import { IPartnerResponse } from '../models';
|
||||
import { PartnersService } from '../services/main.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-users',
|
||||
templateUrl: './list.component.html',
|
||||
imports: [PageDataListComponent, GuildFormComponent],
|
||||
})
|
||||
export class PartnersComponent extends AbstractList<IPartnerResponse> {
|
||||
private readonly service = inject(PartnersService);
|
||||
private readonly router = inject(Router);
|
||||
|
||||
override setColumns(): void {
|
||||
this.columns = [
|
||||
{ field: 'id', header: 'شناسه' },
|
||||
{ field: 'name', header: 'نام' },
|
||||
{ field: 'code', header: 'کد' },
|
||||
{ field: 'license_quota', header: 'تعداد لایسنس خریداری شده' },
|
||||
{
|
||||
field: 'created_at',
|
||||
header: 'تاریخ ایجاد',
|
||||
type: 'date',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
override getDataRequest() {
|
||||
return this.service.getAll();
|
||||
}
|
||||
|
||||
toSinglePage(partner: IPartnerResponse) {
|
||||
this.router.navigateByUrl(superAdminPartnersNamedRoutes.partner.meta.pagePath!(partner.id));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<div class="flex flex-col gap-6">
|
||||
<app-card-data cardTitle="اطلاعات شریک تجاری" [editable]="true" [(editMode)]="editMode">
|
||||
<ng-template #moreAction> </ng-template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<div class="grid grid-cols-3 gap-4 items-center">
|
||||
<app-key-value label="عنوان شریک تجاری" [value]="partner()?.name" />
|
||||
<app-key-value label="کد شریک تجاری" [value]="partner()?.code" />
|
||||
<app-key-value label="تعداد لایسنسهای خریداری شده" [value]="partner()?.license_quota + ''" />
|
||||
<app-key-value label="تعداد لایسنسهای باقیمانده" [value]="partner()?.remained_license + ''" />
|
||||
</div>
|
||||
</div>
|
||||
</app-card-data>
|
||||
|
||||
<superAdmin-partner-account-list [partnerId]="partnerId()" />
|
||||
|
||||
<partner-form
|
||||
[(visible)]="editMode"
|
||||
[editMode]="true"
|
||||
[partnerId]="partnerId()"
|
||||
[initialValues]="partner() || undefined"
|
||||
(onSubmit)="getData()"
|
||||
/>
|
||||
</div>
|
||||
@@ -0,0 +1,49 @@
|
||||
import { BreadcrumbService } from '@/core/services';
|
||||
import { AppCardComponent, KeyValueComponent } from '@/shared/components';
|
||||
import { Component, computed, effect, inject, signal } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { ConsumerAccountListComponent } from '../components/accounts/list.component';
|
||||
import { GuildFormComponent } from '../components/form.component';
|
||||
import { superAdminPartnersNamedRoutes } from '../constants';
|
||||
import { PartnerStore } from '../store/partner.store';
|
||||
|
||||
@Component({
|
||||
selector: 'app-user',
|
||||
templateUrl: './single.component.html',
|
||||
imports: [AppCardComponent, KeyValueComponent, GuildFormComponent, ConsumerAccountListComponent],
|
||||
})
|
||||
export class PartnerComponent {
|
||||
private readonly store = inject(PartnerStore);
|
||||
private readonly route = inject(ActivatedRoute);
|
||||
private readonly breadcrumbService = inject(BreadcrumbService);
|
||||
|
||||
readonly partnerId = signal<string>(this.route.snapshot.paramMap.get('partnerId')!);
|
||||
editMode = signal<boolean>(false);
|
||||
|
||||
readonly loading = computed(() => this.store.loading());
|
||||
readonly partner = computed(() => this.store.entity());
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
if (this.partner()?.id) {
|
||||
this.setBreadcrumb();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getData() {
|
||||
this.store.getData(this.partnerId());
|
||||
}
|
||||
|
||||
setBreadcrumb() {
|
||||
this.breadcrumbService.setItems([
|
||||
{
|
||||
...superAdminPartnersNamedRoutes.partners.meta,
|
||||
routerLink: superAdminPartnersNamedRoutes.partners.meta.pagePath!(),
|
||||
},
|
||||
{
|
||||
title: this.partner()?.name,
|
||||
},
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user