erp-platform/ui/src/store/locale.model.ts
Sedat ÖZTÜRK e1a9562b22 init project
2025-05-06 09:45:49 +03:00

39 lines
1.1 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, ThunkOn } from 'easy-peasy'
import { action, thunkOn } from 'easy-peasy'
import appConfig from '../configs/app.config'
import { Injections, StoreModel } from '.'
export interface LocaleStoreModel {
currentLang: string
currentUiVersion: string | undefined
}
export interface LocaleStoreActions {
setLang: Action<LocaleStoreModel, string>
onSetLang: ThunkOn<LocaleModel, Injections, StoreModel>
setUiVersion: Action<LocaleStoreModel, string | undefined>
}
export type LocaleModel = LocaleStoreModel & LocaleStoreActions
const initialState: LocaleStoreModel = {
currentLang: appConfig.locale,
currentUiVersion: appConfig.uiVersion
}
export const localeModel: LocaleModel = {
...initialState,
setLang: action((state, payload) => {
state.currentLang = payload
}),
onSetLang: thunkOn(
(actions) => actions.setLang,
async (actions, target, helpers) => {
// Dil değiştiğince AppConfig ve Localizationları tekrar al
helpers.getStoreActions().abpConfig.getConfig(false)
},
),
setUiVersion: action((state, payload) => {
state.currentUiVersion = payload
}),
}