availableLocales.ts 699 B

12345678910111213141516171819202122
  1. // Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. import { QueryHandler } from '@shared/server/apollo/handler'
  3. import { useLocalesQuery } from '@shared/graphql/queries/locales.api'
  4. import type { LocalesQuery } from '@shared/graphql/types'
  5. let availableLocales: Maybe<LocalesQuery['locales']>
  6. const getAvailableLocales = async (): Promise<
  7. Maybe<LocalesQuery['locales']>
  8. > => {
  9. if (availableLocales !== undefined) return availableLocales
  10. const query = new QueryHandler(useLocalesQuery({ onlyActive: true }))
  11. const result = await query.loadedResult()
  12. availableLocales = result?.locales || null
  13. return availableLocales
  14. }
  15. export default getAvailableLocales