erp-platform/ui/src/store/admin.model.ts

54 lines
1.7 KiB
TypeScript
Raw Normal View History

2025-05-06 06:45:49 +00:00
import type { Action, Thunk } from 'easy-peasy'
import { action, thunk } from 'easy-peasy'
import { Injections } from './store'
import { FieldsDefaultValueDto, GridOptionsEditDto } from '../proxy/form/models'
import setNull from '../utils/setNull'
2025-05-06 06:45:49 +00:00
export interface AdminStoreModel {
listFormValues: GridOptionsEditDto | undefined
}
export interface AdminStoreActions {
setListFormValues: Action<AdminStoreModel, GridOptionsEditDto>
setJsonValue: Action<
AdminStoreModel,
{ field: keyof GridOptionsEditDto; data: FieldsDefaultValueDto[] }
>
getListFormValues: Thunk<AdminStoreActions, string | undefined, Injections>
// onSetLang: ThunkOn<AdminModel, Injections, StoreModel>
}
export type AdminModel = AdminStoreModel & AdminStoreActions
const initialState: AdminStoreModel = {
listFormValues: undefined,
}
export const adminModel: AdminModel = {
...initialState,
setListFormValues: action((state, payload) => {
state.listFormValues = { ...payload }
}),
setJsonValue: action((state, payload) => {
if (state.listFormValues) {
state.listFormValues[payload.field] = payload.data
}
}),
getListFormValues: thunk(async (actions, payload, helpers) => {
if (!payload) {
return
}
const service = helpers.injections.listFormService
const result = await service.getListFormByCode(payload)
setNull(result.data)
actions.setListFormValues(result.data)
}),
// onSetLang: thunkOn(
// (actions) => actions.setLang,
// async (actions, target, helpers) => {
// // Dil değiştiğince AppConfig ve Localizationları tekrar al
// helpers.getStoreActions().abpConfig.getConfig(false)
// },
// ),
}