From 1870f3fdf43707a15fda0f609a021f516f45eb63 Mon Sep 17 00:00:00 2001 From: Piotr Russ Date: Wed, 18 Nov 2020 23:15:38 +0100 Subject: finish auth routes, create cookie token, fix folder structure, add context to FE --- client/src/admin/jsx/App.jsx | 32 +++++++++++++++------------- client/src/admin/jsx/Info.jsx | 10 +++++++++ client/src/admin/jsx/LangSwitch.jsx | 42 +++++++++++++++++++++++++++++++++++++ client/src/admin/jsx/MainScreen.jsx | 10 ++++----- client/src/admin/jsx/TopBar.jsx | 35 +++++++++++++++++++++++++++++++ client/src/admin/jsx/User.jsx | 39 ++++++++++++++++++++++++++++++++++ 6 files changed, 148 insertions(+), 20 deletions(-) create mode 100644 client/src/admin/jsx/Info.jsx create mode 100644 client/src/admin/jsx/LangSwitch.jsx create mode 100644 client/src/admin/jsx/TopBar.jsx create mode 100644 client/src/admin/jsx/User.jsx (limited to 'client/src/admin/jsx') diff --git a/client/src/admin/jsx/App.jsx b/client/src/admin/jsx/App.jsx index c5be77c..146af70 100644 --- a/client/src/admin/jsx/App.jsx +++ b/client/src/admin/jsx/App.jsx @@ -3,33 +3,35 @@ import ReactDOM from 'react-dom'; import "../scss/index.scss"; -import texts from '../../common/data/texts.js'; -import TopBar from '../../common/jsx/TopBar.jsx'; -import Info from '../../common/jsx/Info.jsx'; +import TopBar from './TopBar.jsx'; +import Info from './Info.jsx'; import MainScreen from './MainScreen.jsx'; +import Context from '../context'; +import { defaultLanguage } from '../data/translations'; const App = () => { - const [adminLang, setAdminLang] = useState('en'); + const [lang, setLang] = useState(defaultLanguage); const [projects, setProjects] = useState([]); const [info, setInfo] = useState(''); const [hover, setHover] = useState(''); const [view, setView] = useState('main'); const [user, setUser] = useState(null); - const t = (key) => texts[adminLang][key] || texts['en'][key]; - // useEffect(() => { - // setInfo('no-saved-websites') - // setHover(''); - // }, [user]); + useEffect(() => { + setInfo('no-saved-websites'); + setUser('admin@op.pl'); + }, []); return ( -
- -
- { view === 'main' && } + +
+ +
+ { view === 'main' && } +
+
- -
+ ) }; diff --git a/client/src/admin/jsx/Info.jsx b/client/src/admin/jsx/Info.jsx new file mode 100644 index 0000000..75294e1 --- /dev/null +++ b/client/src/admin/jsx/Info.jsx @@ -0,0 +1,10 @@ +import React from 'react'; +import { t } from '../hocs'; + +const Info = ({ info, hover }) => ( +

+ { hover ? t(hover) : t(info) } +

+); + +export default Info; diff --git a/client/src/admin/jsx/LangSwitch.jsx b/client/src/admin/jsx/LangSwitch.jsx new file mode 100644 index 0000000..2494bef --- /dev/null +++ b/client/src/admin/jsx/LangSwitch.jsx @@ -0,0 +1,42 @@ +import React from 'react'; +import { WithHover } from '../hocs'; +import { languages } from '../data/translations.js' + +const LangSwitch = ({ lang, setLang, opened, setOpened}) => { + const handleSetLang = (key) => { + setLang(key); + setOpened(false); + }; + + return ( +
+ + setOpened(opened !== 'lang' ? 'lang' : false)} + > + {lang} + + { + opened === 'lang' && ( +
+ { + languages.map(key => key !== lang && ( + handleSetLang(key)} + > + {key} + + )) + } +
+ ) + } +
+
+ ); +}; + +export default LangSwitch; diff --git a/client/src/admin/jsx/MainScreen.jsx b/client/src/admin/jsx/MainScreen.jsx index ff28256..3d65384 100644 --- a/client/src/admin/jsx/MainScreen.jsx +++ b/client/src/admin/jsx/MainScreen.jsx @@ -1,21 +1,21 @@ import React, { Fragment } from 'react'; -import WithHover from '../../common/jsx/WithHover.jsx'; +import { WithHover, t } from '../hocs'; -const MainScreen = ({ projects, t, setHover }) => ( +const MainScreen = ({ projects }) => (

{ t('main-title') }

{ !projects.length && ( - +

{ t('edit-current-project') }

)} { !projects.length && ( - +

{ t('show-saved-projects') }

)} - +

{ t('create-new-project') }

diff --git a/client/src/admin/jsx/TopBar.jsx b/client/src/admin/jsx/TopBar.jsx new file mode 100644 index 0000000..e9be676 --- /dev/null +++ b/client/src/admin/jsx/TopBar.jsx @@ -0,0 +1,35 @@ +import React, {useState} from 'react'; +import LangSwitch from './LangSwitch.jsx'; +import User from './User.jsx'; + +const TopBar = ({ user, setUser, lang, setLang }) => { + const [opened, setOpened] = useState(false); + + return ( +
+ { opened !== false && ( +
setOpened(false)} + /> + )} + + { user && ( + + ) + } +
+ ); +}; + +export default TopBar; diff --git a/client/src/admin/jsx/User.jsx b/client/src/admin/jsx/User.jsx new file mode 100644 index 0000000..22b96b4 --- /dev/null +++ b/client/src/admin/jsx/User.jsx @@ -0,0 +1,39 @@ +import React from 'react'; +import { WithHover, t } from '../hocs'; +import logout from '../api/logout'; + +const User = ({ user, setUser, opened, setOpened }) => { + const handleLogout = () => { + setOpened(false); + logout(); + }; + const handleChangePass = () => { setOpened(false) }; + const handleRemoveUser = () => { setOpened(false) }; + + return ( +
+ + setOpened(opened !== 'user' ? 'user' : false)} + > + {user} + + { + opened === 'user' && ( +
+ + {t('logout')} + + + {t('user-settings')} + +
+ ) + } +
+
+ ); +}; + +export default User; -- cgit v1.2.3