Files
boursecu_user/src/views/base/rules/composables/useRulesPage.ts
T

56 lines
1.6 KiB
TypeScript
Raw Normal View History

import { computed, inject, provide, type ComputedRef, type InjectionKey } from 'vue'
import { useConfigStore } from '@/store/configStore'
import {
getProjectBaleLink,
getProjectSupportPhoneLink,
isBoursecuProject,
} from '@/utils/config'
import { getRulesBlocks, getRulesTitle, type RulesBlock } from '../rulesContent'
export interface RulesPageContext {
config: ReturnType<typeof useConfigStore>
nameProject: ComputedRef<string>
isBoursecu: ComputedRef<boolean>
rulesTitle: ComputedRef<string>
rulesBlocks: ComputedRef<RulesBlock[]>
getProjectSupportPhoneLink: typeof getProjectSupportPhoneLink
getProjectBaleLink: typeof getProjectBaleLink
}
export const RULES_PAGE_CONTEXT_KEY: InjectionKey<RulesPageContext> = Symbol('rulesPageContext')
export function useRulesPage() {
const config = useConfigStore()
const nameProject = computed(
() => config.config?.name_fa || config.config?.name || 'بورس مس',
)
const isBoursecu = computed(() => isBoursecuProject())
const rulesTitle = computed(() => getRulesTitle(nameProject.value, isBoursecu.value))
const rulesBlocks = computed(() => getRulesBlocks(nameProject.value, isBoursecu.value))
const context: RulesPageContext = {
config,
nameProject,
isBoursecu,
rulesTitle,
rulesBlocks,
getProjectSupportPhoneLink,
getProjectBaleLink,
}
provide(RULES_PAGE_CONTEXT_KEY, context)
return context
}
export function useRulesPageContext() {
const context = inject(RULES_PAGE_CONTEXT_KEY)
if (!context) {
throw new Error('useRulesPageContext must be used within a page that calls useRulesPage()')
}
return context
}