2026-02-24 20:44:16 +00:00
|
|
|
import type { Action, Thunk } from 'easy-peasy'
|
|
|
|
|
import { action, thunk } from 'easy-peasy'
|
|
|
|
|
import { Injections } from './store'
|
|
|
|
|
import { GridOptionsEditDto } from '../proxy/form/models'
|
|
|
|
|
import setNull from '../utils/setNull'
|
|
|
|
|
import { ListState } from '@/proxy/admin/list-form/models'
|
2026-07-09 17:55:07 +00:00
|
|
|
import { Conversation } from '@/proxy/ai/models'
|
|
|
|
|
|
|
|
|
|
export type DashboardLayout = 'default' | 'wide-center' | 'balanced' | 'wide-left' | 'wide-right'
|
|
|
|
|
|
|
|
|
|
export interface DashboardState {
|
|
|
|
|
dashboardLayout: DashboardLayout
|
|
|
|
|
hiddenWidgetIds: string[]
|
|
|
|
|
widgetOrder: {
|
|
|
|
|
left: string[]
|
|
|
|
|
center: string[]
|
|
|
|
|
right: string[]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface AiConversationsState {
|
|
|
|
|
items: Conversation[]
|
|
|
|
|
aiActiveConversationId: string | null
|
|
|
|
|
}
|
2026-02-24 20:44:16 +00:00
|
|
|
|
|
|
|
|
export interface AdminStoreModel {
|
|
|
|
|
lists: {
|
|
|
|
|
values: GridOptionsEditDto | undefined
|
|
|
|
|
states: ListState[]
|
|
|
|
|
}
|
2026-07-09 17:55:07 +00:00
|
|
|
dashboard: DashboardState
|
|
|
|
|
aiConversations: AiConversationsState
|
2026-02-24 20:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface AdminStoreActions {
|
|
|
|
|
lists: {
|
|
|
|
|
setListFormValues: Action<AdminStoreModel['lists'], GridOptionsEditDto>
|
|
|
|
|
setJsonValue: Action<AdminStoreModel['lists'], { field: keyof GridOptionsEditDto; data: any[] }>
|
|
|
|
|
getListFormValues: Thunk<
|
|
|
|
|
AdminStoreModel['lists'] & AdminStoreActions['lists'],
|
|
|
|
|
string | undefined,
|
|
|
|
|
Injections
|
|
|
|
|
>
|
|
|
|
|
setStates: Action<AdminStoreModel['lists'], ListState>
|
|
|
|
|
}
|
2026-07-09 17:55:07 +00:00
|
|
|
dashboard: {
|
|
|
|
|
setDashboardLayout: Action<DashboardState, DashboardLayout>
|
|
|
|
|
setHiddenWidgetIds: Action<DashboardState, string[]>
|
|
|
|
|
setWidgetOrder: Action<DashboardState, DashboardState['widgetOrder']>
|
|
|
|
|
reset: Action<DashboardState>
|
2026-03-21 18:10:40 +00:00
|
|
|
}
|
2026-07-09 17:55:07 +00:00
|
|
|
setAiConversations: Action<AdminStoreModel, AiConversationsState>
|
2026-02-24 20:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type AdminModel = AdminStoreModel & AdminStoreActions
|
|
|
|
|
|
2026-07-09 17:55:07 +00:00
|
|
|
const initialDashboardState: DashboardState = {
|
|
|
|
|
dashboardLayout: 'default',
|
|
|
|
|
hiddenWidgetIds: [],
|
|
|
|
|
widgetOrder: {
|
|
|
|
|
left: [],
|
|
|
|
|
center: [],
|
|
|
|
|
right: [],
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-24 20:44:16 +00:00
|
|
|
const initialState: AdminStoreModel = {
|
|
|
|
|
lists: {
|
|
|
|
|
values: undefined,
|
|
|
|
|
states: [],
|
|
|
|
|
},
|
2026-07-09 17:55:07 +00:00
|
|
|
dashboard: initialDashboardState,
|
|
|
|
|
aiConversations: {
|
|
|
|
|
items: [],
|
|
|
|
|
aiActiveConversationId: null,
|
2026-03-21 18:10:40 +00:00
|
|
|
},
|
2026-02-24 20:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const adminModel: AdminModel = {
|
|
|
|
|
lists: {
|
|
|
|
|
...initialState.lists,
|
|
|
|
|
setStates: action((state, payload) => {
|
|
|
|
|
const stateId = state.states.findIndex((s) => s.listFormCode === payload.listFormCode)
|
|
|
|
|
if (stateId !== -1) {
|
2026-07-16 14:01:18 +00:00
|
|
|
state.states[stateId] = { ...state.states[stateId], ...payload }
|
2026-02-24 20:44:16 +00:00
|
|
|
} else {
|
|
|
|
|
state.states = [...state.states, payload]
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
setListFormValues: action((state, payload) => {
|
|
|
|
|
state.values = { ...state.values, ...payload }
|
|
|
|
|
}),
|
|
|
|
|
setJsonValue: action((state, payload) => {
|
|
|
|
|
if (state.values) {
|
|
|
|
|
state.values[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)
|
|
|
|
|
}),
|
|
|
|
|
},
|
2026-07-09 17:55:07 +00:00
|
|
|
dashboard: {
|
|
|
|
|
...initialState.dashboard,
|
|
|
|
|
setDashboardLayout: action((state, payload) => {
|
|
|
|
|
state.dashboardLayout = payload
|
2026-03-21 18:10:40 +00:00
|
|
|
}),
|
2026-07-09 17:55:07 +00:00
|
|
|
setHiddenWidgetIds: action((state, payload) => {
|
|
|
|
|
state.hiddenWidgetIds = payload
|
|
|
|
|
}),
|
|
|
|
|
setWidgetOrder: action((state, payload) => {
|
|
|
|
|
state.widgetOrder = payload
|
|
|
|
|
}),
|
|
|
|
|
reset: action((state) => {
|
|
|
|
|
state.dashboardLayout = initialDashboardState.dashboardLayout
|
|
|
|
|
state.hiddenWidgetIds = initialDashboardState.hiddenWidgetIds
|
|
|
|
|
state.widgetOrder = initialDashboardState.widgetOrder
|
2026-03-21 18:10:40 +00:00
|
|
|
}),
|
|
|
|
|
},
|
2026-07-09 17:55:07 +00:00
|
|
|
aiConversations: initialState.aiConversations,
|
|
|
|
|
setAiConversations: action((state, payload) => {
|
|
|
|
|
state.aiConversations = payload
|
|
|
|
|
}),
|
2026-02-24 20:44:16 +00:00
|
|
|
}
|