Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/components/NavigationBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,15 @@ const NavigationBar: React.SFC<INavigationBarProps> = props => (
className="NavigationBar__link pt-button pt-minimal"
>
<Icon icon={IconNames.USER} />
<div className="navbar-button-text hidden-xs">{props.username}</div>
<div className="navbar-button-text hidden-xs">{titleCase(props.username)}</div>
</NavLink>
</>
)}
</NavbarGroup>
</Navbar>
)

const titleCase = (str: string) =>
str.replace(/\w\S*/g, wrd => wrd.charAt(0).toUpperCase() + wrd.substr(1).toLowerCase())

export default NavigationBar
32 changes: 20 additions & 12 deletions src/sagas/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,37 @@ function* backendSaga(): SagaIterator {
const ivleToken = (action as actionTypes.IAction).payload
const resp = yield call(request, 'auth', {
method: 'POST',
body: JSON.stringify({ login: { ivle_token: ivleToken } })
body: JSON.stringify({ login: { ivle_token: ivleToken } }),
headers: new Headers({
Accept: 'application/json',
'Content-Type': 'application/json'
})
})
const tokens = {
accessToken: resp.refresh_token,
refreshToken: resp.access_token
accessToken: resp.access_token,
refreshToken: resp.refresh_token
}
const username = yield call(() => 'IVLE USER') // TODO: fetchUsername
const username = yield getUsername(tokens.accessToken)
yield put(actions.setTokens(tokens))
yield put(actions.setUsername(username))
yield delay(2000)
yield history.push('/academy')
})
}

function* getUsername(accessToken: string) {
const resp = yield call(request, 'user', {
method: 'GET',
headers: new Headers({
Authorization: `Bearer ${accessToken}`,
Accept: 'application/json'
})
})
return resp.name
}

function request(path: string, opts: {}) {
const defaultOpts = {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
}
}
const requestOpts = { ...defaultOpts, ...opts }
return fetch(`${BACKEND_URL}/v1/${path}`, requestOpts)
return fetch(`${BACKEND_URL}/v1/${path}`, opts)
.then(data => data.json())
.catch(err => err)
}
Expand Down