erp-platform/ui/src/store/admin.model.ts
2025-08-12 11:39:06 +03:00

53 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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'
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)
// },
// ),
}