From 124170492ccd0d1db5d493584097404215a39d19 Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Sat, 20 Jun 2020 14:10:58 +0200 Subject: [PATCH] Refactored --- src/App.tsx | 31 +++++++++------ src/businesslogic/BusinessLogicProvider.tsx | 18 ++++++--- src/components/RightBar/index.tsx | 5 ++- src/components/TopBar/Profile.tsx | 22 +++++------ src/components/TopBar/index.tsx | 43 +++++++++++++++++---- 5 files changed, 81 insertions(+), 38 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 70c2e30..4e946f1 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -5,6 +5,8 @@ import "./App.scss"; import Schedule from "./components/Calendar/"; import { appointments } from "./components/Calendar/appointments"; import RightBar from "./components/RightBar"; +import BusinessLogicContext from "./businesslogic/BusinessLogicContext"; +import { BuisnessProvided } from "./businesslogic/BusinessLogicProvider"; function App() { const [isOpenTransfer, setOpenTransfer] = useState(false); @@ -53,17 +55,24 @@ function App() { return (
- { - setText(e.target.value); - }} - handleTransfer={(e) => { - setOpenTransfer(!isOpenTransfer); - }} - onLangChange={(e) => { - console.log(e); - }} - /> + + {(context) => ( + { + setText(e.target.value); + }} + handleTransfer={(e) => { + setOpenTransfer(!isOpenTransfer); + }} + onLangChange={(e) => { + console.log(e); + }} + handleLogout={() => { + (context as BuisnessProvided).reducers.userlogout(); + }} + /> + )} + { diff --git a/src/businesslogic/BusinessLogicProvider.tsx b/src/businesslogic/BusinessLogicProvider.tsx index 297133c..4cdb84a 100644 --- a/src/businesslogic/BusinessLogicProvider.tsx +++ b/src/businesslogic/BusinessLogicProvider.tsx @@ -4,7 +4,9 @@ import { User } from "./models/user"; export interface BuisnessProvided { states: BusinessState; - reducers: () => void; + reducers: { + userlogout: () => void; + }; } interface BusinessState { @@ -42,11 +44,15 @@ class BusinessLogicProvider extends Component { } redirectToCASLogoutService() { - window.location.replace(`https://cas.amu.edu.pl/cas/logout?service=${window.origin}`); + window.location.replace( + `https://cas.amu.edu.pl/cas/logout?service=${window.origin}` + ); } redirectToCASLoginService() { - window.location.replace(`https://cas.amu.edu.pl/cas/login?service=${window.origin}&locale=pl`); + window.location.replace( + `https://cas.amu.edu.pl/cas/login?service=${window.origin}&locale=pl` + ); } render() { @@ -54,8 +60,10 @@ class BusinessLogicProvider extends Component { { - this.logout(); + reducers: { + userlogout: () => { + this.logout(); + }, }, }} > diff --git a/src/components/RightBar/index.tsx b/src/components/RightBar/index.tsx index e6c31ee..b2d70aa 100644 --- a/src/components/RightBar/index.tsx +++ b/src/components/RightBar/index.tsx @@ -21,14 +21,15 @@ export default class RightBar extends React.Component<
{(context) => ( -

+

{JSON.stringify( (context as BuisnessProvided).states.user ?.ticket )} -

+

)}
+

Semestr zimowy 2020/2021

{this.props.lectures.map((classgroup, index) => ( void; + handleLogout: () => void; } export const Profile: FC = ({ anchorEl, handleClose, + handleLogout, ...restProps }) => { return ( @@ -24,17 +24,13 @@ export const Profile: FC = ({ > Profile My account - - {(context) => ( - { - (context as BuisnessProvided).reducers(); - }} - > - Logout - - )} - + { + handleLogout(); + }} + > + Logout + ); }; diff --git a/src/components/TopBar/index.tsx b/src/components/TopBar/index.tsx index 4d5c22d..c0455ce 100644 --- a/src/components/TopBar/index.tsx +++ b/src/components/TopBar/index.tsx @@ -12,7 +12,10 @@ import { Profile } from "./Profile"; interface TopBarProps { handleTransfer: (e: React.MouseEvent) => void; onLangChange: (lang: boolean) => void; - textChangeHandler: (e: React.ChangeEvent) => void; + handleLogout: () => void; + textChangeHandler: ( + e: React.ChangeEvent + ) => void; } interface TopBarState { @@ -64,29 +67,55 @@ export default class TopBar extends React.Component { return (
- logo + logo
plan na plan
- search + search this.handleChange(e)} /> - close + close
- transfer + transfer change_language - profile - + profile +
);