Skip to content

Commit

Permalink
feat(admin-ui): remember languange and theme config after user logout
Browse files Browse the repository at this point in the history
  • Loading branch information
harryandriyan committed Aug 22, 2022
1 parent cee28ef commit 3580382
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions admin-ui/app/redux/reducers/LogoutReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ const INIT_STATE = {}

export default function logoutReducer(state = INIT_STATE, action) {
if (action.type === USER_LOGGED_OUT) {
const initTheme = localStorage.getItem('initTheme')
const initLang = localStorage.getItem('initLang')
localStorage.clear()
localStorage.setItem('initTheme', initTheme)
localStorage.setItem('initLang', initLang)
}
return state
}
Expand Down
12 changes: 11 additions & 1 deletion admin-ui/app/routes/Apps/Gluu/LanguageMenu.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react'
import React, { useState, useEffect } from 'react'
import { useTranslation } from 'react-i18next'
import {
DropdownToggle,
Expand All @@ -9,13 +9,23 @@ import {

const LanguageMenu = () => {
const [isOpen, setOpen] = useState(false)
const initLang = localStorage.getItem('initLang')
const [lang, setLang] = useState('en')
const { t, i18n } = useTranslation()
const toggle = () => setOpen(!isOpen)

function changeLanguage(code) {
i18n.changeLanguage(code)
setLang(code)
localStorage.setItem('initLang', code)
}

useEffect(() => {
i18n.changeLanguage(initLang)
const currentLang = initLang ? initLang : 'en'
setLang(currentLang)
}, [initLang])

return (
<ButtonDropdown isOpen={isOpen} toggle={toggle}>
<DropdownToggle caret color="transparent" data-testid="ACTIVE_LANG">
Expand Down

0 comments on commit 3580382

Please sign in to comment.