11import React from 'react'
22import classNames from 'classnames'
3- import { Link } from 'react-router-dom'
4- import { connect } from 'react-redux'
5- import { filterToggle } from '../Redux'
3+ import { Link } from 'react-router-dom'
4+ import { connect } from 'react-redux'
5+ import { filterToggle } from '../Redux'
66import { withStyles } from '@material-ui/core/styles'
7- import { withRouter } from 'react-router'
7+ import { withRouter } from 'react-router'
88import {
99 AppBar ,
1010 Toolbar ,
@@ -18,19 +18,23 @@ import {
1818 ListItemText ,
1919 FormControlLabel ,
2020 Switch ,
21- Button ,
22- Tooltip
21+ Tooltip ,
22+ Button
2323} from '@material-ui/core'
2424// import MenuIcon from '@material-ui/icons/Menu'
2525import ChevronLeftIcon from '@material-ui/icons/ChevronLeft'
2626import DoneIcon from '@material-ui/icons/Done'
27+ import axios from 'axios'
28+
29+ axios . defaults . withCredentials = true
30+ const URL = 'http://localhost:8080'
2731
2832const drawerWidth = 240
2933
30- const styles = ( theme ) => ( {
34+ const styles = ( theme ) => ( {
3135 flex : {
3236 flexGrow : 1 ,
33- userSelect :'none'
37+ userSelect : 'none'
3438 } ,
3539 appBar : {
3640 transition : theme . transitions . create ( [ 'margin' , 'width' ] , {
@@ -39,14 +43,14 @@ const styles =(theme)=>({
3943 } ) ,
4044 } ,
4145 appBarShift : {
42- width : `calc(100% - ${ drawerWidth } px)` ,
43- transition : theme . transitions . create ( [ 'margin' , 'width' ] , {
44- easing : theme . transitions . easing . easeOut ,
45- duration : theme . transitions . duration . enteringScreen ,
46- } ) ,
46+ width : `calc(100% - ${ drawerWidth } px)` ,
47+ transition : theme . transitions . create ( [ 'margin' , 'width' ] , {
48+ easing : theme . transitions . easing . easeOut ,
49+ duration : theme . transitions . duration . enteringScreen ,
50+ } ) ,
4751 } ,
4852 'appBarShift-left' : {
49- marginLeft : drawerWidth ,
53+ marginLeft : drawerWidth ,
5054 } ,
5155 menuButton : {
5256 marginLeft : - 12 ,
@@ -73,56 +77,63 @@ const menu = (
7377 < ListItemIcon >
7478 < DoneIcon />
7579 </ ListItemIcon >
76- < ListItemText primary = "已繳系學會費" />
80+ < ListItemText primary = "已繳系學會費" />
7781 </ ListItem >
7882 </ Link >
7983)
8084
8185class NavBar extends React . Component {
82- constructor ( props ) {
86+ constructor ( props ) {
8387 super ( props )
8488 this . state = {
8589 open : false
8690 }
8791 this . drawerOpen = this . drawerOpen . bind ( this )
8892 this . drawerClose = this . drawerClose . bind ( this )
8993 }
90- drawerOpen ( ) {
94+ drawerOpen ( ) {
9195 this . props . check ( true )
92- this . setState ( { open :true } )
96+ this . setState ( { open : true } )
9397 }
94- drawerClose ( ) {
98+ drawerClose ( ) {
9599 this . props . check ( false )
96- this . setState ( { open :false } )
100+ this . setState ( { open : false } )
101+ }
102+ logout ( ) {
103+ axios . post ( `${ URL } /_api/fee_logout` , { } ) . then (
104+ res => {
105+ window . location . href = '/login'
106+ }
107+ )
97108 }
98109 render ( ) {
99110 const { classes } = this . props
100111 const LDrawer = (
101- < Drawer
102- variant = "persistent"
103- open = { this . state . open }
104- classes = { {
112+ < Drawer
113+ variant = "persistent"
114+ open = { this . state . open }
115+ classes = { {
105116 paper : classes . drawerPaper ,
106- } }
107- >
108- < div className = { classes . drawerHeader } >
109- < IconButton onClick = { this . drawerClose } >
110- < ChevronLeftIcon />
111- </ IconButton >
112- </ div >
113- < Divider />
114- < List >
115- { menu }
116- </ List >
117- </ Drawer > )
117+ } }
118+ >
119+ < div className = { classes . drawerHeader } >
120+ < IconButton onClick = { this . drawerClose } >
121+ < ChevronLeftIcon />
122+ </ IconButton >
123+ </ div >
124+ < Divider />
125+ < List >
126+ { menu }
127+ </ List >
128+ </ Drawer > )
118129
119130 return (
120131 < React . Fragment >
121132 < AppBar position = "sticky"
122- className = { classNames ( classes . appBar , {
123- [ classes . appBarShift ] : this . state . open ,
124- [ classes [ 'appBarShift-left' ] ] : this . state . open ,
125- } ) } >
133+ className = { classNames ( classes . appBar , {
134+ [ classes . appBarShift ] : this . state . open ,
135+ [ classes [ 'appBarShift-left' ] ] : this . state . open ,
136+ } ) } >
126137 < Toolbar >
127138 { /* <IconButton
128139 className={classNames(classes.menuButton, this.state.open && classes.hide)}
@@ -134,7 +145,7 @@ class NavBar extends React.Component {
134145 </ Typography >
135146 {
136147 this . props . location . pathname === '/' &&
137- < Tooltip title = { this . props . filter ? '僅顯示已繳系學會費' : '顯示全部' } >
148+ < Tooltip title = { this . props . filter ? '僅顯示已繳系學會費' : '顯示全部' } >
138149 < FormControlLabel
139150 control = {
140151 < Switch
@@ -148,9 +159,9 @@ class NavBar extends React.Component {
148159 </ Tooltip >
149160 }
150161 {
151- this . props . location . pathname = == '/login' &&
152- < Button color = "inherit" onClick = { ( ) => ( window . location . href = 'https://csunion.nctu.me/_api/oauth' ) } >
153- 登入
162+ this . props . location . pathname ! == '/login' &&
163+ < Button color = "inherit" onClick = { ( ) => this . logout ( ) } >
164+ 登出
154165 </ Button >
155166 }
156167 </ Toolbar >
0 commit comments