feat(consumers): implement consumer and POS stores with breadcrumb management

- Added ConsumerStore and PosStore to manage state and data fetching for consumers and POS entities.
- Implemented breadcrumb functionality in both stores to enhance navigation.
- Created views for consumer accounts, business activities, complexes, and poses with respective components.
- Developed single view components for detailed display and editing of consumer and POS data.
- Introduced charge account management components in the super admin module, including forms and lists for charge transactions.
- Established API routes and services for handling charge account transactions.
This commit is contained in:
2026-04-23 20:59:48 +03:30
parent 57f333f5b8
commit e58bcbef57
119 changed files with 2917 additions and 52 deletions
@@ -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.role" name="role" type="consumerRole" />
<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,78 @@
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 { IConsumerAccountRequest, IConsumerAccountResponse } from '../../models';
import { PartnerConsumerAccountsService } from '../../services/accounts.service';
@Component({
selector: 'partner-consumer-account-form',
templateUrl: './form.component.html',
imports: [
ReactiveFormsModule,
Dialog,
InputComponent,
FormFooterActionsComponent,
UikitFieldComponent,
Password,
EnumSelectComponent,
],
})
export class ConsumerAccountFormComponent extends AbstractFormDialog<
IConsumerAccountRequest,
IConsumerAccountResponse
> {
private readonly service = inject(PartnerConsumerAccountsService);
@Input({ required: true }) consumerId!: string;
@Input() accountId!: string;
initForm = () => {
if (this.editMode) {
return this.fb.group(
{
username: [this.initialValues?.username || '', [Validators.required]],
password: ['', [password()]],
confirmPassword: [''],
},
{
validators: [MustMatch('password', 'confirmPassword')],
},
);
}
return this.fb.group(
{
username: [this.initialValues?.username || '', [Validators.required]],
role: ['', [Validators.required]],
password: ['', [Validators.required, password()]],
confirmPassword: ['', [Validators.required]],
},
{
validators: [MustMatch('password', 'confirmPassword')],
},
) as any;
};
form = this.initForm();
override ngOnChanges(): void {
this.form = this.initForm();
}
submitForm() {
const formValue = this.form.value as IConsumerAccountRequest;
// @ts-ignore
const { confirmPassword, ...rest } = formValue;
if (this.editMode) {
return this.service.update(this.consumerId, this.accountId, rest);
}
return this.service.create(this.consumerId, 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>
<partner-consumer-account-form
[(visible)]="visibleForm"
[editMode]="editMode()"
[consumerId]="consumerId"
[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 { IConsumerAccountResponse } from '../../models';
import { PartnerConsumerAccountsService } from '../../services/accounts.service';
import { ConsumerAccountFormComponent } from './form.component';
@Component({
selector: 'partner-consumer-account-list',
templateUrl: './list.component.html',
imports: [PageDataListComponent, ConsumerAccountFormComponent],
})
export class ConsumerAccountListComponent extends AbstractList<IConsumerAccountResponse> {
@Input({ required: true }) consumerId!: string;
@Input() fullHeight?: boolean;
@Input() header: IColumn[] = [
{ field: 'id', header: 'شناسه', type: 'id' },
{
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(PartnerConsumerAccountsService);
override setColumns(): void {
this.columns = this.header;
}
override getDataRequest() {
return this.service.getAll(this.consumerId);
}
}
@@ -0,0 +1,15 @@
<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.economic_code" name="economic_code" />
<catalog-guild-select label="صنف" [control]="form.controls.guild_id" name="guild_id" />
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="submitLoading()" (onCancel)="close()" />
</form>
</p-dialog>
@@ -0,0 +1,57 @@
// import { CatalogRolesComponent } from '@/shared/catalog/roles';
import { AbstractFormDialog } from '@/shared/abstractClasses';
import { CatalogGuildSelectComponent } from '@/shared/catalog/guild/components/select.component';
import { InputComponent } from '@/shared/components';
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
import { Component, inject, Input } from '@angular/core';
import { ReactiveFormsModule, Validators } from '@angular/forms';
import { Dialog } from 'primeng/dialog';
import { IBusinessActivityRequest, IBusinessActivityResponse } from '../../models';
import { PartnerConsumerBusinessActivitiesService } from '../../services/businessActivities.service';
@Component({
selector: 'partner-consumer-businessActivities-form',
templateUrl: './form.component.html',
imports: [
ReactiveFormsModule,
Dialog,
InputComponent,
FormFooterActionsComponent,
CatalogGuildSelectComponent,
],
})
export class ConsumerBusinessActivitiesFormComponent extends AbstractFormDialog<
IBusinessActivityRequest,
IBusinessActivityResponse
> {
private readonly service = inject(PartnerConsumerBusinessActivitiesService);
@Input({ required: true }) consumerId!: string;
@Input() businessActivityId!: string;
initForm = () => {
return this.fb.group({
name: [this.initialValues?.name || '', [Validators.required]],
economic_code: [this.initialValues?.economic_code || '', [Validators.required]],
guild_id: [this.initialValues?.guild?.id || '', [Validators.required]],
});
};
form = this.initForm();
get preparedTitle() {
return `${this.editMode ? 'ویرایش' : 'ایجاد'} فعالیت اقتصادی`;
}
override ngOnChanges(): void {
this.form = this.initForm();
}
submitForm() {
const formValue = this.form.value as IBusinessActivityRequest;
if (this.editMode) {
return this.service.update(this.consumerId, this.businessActivityId, formValue);
}
return this.service.create(this.consumerId, formValue);
}
}
@@ -0,0 +1,5 @@
@if (loading()) {
<shared-page-loading />
} @else {
<router-outlet></router-outlet>
}
@@ -0,0 +1,30 @@
import { PageLoadingComponent } from '@/shared/components/page-loading.component';
import pageParamsUtils from '@/utils/page-params.utils';
import { Component, computed, inject } from '@angular/core';
import { ActivatedRoute, RouterOutlet } from '@angular/router';
import { BusinessActivityStore } from '../../store/businessActivity.store';
@Component({
selector: 'partner-user-businessActivity-layout',
templateUrl: './layout.component.html',
imports: [PageLoadingComponent, RouterOutlet],
})
export class PartnerUserBusinessActivityLayoutComponent {
private readonly store = inject(BusinessActivityStore);
private readonly route = inject(ActivatedRoute);
readonly loading = computed(() => this.store.loading());
readonly businessActivity = computed(() => this.store.entity());
readonly pageParams = computed(() => pageParamsUtils(this.route));
readonly consumerId = computed(() => this.pageParams()['consumerId']!);
readonly businessId = computed(() => this.pageParams()['businessActivityId']!);
getData() {
this.store.getData(this.consumerId(), this.businessId());
}
ngOnInit() {
this.getData();
}
}
@@ -0,0 +1,25 @@
<app-page-data-list
pageTitle="مدیریت فعالیت‌های اقتصادی"
[addNewCtaLabel]="'افزودن فعالیت اقتصادی جدید'"
[columns]="columns"
[showAdd]="true"
emptyPlaceholderTitle="فعالیت اقتصادی‌ای یافت نشد."
emptyPlaceholderDescription="برای افزودن فعالیت اقتصادی جدید، روی دکمهٔ بالا کلیک کنید."
[items]="items()"
[loading]="loading()"
[showDetails]="true"
[showAdd]="true"
[showEdit]="true"
(onAdd)="openAddForm()"
(onEdit)="onEditClick($event)"
(onDetails)="toSinglePage($event)"
>
</app-page-data-list>
<partner-consumer-businessActivities-form
[(visible)]="visibleForm"
[editMode]="editMode()"
[consumerId]="consumerId"
[businessActivityId]="selectedItemForEdit()?.id || ''"
[initialValues]="selectedItemForEdit() || undefined"
(onSubmit)="refresh()"
/>
@@ -0,0 +1,52 @@
// 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 { Router } from '@angular/router';
import { partnerConsumerBusinessActivitiesNamedRoutes } from '../../constants/routes/businessActivities';
import { IBusinessActivityResponse } from '../../models';
import { PartnerConsumerBusinessActivitiesService } from '../../services/businessActivities.service';
import { ConsumerBusinessActivitiesFormComponent } from './form.component';
@Component({
selector: 'partner-consumer-businessActivities-list',
templateUrl: './list.component.html',
imports: [PageDataListComponent, ConsumerBusinessActivitiesFormComponent],
})
export class ConsumerBusinessActivitiesComponent extends AbstractList<IBusinessActivityResponse> {
@Input({ required: true }) consumerId!: string;
@Input() fullHeight?: boolean;
@Input() header: IColumn[] = [
{ field: 'id', header: 'شناسه', type: 'id' },
{ field: 'name', header: 'عنوان' },
{ field: 'guild', header: 'صنف', type: 'nested', nestedPath: 'name' },
{
field: 'created_at',
header: 'تاریخ ایجاد',
type: 'date',
},
];
private readonly service = inject(PartnerConsumerBusinessActivitiesService);
private readonly router = inject(Router);
override setColumns(): void {
this.columns = this.header;
}
override getDataRequest() {
return this.service.getAll(this.consumerId);
}
toSinglePage(item: IBusinessActivityResponse) {
this.router.navigateByUrl(
partnerConsumerBusinessActivitiesNamedRoutes.businessActivity.meta.pagePath!(
this.consumerId,
item.id,
),
);
}
}
@@ -0,0 +1,15 @@
<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.branch_code" name="branch_code" />
<app-input label="آدرس" [control]="form.controls.address" name="address" />
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="submitLoading()" (onCancel)="close()" />
</form>
</p-dialog>
@@ -0,0 +1,56 @@
// import { CatalogRolesComponent } from '@/shared/catalog/roles';
import { AbstractFormDialog } from '@/shared/abstractClasses';
import { InputComponent } from '@/shared/components';
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
import { Component, inject, Input } from '@angular/core';
import { ReactiveFormsModule, Validators } from '@angular/forms';
import { Dialog } from 'primeng/dialog';
import { IComplexRequest, IComplexResponse } from '../../models';
import { PartnerComplexesService } from '../../services/complexes.service';
@Component({
selector: 'partner-consumer-complex-form',
templateUrl: './form.component.html',
imports: [ReactiveFormsModule, Dialog, InputComponent, FormFooterActionsComponent],
})
export class ConsumerComplexFormComponent extends AbstractFormDialog<
IComplexRequest,
IComplexResponse
> {
private readonly service = inject(PartnerComplexesService);
@Input({ required: true }) consumerId!: string;
@Input() businessActivityId!: string;
@Input() complexId!: string;
initForm = () => {
return this.fb.group({
name: [this.initialValues?.name || '', [Validators.required]],
branch_code: [this.initialValues?.branch_code || ''],
address: [this.initialValues?.address || '', [Validators.required]],
});
};
form = this.initForm();
get preparedTitle() {
return `${this.editMode ? 'ویرایش' : 'ایجاد'} شعبه`;
}
override ngOnChanges(): void {
this.form = this.initForm();
}
submitForm() {
const formValue = this.form.value as IComplexRequest;
if (this.editMode) {
return this.service.update(
this.consumerId,
this.businessActivityId,
this.complexId,
formValue,
);
}
return this.service.create(this.consumerId, this.businessActivityId, formValue);
}
}
@@ -0,0 +1,5 @@
@if (loading()) {
<shared-page-loading />
} @else {
<router-outlet></router-outlet>
}
@@ -0,0 +1,30 @@
import { PageLoadingComponent } from '@/shared/components/page-loading.component';
import pageParamsUtils from '@/utils/page-params.utils';
import { Component, computed, inject } from '@angular/core';
import { ActivatedRoute, RouterOutlet } from '@angular/router';
import { ComplexStore } from '../../store/complex.store';
@Component({
selector: 'partner-consumer-complex-layout',
templateUrl: './layout.component.html',
imports: [PageLoadingComponent, RouterOutlet],
})
export class PartnerConsumerComplexLayoutComponent {
private readonly store = inject(ComplexStore);
private readonly route = inject(ActivatedRoute);
readonly loading = computed(() => this.store.loading());
readonly pageParams = computed(() => pageParamsUtils(this.route));
readonly consumerId = computed(() => this.pageParams()['consumerId']!);
readonly businessId = computed(() => this.pageParams()['businessActivityId']!);
readonly complexId = computed(() => this.pageParams()['complexId']!);
getData() {
this.store.getData(this.consumerId(), this.businessId(), this.complexId());
}
ngOnInit() {
this.getData();
}
}
@@ -0,0 +1,26 @@
<app-page-data-list
pageTitle="مدیریت شعب"
[addNewCtaLabel]="'افزودن شعبه‌ جدید'"
[columns]="columns"
[showAdd]="true"
emptyPlaceholderTitle="شعبه‌ای یافت نشد."
emptyPlaceholderDescription="برای افزودن شعبه‌ جدید، روی دکمهٔ بالا کلیک کنید."
[items]="items()"
[loading]="loading()"
[showDetails]="true"
[showAdd]="true"
[showEdit]="true"
(onAdd)="openAddForm()"
(onEdit)="onEditClick($event)"
(onDetails)="toSinglePage($event)"
>
</app-page-data-list>
<partner-consumer-complex-form
[(visible)]="visibleForm"
[editMode]="editMode()"
[consumerId]="consumerId"
[businessActivityId]="businessId"
[complexId]="selectedItemForEdit()?.id || ''"
[initialValues]="selectedItemForEdit() || undefined"
(onSubmit)="refresh()"
/>
@@ -0,0 +1,53 @@
// 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 { Router } from '@angular/router';
import { partnerConsumerComplexesNamedRoutes } from '../../constants/routes/complexes';
import { IComplexResponse } from '../../models';
import { PartnerComplexesService } from '../../services/complexes.service';
import { ConsumerComplexFormComponent } from './form.component';
@Component({
selector: 'partner-consumer-complexes-list',
templateUrl: './list.component.html',
imports: [PageDataListComponent, ConsumerComplexFormComponent],
})
export class ConsumerComplexesComponent extends AbstractList<IComplexResponse> {
@Input() consumerId!: string;
@Input() businessId!: string;
@Input() fullHeight?: boolean;
@Input() header: IColumn[] = [
{ field: 'id', header: 'شناسه', type: 'id' },
{ field: 'name', header: 'عنوان' },
{
field: 'created_at',
header: 'تاریخ ایجاد',
type: 'date',
},
];
private readonly service = inject(PartnerComplexesService);
private readonly router = inject(Router);
override setColumns(): void {
this.columns = this.header;
}
override getDataRequest() {
return this.service.getAll(this.consumerId, this.businessId);
}
toSinglePage(item: IComplexResponse) {
this.router.navigateByUrl(
partnerConsumerComplexesNamedRoutes.complex.meta.pagePath!(
this.consumerId,
this.businessId,
item.id,
),
);
}
}
@@ -0,0 +1,58 @@
<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.first_name" name="first_name" />
<app-input label="نام خانوادگی" [control]="form.controls.last_name" name="last_name" />
<app-input label="موبایل" [control]="form.controls.mobile_number" name="mobile_number" type="mobile" />
<app-input label="کد ملی" [control]="form.controls.national_code" name="national_code" type="nationalId" />
@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>
<p-divider align="center"> اطلاعات لایسنس </p-divider>
<uikit-datepicker
label="تاریخ شروع لایسنس"
[control]="form.controls.license_starts_at"
name="license_starts_at"
hint="مدت زمان لایسنس‌ها ۱ ساله هستند."
/>
}
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="submitLoading()" (onCancel)="close()" />
</form>
</p-dialog>
@@ -0,0 +1,121 @@
import { mobileValidator, MustMatch } from '@/core/validators';
import { nationalIdValidator } from '@/core/validators/national-id.validator';
import { AbstractFormDialog } from '@/shared/abstractClasses';
import { InputComponent } from '@/shared/components';
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
import { UikitFieldComponent, UikitFlatpickrJalaliComponent } from '@/uikit';
import { nowJalali } from '@/utils';
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 { IConsumerRequest, IConsumerResponse } from '../models';
import { ConsumersService } from '../services/main.service';
@Component({
selector: 'partner-consumer-form',
templateUrl: './form.component.html',
imports: [
ReactiveFormsModule,
Dialog,
InputComponent,
FormFooterActionsComponent,
Divider,
UikitFieldComponent,
Password,
UikitFlatpickrJalaliComponent,
],
})
export class ConsumerUserFormComponent extends AbstractFormDialog<
IConsumerRequest,
IConsumerResponse
> {
@Input() consumerId?: string;
private service = inject(ConsumersService);
preparedTitle = computed(() => `${this.editMode ? 'ویرایش' : 'ایجاد'} مشتری`);
initForm = () => {
const form = this.fb.group({
first_name: [this.initialValues?.first_name || '', [Validators.required]],
last_name: [this.initialValues?.last_name || '', [Validators.required]],
mobile_number: [
this.initialValues?.mobile_number || '',
[Validators.required, mobileValidator()],
],
national_code: [
this.initialValues?.national_code || '',
[Validators.required, nationalIdValidator()],
],
username: [''],
password: [''],
confirmPassword: [''],
license_starts_at: [nowJalali(), [Validators.required]],
});
if (this.editMode) {
// @ts-ignore
form.removeControl('username');
// @ts-ignore
form.removeControl('password');
// @ts-ignore
form.removeControl('confirmPassword');
// @ts-ignore
form.removeControl('license_starts_at');
form.removeValidators([MustMatch('password', 'confirmPassword')]);
} else {
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.addControl(
'license_starts_at',
this.fb.control<string>(nowJalali(), {
nonNullable: true,
validators: [Validators.required],
}),
);
form.addValidators([MustMatch('password', 'confirmPassword')]);
}
return form;
};
form = this.initForm();
override ngOnChanges() {
this.form.patchValue(this.initialValues || {});
if (this.editMode && !this.consumerId) {
throw 'missing some arguments';
}
this.form = this.initForm();
}
override submitForm(payload: IConsumerRequest) {
if (this.editMode) {
return this.service.update(this.consumerId!, 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 { ConsumerStore } from '../store/consumer.store';
@Component({
selector: 'partner-consumer-layout',
templateUrl: './layout.component.html',
imports: [PageLoadingComponent, RouterOutlet],
})
export class ConsumerLayoutComponent {
private readonly store = inject(ConsumerStore);
private readonly route = inject(ActivatedRoute);
readonly consumerId = signal<string>(this.route.snapshot.paramMap.get('consumerId')!);
readonly loading = computed(() => this.store.loading());
readonly consumer = computed(() => this.store.entity());
getData() {
this.store.getData(this.consumerId());
}
ngOnInit() {
this.getData();
}
}
@@ -0,0 +1,19 @@
<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">
<uikit-datepicker
label="تاریخ شروع لایسنس"
[control]="form.controls.starts_at"
name="starts_at"
hint="مدت زمان لایسنس‌ها ۱ ساله هستند."
/>
<!-- <uikit-datepicker label="تاریخ انقضای لایسنس" [control]="form.controls.expires_at" name="expires_at" /> -->
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="submitLoading()" (onCancel)="close()" />
</form>
</p-dialog>
@@ -0,0 +1,51 @@
import { AbstractFormDialog } from '@/shared/abstractClasses';
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
import { UikitFlatpickrJalaliComponent } from '@/uikit';
import { Component, computed, inject, Input } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { Dialog } from 'primeng/dialog';
import { ILicenseRequest, ILicenseResponse } from '../../models';
import { LicensesService } from '../../services/licenses.service';
@Component({
selector: 'partner-consumer-license-form',
templateUrl: './form.component.html',
imports: [ReactiveFormsModule, Dialog, FormFooterActionsComponent, UikitFlatpickrJalaliComponent],
})
export class ConsumerLicenseFormComponent extends AbstractFormDialog<
ILicenseRequest,
ILicenseResponse
> {
@Input({ required: true }) consumerId!: string;
@Input() licenseId?: string;
private service = inject(LicensesService);
preparedTitle = computed(() => `${this.editMode ? 'ویرایش' : 'ایجاد'} لایسنس`);
initForm = () => {
const form = this.fb.group({
starts_at: [this.initialValues?.starts_at || ''],
partner_id: [this.initialValues?.partner?.id || ''],
});
return form;
};
form = this.initForm();
override ngOnChanges() {
this.form.patchValue({ ...this.initialValues });
if (this.editMode && !this.licenseId) {
throw 'missing some arguments';
}
this.form = this.initForm();
}
override submitForm(payload: ILicenseRequest) {
if (this.editMode) {
return this.service.update(this.consumerId!, this.licenseId!, payload);
}
return this.service.create(this.consumerId, payload);
}
}
@@ -0,0 +1,20 @@
<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.serial" name="serial" />
<!-- <app-input label="مدل دستگاه" [control]="form.controls.model" name="model" /> -->
<app-enum-select [control]="form.controls.pos_type" type="posType" name="pos_type" />
@if (form.controls.pos_type.value === "PSP") {
<catalog-device-select [control]="form.controls.device_id" />
<catalog-provider-select [control]="form.controls.provider_id" />
}
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="submitLoading()" (onCancel)="close()" />
</form>
</p-dialog>
@@ -0,0 +1,87 @@
// import { CatalogRolesComponent } from '@/shared/catalog/roles';
import { AbstractFormDialog } from '@/shared/abstractClasses';
import { EnumSelectComponent } from '@/shared/apiEnum/select.component';
import { CatalogProviderSelectComponent } from '@/shared/catalog';
import { CatalogDeviceSelectComponent } from '@/shared/catalog/devices';
import { InputComponent } from '@/shared/components';
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
import { Component, inject, Input } from '@angular/core';
import { ReactiveFormsModule, Validators } from '@angular/forms';
import { Dialog } from 'primeng/dialog';
import { IPosRequest, IPosResponse } from '../../models';
import { PartnerPosesService } from '../../services/poses.service';
@Component({
selector: 'partner-consumer-pos-form',
templateUrl: './form.component.html',
imports: [
ReactiveFormsModule,
Dialog,
InputComponent,
FormFooterActionsComponent,
CatalogDeviceSelectComponent,
CatalogProviderSelectComponent,
EnumSelectComponent,
],
})
export class ConsumerPosFormComponent extends AbstractFormDialog<IPosRequest, IPosResponse> {
private readonly service = inject(PartnerPosesService);
@Input({ required: true }) consumerId!: string;
@Input({ required: true }) businessActivityId!: string;
@Input({ required: true }) complexId!: string;
@Input() posId!: string;
initForm = () => {
const form = this.fb.group({
name: [this.initialValues?.name || '', [Validators.required]],
serial: [this.initialValues?.serial || '', [Validators.required]],
// model: [this.initialValues?.model || '', [Validators.required]],
pos_type: [this.initialValues?.pos_type || '', [Validators.required]],
device_id: [this.initialValues?.device?.id || ''],
provider_id: [this.initialValues?.provider?.id || ''],
});
form.controls.pos_type.valueChanges.subscribe((value) => {
if (value === 'PSP') {
form.addControl(
'device_id',
this.fb.control<string>(this.initialValues?.device?.id ?? '', {
nonNullable: true,
validators: [Validators.required],
}),
);
form.addControl(
'provider_id',
this.fb.control<string>(this.initialValues?.provider?.id ?? '', {
nonNullable: true,
validators: [Validators.required],
}),
);
} else {
// @ts-ignore
form.removeControl('device_id');
// @ts-ignore
form.removeControl('provider_id');
}
});
return form;
};
form = this.initForm();
get preparedTitle() {
return `${this.editMode ? 'ویرایش' : 'ایجاد'} پایانه فروش`;
}
override ngOnChanges(): void {
this.form = this.initForm();
}
submitForm() {
const formValue = this.form.value as IPosRequest;
if (this.editMode) {
return this.service.update(this.businessActivityId, this.complexId, this.posId, formValue);
}
return this.service.create(this.businessActivityId, this.complexId, formValue);
}
}
@@ -0,0 +1,5 @@
@if (loading()) {
<shared-page-loading />
} @else {
<router-outlet></router-outlet>
}
@@ -0,0 +1,31 @@
import { PageLoadingComponent } from '@/shared/components/page-loading.component';
import pageParamsUtils from '@/utils/page-params.utils';
import { Component, computed, inject } from '@angular/core';
import { ActivatedRoute, RouterOutlet } from '@angular/router';
import { PosStore } from '../../store/pos.store';
@Component({
selector: 'partner-consumer-pos-layout',
templateUrl: './layout.component.html',
imports: [PageLoadingComponent, RouterOutlet],
})
export class PartnerConsumerPosLayoutComponent {
private readonly store = inject(PosStore);
private readonly route = inject(ActivatedRoute);
readonly loading = computed(() => this.store.loading());
readonly pageParams = computed(() => pageParamsUtils(this.route));
readonly consumerId = computed(() => this.pageParams()['consumerId']!);
readonly businessId = computed(() => this.pageParams()['businessActivityId']!);
readonly complexId = computed(() => this.pageParams()['complexId']!);
readonly posId = computed(() => this.pageParams()['posId']!);
getData() {
this.store.getData(this.consumerId(), this.businessId(), this.complexId(), this.posId());
}
ngOnInit() {
this.getData();
}
}
@@ -0,0 +1,27 @@
<app-page-data-list
pageTitle="مدیریت پایانه‌های فروش"
[addNewCtaLabel]="'افزودن پایانه‌ی فروش جدید'"
[columns]="columns"
[showAdd]="true"
emptyPlaceholderTitle="پایانه‌ی فروشی یافت نشد."
emptyPlaceholderDescription="برای افزودن پایانه‌ی فروش جدید، روی دکمهٔ بالا کلیک کنید."
[items]="items()"
[loading]="loading()"
[showDetails]="true"
[showAdd]="true"
[showEdit]="true"
(onAdd)="openAddForm()"
(onEdit)="onEditClick($event)"
(onDetails)="toSinglePage($event)"
>
</app-page-data-list>
<partner-consumer-pos-form
[(visible)]="visibleForm"
[editMode]="editMode()"
[consumerId]="consumerId"
[businessActivityId]="businessId"
[complexId]="complexId"
[posId]="selectedItemForEdit()?.id || ''"
[initialValues]="selectedItemForEdit() || undefined"
(onSubmit)="refresh()"
/>
@@ -0,0 +1,60 @@
// 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 { Router } from '@angular/router';
import { partnerConsumerPosesNamedRoutes } from '../../constants/routes/poses';
import { IPosResponse } from '../../models';
import { PartnerPosesService } from '../../services/poses.service';
import { ConsumerPosFormComponent } from './form.component';
@Component({
selector: 'partner-consumer-poses-list',
templateUrl: './list.component.html',
imports: [PageDataListComponent, ConsumerPosFormComponent],
})
export class ConsumerPosesComponent extends AbstractList<IPosResponse> {
@Input({ required: true }) consumerId!: string;
@Input({ required: true }) businessId!: string;
@Input({ required: true }) complexId!: string;
@Input() fullHeight?: boolean;
@Input() header: IColumn[] = [
{ field: 'id', header: 'شناسه', type: 'id' },
{ field: 'name', header: 'عنوان' },
{ field: 'serial', header: 'شماره سریال' },
{ field: 'device', header: 'دستگاه', type: 'nested', nestedPath: 'device.name' },
{ field: 'pos_type', header: 'نوع دستگاه' },
{ field: 'provider', header: 'ارایه‌دهنده', type: 'nested', nestedPath: 'provider.name' },
{ field: 'status', header: 'وضعیت' },
{
field: 'created_at',
header: 'تاریخ ایجاد',
type: 'date',
},
];
private readonly service = inject(PartnerPosesService);
private readonly router = inject(Router);
override setColumns(): void {
this.columns = this.header;
}
override getDataRequest() {
return this.service.getAll(this.businessId, this.complexId);
}
toSinglePage(item: IPosResponse) {
this.router.navigateByUrl(
partnerConsumerPosesNamedRoutes.pos.meta.pagePath!(
this.consumerId,
this.businessId,
this.complexId,
item.id,
),
);
}
}