2026-03-16 00:35:34 +03:30
|
|
|
import { BreadcrumbService } from '@/core/services';
|
|
|
|
|
import { AppCardComponent, KeyValueComponent } from '@/shared/components';
|
2026-04-06 13:31:30 +03:30
|
|
|
import { JalaliDateDirective } from '@/shared/directives';
|
|
|
|
|
import { licenseStatus } from '@/shared/localEnum/constants/licenseStatus';
|
2026-03-16 00:35:34 +03:30
|
|
|
import { Component, computed, effect, inject, signal } from '@angular/core';
|
|
|
|
|
import { ActivatedRoute } from '@angular/router';
|
2026-04-06 13:31:30 +03:30
|
|
|
import { Button } from 'primeng/button';
|
2026-03-16 00:35:34 +03:30
|
|
|
import { ConsumerAccountListComponent } from '../components/accounts/list.component';
|
|
|
|
|
import { ConsumerBusinessActivitiesComponent } from '../components/businessActivities/list.component';
|
|
|
|
|
import { ConsumerUserFormComponent } from '../components/form.component';
|
2026-04-06 13:31:30 +03:30
|
|
|
import { ConsumerLicenseFormComponent } from '../components/licenses/form.component';
|
2026-03-16 00:35:34 +03:30
|
|
|
import { superAdminConsumersNamedRoutes } from '../constants';
|
|
|
|
|
import { ConsumerStore } from '../store/consumer.store';
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'consumer-user',
|
|
|
|
|
templateUrl: './single.component.html',
|
|
|
|
|
imports: [
|
|
|
|
|
AppCardComponent,
|
|
|
|
|
KeyValueComponent,
|
|
|
|
|
ConsumerUserFormComponent,
|
|
|
|
|
ConsumerAccountListComponent,
|
|
|
|
|
ConsumerBusinessActivitiesComponent,
|
2026-04-06 13:31:30 +03:30
|
|
|
Button,
|
|
|
|
|
JalaliDateDirective,
|
|
|
|
|
ConsumerLicenseFormComponent,
|
2026-03-16 00:35:34 +03:30
|
|
|
],
|
|
|
|
|
})
|
|
|
|
|
export class ConsumerComponent {
|
|
|
|
|
private readonly store = inject(ConsumerStore);
|
|
|
|
|
private readonly route = inject(ActivatedRoute);
|
|
|
|
|
private readonly breadcrumbService = inject(BreadcrumbService);
|
|
|
|
|
|
|
|
|
|
readonly consumerId = signal<string>(this.route.snapshot.paramMap.get('consumerId')!);
|
|
|
|
|
editMode = signal<boolean>(false);
|
|
|
|
|
|
2026-04-06 13:31:30 +03:30
|
|
|
visibleLicenseForm = signal(false);
|
|
|
|
|
|
2026-03-16 00:35:34 +03:30
|
|
|
readonly loading = computed(() => this.store.loading());
|
|
|
|
|
readonly consumer = computed(() => this.store.entity());
|
2026-04-06 13:31:30 +03:30
|
|
|
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;
|
|
|
|
|
});
|
2026-03-16 00:35:34 +03:30
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
effect(() => {
|
|
|
|
|
if (this.consumer()?.id) {
|
|
|
|
|
this.setBreadcrumb();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getData() {
|
|
|
|
|
this.store.getData(this.consumerId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setBreadcrumb() {
|
|
|
|
|
this.breadcrumbService.setItems([
|
|
|
|
|
{
|
|
|
|
|
...superAdminConsumersNamedRoutes.consumers.meta,
|
|
|
|
|
routerLink: superAdminConsumersNamedRoutes.consumers.meta.pagePath!(),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: this.consumer()?.fullname,
|
|
|
|
|
routerLink: superAdminConsumersNamedRoutes.consumer.meta.pagePath!(this.consumerId()),
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
}
|
2026-04-06 13:31:30 +03:30
|
|
|
|
|
|
|
|
openLicenseForm() {
|
|
|
|
|
this.visibleLicenseForm.set(true);
|
|
|
|
|
}
|
2026-03-16 00:35:34 +03:30
|
|
|
}
|