53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
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)
|
||
// },
|
||
// ),
|
||
}
|