create license management
This commit is contained in:
+5
-19
@@ -1,38 +1,24 @@
|
||||
# Build stage
|
||||
FROM node:20-alpine AS builder
|
||||
FROM node:20 AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install pnpm
|
||||
RUN npm config set registry "https://hub.megan.ir/npm/"
|
||||
|
||||
RUN npm install -g pnpm
|
||||
|
||||
# Copy package files
|
||||
COPY package.json pnpm-lock.yaml ./
|
||||
RUN pnpm install
|
||||
|
||||
# Install dependencies
|
||||
RUN pnpm install --frozen-lockfile
|
||||
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Build the application for production
|
||||
RUN pnpm run build
|
||||
|
||||
# Production stage - serve with nginx
|
||||
FROM nginx:alpine
|
||||
|
||||
# Copy nginx configuration
|
||||
COPY nginx.conf /etc/nginx/nginx.conf
|
||||
|
||||
# Copy built application from builder stage
|
||||
COPY --from=builder /app/dist/pos.client/browser /usr/share/nginx/html
|
||||
|
||||
# Expose port
|
||||
EXPOSE 80
|
||||
EXPOSE 4001
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
||||
CMD wget --quiet --tries=1 --spider http://localhost:80/ || exit 1
|
||||
|
||||
# Start nginx
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ COPY nginx.conf /etc/nginx/nginx.conf
|
||||
COPY --from=builder /app/dist/pos.client/browser /usr/share/nginx/html
|
||||
|
||||
# Expose port
|
||||
EXPOSE 80
|
||||
EXPOSE 5000
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
||||
|
||||
+9
-9
@@ -6,9 +6,9 @@ services:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
container_name: sakai-ng-prod
|
||||
container_name: psp_panel_prod
|
||||
ports:
|
||||
- "80:80"
|
||||
- "5000:5000"
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
restart: unless-stopped
|
||||
@@ -20,16 +20,16 @@ services:
|
||||
retries: 3
|
||||
start_period: 5s
|
||||
networks:
|
||||
- sakai-network
|
||||
- psp_panel_network
|
||||
|
||||
# Staging service
|
||||
staging:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.staging
|
||||
container_name: sakai-ng-staging
|
||||
container_name: psp_panel_staging
|
||||
ports:
|
||||
- "8080:80"
|
||||
- "5050:5000"
|
||||
environment:
|
||||
- NODE_ENV=staging
|
||||
restart: unless-stopped
|
||||
@@ -43,14 +43,14 @@ services:
|
||||
profiles:
|
||||
- staging
|
||||
networks:
|
||||
- sakai-network
|
||||
- psp_panel_network
|
||||
|
||||
# Development service with hot reload
|
||||
dev:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.dev
|
||||
container_name: sakai-ng-dev
|
||||
container_name: psp_panel-dev
|
||||
working_dir: /app
|
||||
volumes:
|
||||
- .:/app
|
||||
@@ -63,8 +63,8 @@ services:
|
||||
profiles:
|
||||
- dev
|
||||
networks:
|
||||
- sakai-network
|
||||
- psp_panel_network
|
||||
|
||||
networks:
|
||||
sakai-network:
|
||||
psp_panel_network:
|
||||
driver: bridge
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ http {
|
||||
include /etc/nginx/conf.d/*.conf;
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
listen 5000;
|
||||
server_name localhost;
|
||||
charset utf-8;
|
||||
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@
|
||||
"tailwindcss": "^4.1.11",
|
||||
"typescript": "~5.8.3"
|
||||
},
|
||||
"name": "pos.client",
|
||||
"name": "psp_panel",
|
||||
"prettier": {
|
||||
"overrides": [
|
||||
{
|
||||
|
||||
Generated
+291
-291
File diff suppressed because it is too large
Load Diff
@@ -11,8 +11,6 @@ import { AuthService } from '../services/auth.service';
|
||||
* - Prevents duplicate refresh token requests
|
||||
*/
|
||||
export const authInterceptor: HttpInterceptorFn = (req, next) => {
|
||||
console.log('authInterceptor');
|
||||
|
||||
const authService = inject(AuthService);
|
||||
|
||||
// Skip auth for certain endpoints
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<p-dialog
|
||||
header="اطلاعات لایسنس"
|
||||
[(visible)]="visible"
|
||||
[modal]="true"
|
||||
[style]="{ width: '400px' }"
|
||||
[closable]="true"
|
||||
(onHide)="close()"
|
||||
>
|
||||
@if (!licenseStatus()) {
|
||||
<p-message severity="warn" [closable]="false" variant="text" icon="pi pi-info-circle" class="mb-5">
|
||||
برای کاربر شما لایسنسی در نظر گرفته نشده است. برای پیگیری با پشتیبانی تماس بگیرید.
|
||||
</p-message>
|
||||
} @else {
|
||||
@if (licenseStatus() === "EXPIRED") {
|
||||
<p-message severity="error" [closable]="false" variant="text" icon="pi pi-info-circle" class="mb-5">
|
||||
لایسنس شما منقضی شده است. برای تمدید با پشتیبانی تماس بگیرید.
|
||||
</p-message>
|
||||
}
|
||||
<div class="flex flex-col gap-4">
|
||||
<app-key-value label="شروع لایسنس از" [value]="license()?.starts_at!" type="date" />
|
||||
<app-key-value label="انقضای لایسنس" [value]="license()?.expires_at!" type="date" />
|
||||
<app-key-value label="ارایه شده توسط" [value]="license()?.partner?.name || 'برند نرمافزار'" />
|
||||
</div>
|
||||
}
|
||||
</p-dialog>
|
||||
@@ -0,0 +1,31 @@
|
||||
import { AbstractDialog } from '@/shared/abstractClasses/abstract-dialog';
|
||||
import { KeyValueComponent } from '@/shared/components';
|
||||
import { licenseStatus } from '@/shared/localEnum/constants/licenseStatus';
|
||||
import { Component, computed, inject } from '@angular/core';
|
||||
import { Dialog } from 'primeng/dialog';
|
||||
import { Message } from 'primeng/message';
|
||||
import { ConsumerStore } from '../store/main.store';
|
||||
|
||||
@Component({
|
||||
selector: 'consumer-license-info-dialog',
|
||||
templateUrl: './license-info-dialog.component.html',
|
||||
imports: [Dialog, KeyValueComponent, Message],
|
||||
})
|
||||
export class ConsumerLicenseInfoDialogComponent extends AbstractDialog {
|
||||
private readonly store = inject(ConsumerStore);
|
||||
|
||||
license = computed(() => this.store.entity()?.license);
|
||||
|
||||
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;
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
const baseUrl = '/api/v1/consumer';
|
||||
|
||||
export const CONSUMERS_API_ROUTES = {
|
||||
info: () => `${baseUrl}`,
|
||||
};
|
||||
@@ -1 +1,2 @@
|
||||
export * from './apiRoutes';
|
||||
export * from './menuItems.const';
|
||||
|
||||
@@ -1 +1,19 @@
|
||||
<ng-template #topBarMoreAction>
|
||||
@if (licenseStatus() === "ACTIVE") {
|
||||
<p-button outlined severity="success" size="small" (click)="showLicenseInfo()">لایسنس فعال</p-button>
|
||||
} @else if (licenseStatus() === "EXPIRED") {
|
||||
<p-button severity="warn" size="small" (onClick)="showLicenseInfo()">
|
||||
لایسنس غیرفعال
|
||||
<i class="pi pi-question-circle" pButtonIcon></i>
|
||||
</p-button>
|
||||
} @else if (licenseStatus() === null) {
|
||||
<p-button severity="warn" size="small" (click)="showLicenseInfo()">
|
||||
لایسنس غیرفعال
|
||||
<i class="pi pi-question-circle" pButtonIcon></i>
|
||||
</p-button>
|
||||
}
|
||||
</ng-template>
|
||||
|
||||
<consumer-license-info-dialog [(visible)]="visibleLicenseInfo" />
|
||||
|
||||
<router-outlet></router-outlet>
|
||||
|
||||
@@ -1,17 +1,52 @@
|
||||
import { LayoutService } from '@/layout/service/layout.service';
|
||||
import { Component, inject } from '@angular/core';
|
||||
import { licenseStatus } from '@/shared/localEnum/constants/licenseStatus';
|
||||
import { Component, computed, inject, signal, TemplateRef, ViewChild } from '@angular/core';
|
||||
import { RouterOutlet } from '@angular/router';
|
||||
import { Button, ButtonIcon } from 'primeng/button';
|
||||
import { ConsumerLicenseInfoDialogComponent } from '../components/license-info-dialog.component';
|
||||
import { CONSUMER_MENU_ITEMS } from '../constants';
|
||||
import { ConsumerStore } from '../store/main.store';
|
||||
|
||||
@Component({
|
||||
selector: 'consumer-layout',
|
||||
templateUrl: './layout.component.html',
|
||||
imports: [RouterOutlet],
|
||||
imports: [RouterOutlet, Button, ButtonIcon, ConsumerLicenseInfoDialogComponent],
|
||||
})
|
||||
export class LayoutComponent {
|
||||
@ViewChild('topBarMoreAction') topBarMoreAction!: TemplateRef<any>;
|
||||
|
||||
private readonly layoutService = inject(LayoutService);
|
||||
private readonly store = inject(ConsumerStore);
|
||||
|
||||
visibleLicenseInfo = signal(false);
|
||||
|
||||
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;
|
||||
});
|
||||
|
||||
ngOnInit() {
|
||||
this.layoutService.setMenuItems(CONSUMER_MENU_ITEMS);
|
||||
this.store.getData();
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
this.layoutService.setHeaderSlot(this.topBarMoreAction);
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.layoutService.setHeaderSlot(null);
|
||||
}
|
||||
|
||||
showLicenseInfo() {
|
||||
this.visibleLicenseInfo.set(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export * from './io';
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import ISummary from '@/core/models/summary';
|
||||
import { TLicenseStatus } from '@/shared/localEnum/constants/licenseStatus';
|
||||
|
||||
export interface IConsumerInfoRawResponse {
|
||||
id: string;
|
||||
first_name: string;
|
||||
last_name: string;
|
||||
full_name: string;
|
||||
mobile_number: string;
|
||||
license: {
|
||||
starts_at: string;
|
||||
expires_at: string;
|
||||
status: TLicenseStatus;
|
||||
partner?: ISummary;
|
||||
};
|
||||
}
|
||||
export interface IConsumerInfoResponse extends IConsumerInfoRawResponse {}
|
||||
@@ -1,6 +1,6 @@
|
||||
const baseUrl = '/api/v1/consumer/accounts';
|
||||
|
||||
export const CONSUMERS_API_ROUTES = {
|
||||
export const CONSUMER_Accounts_API_ROUTES = {
|
||||
list: () => `${baseUrl}`,
|
||||
single: (id: string) => `${baseUrl}/${id}`,
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@ import { IPaginatedResponse } from '@/core/models/service.model';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { CONSUMERS_API_ROUTES as CONSUMER_ACCOUNTS_API_ROUTES } from '../constants';
|
||||
import { CONSUMER_Accounts_API_ROUTES as CONSUMER_ACCOUNTS_API_ROUTES } from '../constants';
|
||||
import { IAccountRawResponse, IAccountRequest, IAccountResponse } from '../models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { CONSUMERS_API_ROUTES } from '../constants';
|
||||
import { IConsumerInfoRawResponse, IConsumerInfoResponse } from '../models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class ConsumerService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
private apiRoutes = CONSUMERS_API_ROUTES;
|
||||
|
||||
getInfo(): Observable<IConsumerInfoResponse> {
|
||||
return this.http.get<IConsumerInfoRawResponse>(this.apiRoutes.info());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import { EntityState, EntityStore } from '@/core/state';
|
||||
import { LayoutService } from '@/layout/service/layout.service';
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { catchError, finalize, throwError } from 'rxjs';
|
||||
import { IConsumerInfoResponse } from '../models';
|
||||
import { ConsumerService } from '../services/main.service';
|
||||
|
||||
interface ConsumerState extends EntityState<IConsumerInfoResponse> {}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ConsumerStore extends EntityStore<IConsumerInfoResponse, ConsumerState> {
|
||||
private readonly service = inject(ConsumerService);
|
||||
private readonly layoutService = inject(LayoutService);
|
||||
|
||||
constructor() {
|
||||
super({
|
||||
loading: false,
|
||||
error: null,
|
||||
entity: null,
|
||||
initialized: false,
|
||||
isRefreshing: false,
|
||||
});
|
||||
}
|
||||
|
||||
getData() {
|
||||
this.patchState({ loading: true });
|
||||
this.service
|
||||
.getInfo()
|
||||
.pipe(
|
||||
finalize(() => {
|
||||
this.patchState({ loading: false });
|
||||
}),
|
||||
catchError(() => {
|
||||
this.patchState({
|
||||
error: '',
|
||||
});
|
||||
return throwError('');
|
||||
}),
|
||||
)
|
||||
.subscribe((entity) => {
|
||||
this.layoutService.setPanelInfo({
|
||||
title: 'پنل مدیریت کسب و کار',
|
||||
});
|
||||
this.patchState({ entity });
|
||||
});
|
||||
}
|
||||
|
||||
override reset(): void {
|
||||
this.setState({
|
||||
loading: false,
|
||||
error: null,
|
||||
entity: null,
|
||||
initialized: false,
|
||||
isRefreshing: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -77,8 +77,6 @@ export class PosOrderSectionComponent {
|
||||
this.isVisiblePaymentForm.set(true);
|
||||
}
|
||||
|
||||
submitCustomer() {
|
||||
console.log('submitCustomer');
|
||||
}
|
||||
submitCustomer() {}
|
||||
submitPayment() {}
|
||||
}
|
||||
|
||||
@@ -199,8 +199,6 @@ export class PosLandingStore {
|
||||
}
|
||||
|
||||
setCustomer(customer: { customer_id?: string; info?: ICustomer; type: CustomerType }) {
|
||||
console.log(customer);
|
||||
|
||||
this.setState({ customerDetails: customer });
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { Maybe } from '@/core';
|
||||
import { AuthService, BreadcrumbService } from '@/core/services';
|
||||
import { BreadcrumbComponent } from '@/shared/components';
|
||||
import { CommonModule } from '@angular/common';
|
||||
@@ -9,7 +10,6 @@ import {
|
||||
Input,
|
||||
Renderer2,
|
||||
TemplateRef,
|
||||
ViewChild,
|
||||
} from '@angular/core';
|
||||
import { NavigationEnd, Router, RouterModule } from '@angular/router';
|
||||
import { ProgressSpinner } from 'primeng/progressspinner';
|
||||
@@ -40,15 +40,14 @@ export class AppLayout {
|
||||
|
||||
@Input() fullLoading: boolean = false;
|
||||
|
||||
@ViewChild(AppSidebar) appSidebar!: AppSidebar;
|
||||
|
||||
@ViewChild(AppTopbar) appTopBar!: AppTopbar;
|
||||
@ContentChild('content', { static: true }) content?: TemplateRef<any> | null;
|
||||
@ContentChild('topBarMoreAction', { static: true }) topBarMoreAction?: TemplateRef<any> | null;
|
||||
// @ContentChild('topBarMoreAction', { static: true }) topBarMoreAction?: TemplateRef<any> | null;
|
||||
|
||||
private breadcrumbService = inject(BreadcrumbService);
|
||||
private authService = inject(AuthService);
|
||||
|
||||
topBarMoreAction?: Maybe<TemplateRef<any>> = null;
|
||||
|
||||
constructor(
|
||||
public layoutService: LayoutService,
|
||||
public renderer: Renderer2,
|
||||
@@ -144,6 +143,8 @@ export class AppLayout {
|
||||
});
|
||||
|
||||
ngOnInit() {
|
||||
this.layoutService.headerSlot$.subscribe((tpl) => (this.topBarMoreAction = tpl));
|
||||
|
||||
if (window.location.pathname === '/') {
|
||||
if (!this.authService.currentAccount()) {
|
||||
this.router.navigateByUrl('auth');
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
<div class="layout-sidebar">
|
||||
<div class="layout-sidebar flex flex-col gap-4">
|
||||
<div class="grow">
|
||||
<app-menu></app-menu>
|
||||
</div>
|
||||
<div class="shrink-0 sticky bottom-0">
|
||||
<div class="py-2 w-full text-center">
|
||||
<span class="text-muted-color text-sm font-bold">ارایه شده توسط (برند نرمافزار)</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layout-topbar-actions">
|
||||
<div class="layout-topbar-actions items-center">
|
||||
<ng-content></ng-content>
|
||||
<div class="layout-config-menu">
|
||||
<button type="button" class="layout-topbar-action" (click)="toggleDarkMode()">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { computed, effect, Injectable, signal } from '@angular/core';
|
||||
import { computed, effect, Injectable, signal, TemplateRef } from '@angular/core';
|
||||
import { MenuItem } from 'primeng/api';
|
||||
import { Subject } from 'rxjs';
|
||||
import { BehaviorSubject, Subject } from 'rxjs';
|
||||
|
||||
export interface layoutConfig {
|
||||
preset?: string;
|
||||
@@ -218,4 +218,11 @@ export class LayoutService {
|
||||
setPanelInfo(info: IPanelInfo) {
|
||||
this.panelInfo.set(info);
|
||||
}
|
||||
|
||||
private headerSlot = new BehaviorSubject<TemplateRef<any> | null>(null);
|
||||
headerSlot$ = this.headerSlot.asObservable();
|
||||
|
||||
setHeaderSlot(tpl: TemplateRef<any> | null) {
|
||||
this.headerSlot.next(tpl);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ export class SearchInputComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
onSearch(searchTerm: string) {
|
||||
console.log('Search:', searchTerm);
|
||||
this.search.emit(searchTerm);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
import { goldKaratLabel, goldKaratSelect } from './goldKarat';
|
||||
import { licenseStatusLabel, licenseStatusSelect } from './licenseStatus';
|
||||
|
||||
export const LOCAL_ENUMS = {
|
||||
gold: {
|
||||
label: goldKaratLabel,
|
||||
items: goldKaratSelect,
|
||||
},
|
||||
|
||||
licenseStatus: {
|
||||
label: licenseStatusLabel,
|
||||
items: licenseStatusSelect,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { ISelectItem } from '@/shared/abstractClasses';
|
||||
|
||||
export const licenseStatus = {
|
||||
ACTIVE: 'ACTIVE',
|
||||
SUSPENDED: 'SUSPENDED',
|
||||
EXPIRED: 'EXPIRED',
|
||||
} as const;
|
||||
export type TLicenseStatus = (typeof licenseStatus)[keyof typeof licenseStatus];
|
||||
|
||||
const translates: Record<string, string> = {
|
||||
ACTIVE: 'فعال',
|
||||
SUSPENDED: 'غیرفعال',
|
||||
EXPIRED: 'منقضی شده',
|
||||
};
|
||||
|
||||
export const licenseStatusSelect: ISelectItem[] = Object.keys(licenseStatus)
|
||||
.filter((data) => data !== 'EXPIRED')
|
||||
.map((key) => ({
|
||||
id: key,
|
||||
name: translates[key],
|
||||
}));
|
||||
|
||||
export const licenseStatusLabel = 'وضعیت';
|
||||
@@ -8,6 +8,10 @@
|
||||
<div class="w-full">
|
||||
<div #wrapper [attr.data-disable]="disabled" [attr.data-name]="name" class="w-full">
|
||||
<input pInputText data-input [attr.placeholder]="placeholder" [name]="name" class="w-full" />
|
||||
|
||||
@if (hint) {
|
||||
<small [attr.id]="name + '-help'">{{ hint }}</small>
|
||||
}
|
||||
</div>
|
||||
<div class="flat"></div>
|
||||
</div>
|
||||
|
||||
@@ -31,6 +31,7 @@ export class UikitFlatpickrJalaliComponent implements OnInit {
|
||||
@Input() options: Partial<BaseOptions> = {};
|
||||
@Input() showLabel: boolean = true;
|
||||
@Input() showErrors: boolean = true;
|
||||
@Input() hint?: string;
|
||||
|
||||
@Output() valueChange = new EventEmitter<string>();
|
||||
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
// Production environment configuration
|
||||
// Development environment configuration
|
||||
export const environment = {
|
||||
production: true,
|
||||
apiBaseUrl: 'https://api.yourdomain.com',
|
||||
host: 'yourdomain.com',
|
||||
port: 443,
|
||||
apiEndpoints: {
|
||||
auth: '/api/auth',
|
||||
users: '/api/users',
|
||||
// Add more endpoints as needed
|
||||
},
|
||||
production: false,
|
||||
apiBaseUrl: 'http://194.59.214.243:5002',
|
||||
host: 'localhost',
|
||||
port: 5000,
|
||||
enableLogging: false,
|
||||
enableDebug: false,
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Development environment configuration
|
||||
export const environment = {
|
||||
production: false,
|
||||
// apiBaseUrl: 'http://194.59.214.243:5002',
|
||||
apiBaseUrl: 'http://localhost:5002',
|
||||
host: 'localhost',
|
||||
port: 5000,
|
||||
|
||||
Reference in New Issue
Block a user