init to pos domain
This commit is contained in:
@@ -1 +1 @@
|
||||
<consumer-complex-goods-list [businessId]="businessId()" [complexId]="complexId()" />
|
||||
<consumer-complex-goods-list [businessId]="businessId()" [complexId]="complexId()" [guildId]="business()?.guild!.id" />
|
||||
|
||||
@@ -24,6 +24,8 @@ export class ConsumerComplexGoodsComponent {
|
||||
businessId = signal<string>(this.pageParams()['businessActivityId']);
|
||||
complexId = signal<string>(this.pageParams()['complexId']);
|
||||
|
||||
business = computed(() => this.businessStore.entity());
|
||||
|
||||
ngOnInit() {
|
||||
this.setBreadcrumb();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
<div class="flex flex-col gap-6">
|
||||
<app-card-data cardTitle="اطلاعات پایانهی فروش" [editable]="true" [(editMode)]="editMode">
|
||||
<ng-template #moreAction>
|
||||
<p-button type="button" variant="outlined" (onClick)="toPosLanding()"> ورود به پایانه </p-button>
|
||||
</ng-template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<div class="grid grid-cols-3 gap-4 items-center">
|
||||
<app-key-value label="عنوان" [value]="pos()?.name" />
|
||||
|
||||
+14
-1
@@ -3,6 +3,8 @@ import { AppCardComponent, KeyValueComponent } from '@/shared/components';
|
||||
import pageParamsUtils from '@/utils/page-params.utils';
|
||||
import { Component, computed, effect, inject, signal } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { CookieService } from 'ngx-cookie-service';
|
||||
import { Button } from 'primeng/button';
|
||||
import { ConsumerPosFormComponent } from '../../components/poses/form.component';
|
||||
import { BusinessActivityStore } from '../../store/businessActivity.store';
|
||||
import { ConsumerComplexStore } from '../../store/complex.store';
|
||||
@@ -11,7 +13,7 @@ import { PosStore } from '../../store/pos.store';
|
||||
@Component({
|
||||
selector: 'superAdmin-user-pos',
|
||||
templateUrl: './single.component.html',
|
||||
imports: [AppCardComponent, KeyValueComponent, ConsumerPosFormComponent],
|
||||
imports: [AppCardComponent, KeyValueComponent, ConsumerPosFormComponent, Button],
|
||||
})
|
||||
export class SuperAdminUserPosComponent {
|
||||
private readonly businessStore = inject(BusinessActivityStore);
|
||||
@@ -19,6 +21,7 @@ export class SuperAdminUserPosComponent {
|
||||
private readonly store = inject(PosStore);
|
||||
private readonly route = inject(ActivatedRoute);
|
||||
private readonly breadcrumbService = inject(BreadcrumbService);
|
||||
private readonly cookieService = inject(CookieService);
|
||||
|
||||
pageParams = computed(() => pageParamsUtils(this.route));
|
||||
|
||||
@@ -42,6 +45,16 @@ export class SuperAdminUserPosComponent {
|
||||
this.store.getData(this.businessId(), this.complexId(), this.posId());
|
||||
}
|
||||
|
||||
toPosLanding() {
|
||||
this.cookieService.set('posId', this.posId(), {
|
||||
sameSite: 'Lax', // or 'Strict' for same-site requests only
|
||||
secure: false,
|
||||
path: '/',
|
||||
domain: 'localhost',
|
||||
});
|
||||
window.open('/pos', '_blank');
|
||||
}
|
||||
|
||||
setBreadcrumb() {
|
||||
this.breadcrumbService.setItems([
|
||||
...this.businessStore.breadcrumbItems(),
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export * from './menuItems.const';
|
||||
@@ -0,0 +1,16 @@
|
||||
import { MenuItem } from 'primeng/api';
|
||||
export const CONSUMER_MENU_ITEMS = [
|
||||
{
|
||||
items: [
|
||||
{
|
||||
label: 'فروش',
|
||||
icon: 'pi pi-fw pi-home',
|
||||
routerLink: ['/'],
|
||||
},
|
||||
{
|
||||
label: 'فاکتورها',
|
||||
icon: 'pi pi-fw pi-home',
|
||||
},
|
||||
],
|
||||
},
|
||||
] as MenuItem[];
|
||||
@@ -0,0 +1,5 @@
|
||||
@if (loading()) {
|
||||
<shared-page-loading />
|
||||
} @else {
|
||||
<router-outlet></router-outlet>
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { PageLoadingComponent } from '@/shared/components/page-loading.component';
|
||||
import { Component, computed, inject } from '@angular/core';
|
||||
import { RouterOutlet } from '@angular/router';
|
||||
import { PosStore } from '../pos.store';
|
||||
|
||||
@Component({
|
||||
selector: 'pos-layout',
|
||||
templateUrl: './layout.component.html',
|
||||
imports: [PageLoadingComponent, RouterOutlet],
|
||||
})
|
||||
export class PosLayoutComponent {
|
||||
constructor() {}
|
||||
|
||||
private readonly store = inject(PosStore);
|
||||
|
||||
readonly loading = computed(() => this.store.loading());
|
||||
readonly posInfo = computed(() => this.store.entity());
|
||||
|
||||
getData() {
|
||||
this.store.getData();
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.getData();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
export interface IPosInfoRawResponse {
|
||||
name: true;
|
||||
complex: {
|
||||
id: string;
|
||||
name: string;
|
||||
tax_id: string;
|
||||
};
|
||||
businessActivity: {
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
guild: {
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface IPosInfoResponse extends IPosInfoRawResponse {}
|
||||
@@ -0,0 +1,6 @@
|
||||
const baseUrl = '/api/v1/pos';
|
||||
|
||||
export const POS_API_ROUTES = {
|
||||
info: () => `${baseUrl}`,
|
||||
goods: () => `${baseUrl}/goods`,
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export * from './apiRoutes';
|
||||
@@ -0,0 +1,13 @@
|
||||
import { TAccountType } from '@/core/constants/accountTypes.const';
|
||||
|
||||
export interface IAccountRawResponse {
|
||||
username: string;
|
||||
id: string;
|
||||
}
|
||||
export interface IAccountResponse extends IAccountRawResponse {}
|
||||
|
||||
export interface IAccountRequest {
|
||||
username: string;
|
||||
password?: string;
|
||||
type: TAccountType;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './accounts_io';
|
||||
export * from './io';
|
||||
@@ -0,0 +1,18 @@
|
||||
import { TRoles } from '@/core';
|
||||
|
||||
export interface IUserRawResponse {
|
||||
mobile_number: string;
|
||||
first_name: string;
|
||||
last_name: string;
|
||||
fullname: string;
|
||||
id: string;
|
||||
role: TRoles;
|
||||
}
|
||||
export interface IUserResponse extends IUserRawResponse {}
|
||||
|
||||
export interface IUserRequest {
|
||||
first_name: string;
|
||||
last_name: string;
|
||||
mobile_number: string;
|
||||
role: TRoles;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { IPosInfoRawResponse, IPosInfoResponse } from '@/domains/pos/models/pos.io';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { POS_API_ROUTES } from '../constants';
|
||||
import { IUserRawResponse, IUserResponse } from '../models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class PosService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
private apiRoutes = POS_API_ROUTES;
|
||||
|
||||
getInfo(): Observable<IPosInfoResponse> {
|
||||
return this.http.get<IPosInfoRawResponse>(this.apiRoutes.info());
|
||||
}
|
||||
getGoods(): Observable<IUserResponse> {
|
||||
return this.http.get<IUserRawResponse>(this.apiRoutes.goods());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from './root.component';
|
||||
@@ -0,0 +1 @@
|
||||
<span>صفحهی pos</span>
|
||||
@@ -0,0 +1,21 @@
|
||||
// import { CatalogRoleTagComponent } from '@/shared/catalog/roles';
|
||||
import { PosStore } from '@/domains/pos/pos.store';
|
||||
import { LayoutService } from '@/layout/service/layout.service';
|
||||
import { Component, computed, inject } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'pos-landing',
|
||||
templateUrl: './root.component.html',
|
||||
})
|
||||
export class PosLandingComponent {
|
||||
private readonly store = inject(PosStore);
|
||||
private readonly layoutService = inject(LayoutService);
|
||||
|
||||
private readonly posInfo = computed(() => this.store.entity());
|
||||
|
||||
ngOnInit() {
|
||||
this.layoutService.setPanelInfo({
|
||||
title: `فروشگاه ${this.posInfo()?.complex.name} - ${this.posInfo()?.name}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import { EntityState, EntityStore } from '@/core/state';
|
||||
import { computed, inject, Injectable } from '@angular/core';
|
||||
import { CookieService } from 'ngx-cookie-service';
|
||||
import { catchError, finalize, throwError } from 'rxjs';
|
||||
import { IPosInfoResponse } from './models/pos.io';
|
||||
import { PosService } from './modules/landing/services/main.service';
|
||||
|
||||
interface PosState extends EntityState<IPosInfoResponse> {
|
||||
posId: string;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class PosStore extends EntityStore<IPosInfoResponse, PosState> {
|
||||
private readonly service = inject(PosService);
|
||||
|
||||
constructor(private readonly cookieService: CookieService) {
|
||||
super({
|
||||
loading: false,
|
||||
error: null,
|
||||
entity: null,
|
||||
initialized: false,
|
||||
isRefreshing: false,
|
||||
posId: cookieService.get('posId'),
|
||||
});
|
||||
}
|
||||
|
||||
posId = computed(() => this._state().posId);
|
||||
|
||||
getData() {
|
||||
this.patchState({ loading: true });
|
||||
this.service
|
||||
.getInfo()
|
||||
.pipe(
|
||||
finalize(() => {
|
||||
this.patchState({ loading: false });
|
||||
}),
|
||||
catchError(() => {
|
||||
this.patchState({
|
||||
error: '',
|
||||
});
|
||||
return throwError('');
|
||||
}),
|
||||
)
|
||||
.subscribe((entity) => {
|
||||
this.patchState({ entity });
|
||||
});
|
||||
}
|
||||
|
||||
override reset(): void {
|
||||
this.setState({
|
||||
loading: false,
|
||||
error: null,
|
||||
entity: null,
|
||||
initialized: false,
|
||||
isRefreshing: false,
|
||||
posId: this.cookieService.get('posId'),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Route } from '@angular/router';
|
||||
|
||||
export const POS_ROUTES = {
|
||||
path: 'pos',
|
||||
loadComponent: () => import('./layouts/layout.component').then((m) => m.PosLayoutComponent),
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
loadComponent: () =>
|
||||
import('./modules/landing/views/root.component').then((m) => m.PosLandingComponent),
|
||||
},
|
||||
],
|
||||
} as Route;
|
||||
@@ -49,6 +49,12 @@ export class SuperAdminUserPosComponent {
|
||||
this.store.getData(this.businessId(), this.complexId(), this.posId());
|
||||
}
|
||||
|
||||
toPosLanding() {
|
||||
// @ts-ignore
|
||||
window.cookieStore.set('posId', this.posId());
|
||||
// window.open('pos')
|
||||
}
|
||||
|
||||
setBreadcrumb() {
|
||||
this.breadcrumbService.setItems([
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user