diff --git a/services/backend/src/routes/users.ts b/services/backend/src/routes/users.ts index 836f77f5af..516b677c15 100644 --- a/services/backend/src/routes/users.ts +++ b/services/backend/src/routes/users.ts @@ -4,6 +4,8 @@ import { roles } from '../config/roles' import * as auth from '../middleware/auth' import { sendNotificationAboutAccessToUser, previewNotificationAboutAccessToUser } from '../services/mailService' import * as userService from '../services/userService' +import { LANGUAGE_CODES } from '../shared/language' +import { Language } from '../types' import logger from '../util/logger' const router = Router() @@ -101,7 +103,7 @@ router.delete('/:uid/elements', auth.roles(['admin']), async (req: ElementsReque interface ChangeLanguageRequest extends Request { body: { - language: string + language: Language } } @@ -109,7 +111,7 @@ router.post('/language', async (req: ChangeLanguageRequest, res: Response) => { const { body: { language }, } = req - if (!['fi', 'sv', 'en'].includes(language)) { + if (!LANGUAGE_CODES.includes(language)) { return res.status(400).json('Invalid language') } try { diff --git a/services/frontend/src/components/LanguagePicker/index.jsx b/services/frontend/src/components/LanguagePicker/index.jsx index 9080aa4e90..7ab00d08bb 100644 --- a/services/frontend/src/components/LanguagePicker/index.jsx +++ b/services/frontend/src/components/LanguagePicker/index.jsx @@ -1,6 +1,6 @@ import { Dropdown } from 'semantic-ui-react' -import { LANGUAGE_CODES } from '@/constants' +import { LANGUAGE_CODES } from '@/shared/language' import { useLanguage } from './useLanguage' export const LanguagePicker = () => { diff --git a/services/frontend/src/components/LanguagePicker/useLanguage.jsx b/services/frontend/src/components/LanguagePicker/useLanguage.jsx index 93d16b2d7c..02e66a19f4 100644 --- a/services/frontend/src/components/LanguagePicker/useLanguage.jsx +++ b/services/frontend/src/components/LanguagePicker/useLanguage.jsx @@ -1,8 +1,8 @@ import { createContext, useState, useCallback, useContext, useEffect } from 'react' -import { DEFAULT_LANG, LANGUAGE_CODES } from '@/constants' import { useGetAuthorizedUserQuery } from '@/redux/auth' import { useModifyLanguageMutation } from '@/redux/users' +import { DEFAULT_LANG, LANGUAGE_CODES } from '@/shared/language' const LanguageContext = createContext([[], () => {}]) LanguageContext.displayName = 'Language' diff --git a/services/frontend/src/constants/index.js b/services/frontend/src/constants/index.js index 7ae09560f7..d1dc63b621 100644 --- a/services/frontend/src/constants/index.js +++ b/services/frontend/src/constants/index.js @@ -1,5 +1,3 @@ -export const DEFAULT_LANG = 'fi' - export const PRIORITYCODE_TEXTS = { 1: 'Main', 2: 'Secondary', @@ -10,5 +8,3 @@ export const PRIORITYCODE_TEXTS = { // Increment this if search history code changes // so it will be reseted for all users. export const SEARCH_HISTORY_VERSION = '1.0' - -export const LANGUAGE_CODES = ['fi', 'en', 'sv'] diff --git a/services/frontend/src/redux/settings.js b/services/frontend/src/redux/settings.js index af506a4539..1980fecefd 100644 --- a/services/frontend/src/redux/settings.js +++ b/services/frontend/src/redux/settings.js @@ -1,4 +1,4 @@ -import { DEFAULT_LANG } from '@/constants' +import { DEFAULT_LANG } from '@/shared/language' const initialState = { language: DEFAULT_LANG, diff --git a/services/shared/language.ts b/services/shared/language.ts new file mode 100644 index 0000000000..8f61d41731 --- /dev/null +++ b/services/shared/language.ts @@ -0,0 +1,2 @@ +export const DEFAULT_LANG = 'fi' +export const LANGUAGE_CODES = ['fi', 'en', 'sv'] as const diff --git a/services/shared/tsconfig.json b/services/shared/tsconfig.json index aa444cea28..1ba4d00eec 100644 --- a/services/shared/tsconfig.json +++ b/services/shared/tsconfig.json @@ -19,5 +19,5 @@ "inlineSources": true, "resolveJsonModule": true }, - "include": ["util/**/*", "index.ts"] + "include": ["**/*.ts"] }