create license management
This commit is contained in:
@@ -43,6 +43,15 @@
|
||||
/>
|
||||
</uikit-field>
|
||||
}
|
||||
<p-divider align="center"> اطلاعات لایسنس </p-divider>
|
||||
<uikit-datepicker
|
||||
label="تاریخ شروع لایسنس"
|
||||
[control]="form.controls.license.controls.starts_at"
|
||||
name="license.starts_at"
|
||||
hint="مدت زمان لایسنسها ۱ ساله هستند."
|
||||
/>
|
||||
<!-- <uikit-datepicker label="تاریخ انقضای لایسنس" [control]="form.controls.license.controls.expires_at" name="license.expires_at" /> -->
|
||||
<app-partner-select label="شریک تجاری" [control]="form.controls.license.controls.partner_id" />
|
||||
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="submitLoading()" (onCancel)="close()" />
|
||||
</form>
|
||||
</p-dialog>
|
||||
|
||||
@@ -2,12 +2,13 @@ import { mobileValidator, 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 { UikitFieldComponent, UikitFlatpickrJalaliComponent } 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 { PartnerSelectComponent } from '../../partners/shared/select.component';
|
||||
import { IConsumerRequest, IConsumerResponse } from '../models';
|
||||
import { ConsumersService } from '../services/main.service';
|
||||
|
||||
@@ -22,6 +23,8 @@ import { ConsumersService } from '../services/main.service';
|
||||
Divider,
|
||||
UikitFieldComponent,
|
||||
Password,
|
||||
UikitFlatpickrJalaliComponent,
|
||||
PartnerSelectComponent,
|
||||
],
|
||||
})
|
||||
export class ConsumerUserFormComponent extends AbstractFormDialog<
|
||||
@@ -44,8 +47,21 @@ export class ConsumerUserFormComponent extends AbstractFormDialog<
|
||||
username: [''],
|
||||
password: [''],
|
||||
confirmPassword: [''],
|
||||
license: this.fb.group({
|
||||
starts_at: [this.initialValues?.license?.starts_at || ''],
|
||||
partner_id: [this.initialValues?.license?.partner?.id || ''],
|
||||
}),
|
||||
});
|
||||
if (!this.editMode) {
|
||||
|
||||
if (this.editMode) {
|
||||
// @ts-ignore
|
||||
form.removeControl('username');
|
||||
// @ts-ignore
|
||||
form.removeControl('password');
|
||||
// @ts-ignore
|
||||
form.removeControl('confirmPassword');
|
||||
form.removeValidators([MustMatch('password', 'confirmPassword')]);
|
||||
} else {
|
||||
form.addControl(
|
||||
'username',
|
||||
this.fb.control<string>('', {
|
||||
@@ -68,14 +84,6 @@ export class ConsumerUserFormComponent extends AbstractFormDialog<
|
||||
}),
|
||||
);
|
||||
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;
|
||||
@@ -84,10 +92,18 @@ export class ConsumerUserFormComponent extends AbstractFormDialog<
|
||||
form = this.initForm();
|
||||
|
||||
override ngOnChanges() {
|
||||
this.form.patchValue(this.initialValues ?? {});
|
||||
this.form.patchValue({
|
||||
...(this.initialValues ?? {}),
|
||||
license: {
|
||||
...(this.initialValues?.license ?? {}),
|
||||
partner_id: this.initialValues?.license?.partner?.id || '',
|
||||
},
|
||||
});
|
||||
if (this.editMode && !this.consumerId) {
|
||||
throw 'missing some arguments';
|
||||
}
|
||||
|
||||
this.form = this.initForm();
|
||||
}
|
||||
|
||||
override submitForm(payload: IConsumerRequest) {
|
||||
|
||||
@@ -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">
|
||||
<uikit-datepicker
|
||||
label="تاریخ شروع لایسنس"
|
||||
[control]="form.controls.starts_at"
|
||||
name="starts_at"
|
||||
hint="مدت زمان لایسنسها ۱ ساله هستند."
|
||||
/>
|
||||
<!-- <uikit-datepicker label="تاریخ انقضای لایسنس" [control]="form.controls.expires_at" name="expires_at" /> -->
|
||||
<app-partner-select label="شریک تجاری" [control]="form.controls.partner_id" />
|
||||
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="submitLoading()" (onCancel)="close()" />
|
||||
</form>
|
||||
</p-dialog>
|
||||
@@ -0,0 +1,58 @@
|
||||
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 { PartnerSelectComponent } from '../../../partners/shared/select.component';
|
||||
import { ILicenseRequest, ILicenseResponse } from '../../models';
|
||||
import { LicensesService } from '../../services/licenses.service';
|
||||
|
||||
@Component({
|
||||
selector: 'superAdmin-consumer-license-form',
|
||||
templateUrl: './form.component.html',
|
||||
imports: [
|
||||
ReactiveFormsModule,
|
||||
Dialog,
|
||||
FormFooterActionsComponent,
|
||||
UikitFlatpickrJalaliComponent,
|
||||
PartnerSelectComponent,
|
||||
],
|
||||
})
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
export * from './accounts';
|
||||
export * from './businessActivities';
|
||||
export * from './businessActivityComplexes';
|
||||
export * from './complexPoses';
|
||||
export * from './licenses';
|
||||
|
||||
const baseUrl = '/api/v1/admin/consumers';
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
const baseUrl = (consumerId: string) => `/api/v1/admin/consumers/${consumerId}/licenses`;
|
||||
|
||||
export const CONSUMER_LICENSES_API_ROUTES = {
|
||||
list: (consumerId: string) => baseUrl(consumerId),
|
||||
single: (consumerId: string, licenseId: string) => `${baseUrl(consumerId)}/${licenseId}`,
|
||||
};
|
||||
@@ -2,4 +2,5 @@ export * from './accounts_io';
|
||||
export * from './businessActivities_io';
|
||||
export * from './complexes_io';
|
||||
export * from './io';
|
||||
export * from './licenses_io';
|
||||
export * from './poses_io';
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { ILicenseRawResponse, ILicenseRequest } from './licenses_io';
|
||||
|
||||
export interface IConsumerRawResponse {
|
||||
id: string;
|
||||
first_name: string;
|
||||
@@ -5,6 +7,7 @@ export interface IConsumerRawResponse {
|
||||
mobile_number: string;
|
||||
status: string;
|
||||
fullname: string;
|
||||
license: ILicenseRawResponse;
|
||||
}
|
||||
export interface IConsumerResponse extends IConsumerRawResponse {}
|
||||
|
||||
@@ -14,4 +17,5 @@ export interface IConsumerRequest {
|
||||
mobile_number: string;
|
||||
username: string;
|
||||
password: string;
|
||||
license?: ILicenseRequest;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import ISummary from '@/core/models/summary';
|
||||
|
||||
export interface ILicenseRawResponse {
|
||||
id: string;
|
||||
starts_at: string;
|
||||
expires_at: string;
|
||||
status: TLicenseStatus;
|
||||
partner?: ISummary;
|
||||
}
|
||||
export interface ILicenseResponse extends ILicenseRawResponse {}
|
||||
|
||||
export interface ILicenseRequest {
|
||||
starts_at: string;
|
||||
expires_at?: string;
|
||||
status: TLicenseStatus;
|
||||
partner_id: string;
|
||||
}
|
||||
@@ -21,8 +21,6 @@ export class AdminConsumerBusinessActivitiesService {
|
||||
);
|
||||
}
|
||||
getSingle(consumerId: string, businessActivityId: string): Observable<IBusinessActivityResponse> {
|
||||
console.log(consumerId, businessActivityId);
|
||||
|
||||
return this.http.get<IBusinessActivityRawResponse>(
|
||||
this.apiRoutes.single(consumerId, businessActivityId),
|
||||
);
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { CONSUMER_LICENSES_API_ROUTES } from '../constants';
|
||||
import { ILicenseRawResponse, ILicenseRequest, ILicenseResponse } from '../models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class LicensesService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
private apiRoutes = CONSUMER_LICENSES_API_ROUTES;
|
||||
|
||||
create(consumerId: string, data: ILicenseRequest): Observable<ILicenseResponse> {
|
||||
return this.http.post<ILicenseRawResponse>(this.apiRoutes.list(consumerId), data);
|
||||
}
|
||||
|
||||
update(
|
||||
consumerId: string,
|
||||
licenseId: string,
|
||||
data: ILicenseRequest,
|
||||
): Observable<ILicenseResponse> {
|
||||
return this.http.patch<ILicenseRawResponse>(this.apiRoutes.single(consumerId, licenseId), data);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user