create license management

This commit is contained in:
2026-04-06 13:31:30 +03:30
parent 44097fe1ac
commit de1a046485
46 changed files with 819 additions and 366 deletions
@@ -23,6 +23,16 @@ export class ConsumersComponent extends AbstractList<IConsumerResponse> {
{ field: 'fullname', header: 'نام' },
{ field: 'mobile_number', header: 'شماره موبایل' },
{ field: 'status', header: 'وضعیت' },
{
field: 'license_expires_at',
header: 'تاریخ انقضای لایسنس',
customDataModel(item) {
if (item.license) {
return item.license.expires_at;
}
return 'بدون لایسنس';
},
},
{
field: 'created_at',
header: 'تاریخ ایجاد',
@@ -6,6 +6,25 @@
<app-key-value label="نام مشتری" [value]="consumer()?.fullname" />
<app-key-value label="شماره موبایل" [value]="consumer()?.mobile_number" />
<app-key-value label="وضعیت" [value]="consumer()?.status" />
@if (licenseStatus() === "EXPIRED") {
<app-key-value label="وضعیت لایسنس">
<p-button size="small" outlined severity="warn" (onClick)="openLicenseForm()">
منقضی شده در <span [jalaliDate]="license()!.expires_at"></span>
</p-button>
</app-key-value>
<app-key-value label="ارایه شده توسط" [value]="license()?.partner?.name || 'برند نرم‌افزار'" />
} @else if (licenseStatus() === "ACTIVE") {
<app-key-value label="وضعیت لایسنس">
<p-button size="small" outlined severity="success" (onClick)="openLicenseForm()">
تا تاریخ <span [jalaliDate]="license()!.expires_at"></span>
</p-button>
</app-key-value>
<app-key-value label="ارایه شده توسط" [value]="license()?.partner?.name || 'برند نرم‌افزار'" />
} @else {
<app-key-value label="وضعیت لایسنس">
<p-button size="small" outlined severity="danger" (onClick)="openLicenseForm()"> ارایه نشده </p-button>
</app-key-value>
}
</div>
</div>
</app-card-data>
@@ -20,4 +39,13 @@
[initialValues]="consumer() || undefined"
(onSubmit)="getData()"
/>
<superAdmin-consumer-license-form
[(visible)]="visibleLicenseForm"
[editMode]="!!licenseStatus()"
[consumerId]="consumerId()"
[licenseId]="license()?.id"
[initialValues]="license() || undefined"
(onSubmit)="getData()"
/>
</div>
@@ -1,10 +1,14 @@
import { BreadcrumbService } from '@/core/services';
import { AppCardComponent, KeyValueComponent } from '@/shared/components';
import { JalaliDateDirective } from '@/shared/directives';
import { licenseStatus } from '@/shared/localEnum/constants/licenseStatus';
import { Component, computed, effect, inject, signal } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Button } from 'primeng/button';
import { ConsumerAccountListComponent } from '../components/accounts/list.component';
import { ConsumerBusinessActivitiesComponent } from '../components/businessActivities/list.component';
import { ConsumerUserFormComponent } from '../components/form.component';
import { ConsumerLicenseFormComponent } from '../components/licenses/form.component';
import { superAdminConsumersNamedRoutes } from '../constants';
import { ConsumerStore } from '../store/consumer.store';
@@ -17,6 +21,9 @@ import { ConsumerStore } from '../store/consumer.store';
ConsumerUserFormComponent,
ConsumerAccountListComponent,
ConsumerBusinessActivitiesComponent,
Button,
JalaliDateDirective,
ConsumerLicenseFormComponent,
],
})
export class ConsumerComponent {
@@ -27,8 +34,23 @@ export class ConsumerComponent {
readonly consumerId = signal<string>(this.route.snapshot.paramMap.get('consumerId')!);
editMode = signal<boolean>(false);
visibleLicenseForm = signal(false);
readonly loading = computed(() => this.store.loading());
readonly consumer = computed(() => this.store.entity());
readonly license = computed(() => this.store.entity()?.license);
readonly licenseStatus = computed(() => {
if (!this.store.entity()?.license?.expires_at) {
return null;
}
if (
new Date().toDateString() >
new Date(this.store.entity()?.license?.expires_at || '').toDateString()
) {
return licenseStatus.EXPIRED;
}
return licenseStatus.ACTIVE;
});
constructor() {
effect(() => {
@@ -54,4 +76,8 @@ export class ConsumerComponent {
},
]);
}
openLicenseForm() {
this.visibleLicenseForm.set(true);
}
}