Files
psp_panel/src/app/domains/partner/store/main.store.ts
T

58 lines
1.4 KiB
TypeScript
Raw Normal View History

2026-04-13 15:47:50 +03:30
import { EntityState, EntityStore } from '@/core/state';
import { LayoutService } from '@/layout/service/layout.service';
import { inject, Injectable } from '@angular/core';
import { catchError, finalize } from 'rxjs';
import { IPartnerInfoResponse } from '../models';
import { PartnerService } from '../services/main.service';
interface PartnerState extends EntityState<IPartnerInfoResponse> {}
@Injectable({
providedIn: 'root',
})
export class PartnerStore extends EntityStore<IPartnerInfoResponse, PartnerState> {
private readonly service = inject(PartnerService);
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((error) => {
this.setError(error);
throw error;
}),
)
.subscribe((entity) => {
this.layoutService.setPanelInfo({
title: `پنل مدیریتی ${entity.name}`,
});
this.setEntity(entity);
});
}
override reset(): void {
this.setState({
loading: false,
error: null,
entity: null,
initialized: false,
isRefreshing: false,
});
}
}