import type { Action } from 'easy-peasy' import { action } from 'easy-peasy' export interface StoreError { id: string title: string message: string cid: string statusCode?: string } export interface BaseStoreModel { common: { currentRouteKey: string tabHasFocus: boolean setupMode: boolean /** Veritabanı mevcut değilse true — setup sayfasına yönlendirme için */ } messages: { errors: StoreError[] warning: string[] } } export interface BaseStoreActions { common: { setCurrentRouteKey: Action setTabHasFocus: Action setSetupMode: Action } messages: { addError: Action removeError: Action // setSuccess: Action setWarning: Action } } export type BaseModel = BaseStoreModel & BaseStoreActions const initialState: BaseStoreModel = { common: { currentRouteKey: '', tabHasFocus: false, setupMode: false }, messages: { errors: [], // success: [], warning: [], } } export const baseModel: BaseModel = { common: { ...initialState.common, setCurrentRouteKey: action((state, payload) => { state.currentRouteKey = payload }), setTabHasFocus: action((state, payload) => { state.tabHasFocus = payload }), setSetupMode: action((state, payload) => { state.setupMode = payload }), }, messages: { ...initialState.messages, addError: action((state, payload) => { state.errors = [...state.errors, payload] }), removeError: action((state, payload) => { state.errors = [...state.errors.filter((a) => a.id != payload)] }), setWarning: action((state, payload) => { if (payload) { state.warning = [payload] } else { state.warning = [] } }), }, }