2018-03-26 00:46:45 +05:30
|
|
|
// @flow
|
2018-11-04 11:52:04 +05:30
|
|
|
import type { Location, RouterHistory } from 'react-router';
|
2018-03-26 00:46:45 +05:30
|
|
|
import type { User } from 'components/user';
|
|
|
|
import type { OauthAppResponse } from 'services/api/oauth';
|
2018-05-05 13:12:29 +05:30
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
2018-11-04 11:52:04 +05:30
|
|
|
import {
|
|
|
|
fetchAvailableApps,
|
|
|
|
resetApp,
|
|
|
|
deleteApp
|
|
|
|
} from 'components/dev/apps/actions';
|
2018-05-05 13:12:29 +05:30
|
|
|
import ApplicationsIndex from 'components/dev/apps/ApplicationsIndex';
|
2018-03-26 00:46:45 +05:30
|
|
|
|
2018-11-04 11:52:04 +05:30
|
|
|
class ApplicationsListPage extends Component<
|
|
|
|
{
|
|
|
|
location: Location,
|
|
|
|
history: RouterHistory,
|
|
|
|
user: User,
|
|
|
|
apps: Array<OauthAppResponse>,
|
|
|
|
fetchAvailableApps: () => Promise<void>,
|
|
|
|
deleteApp: string => Promise<void>,
|
|
|
|
resetApp: (string, bool) => Promise<void>
|
|
|
|
},
|
|
|
|
{
|
|
|
|
isLoading: bool
|
|
|
|
}
|
|
|
|
> {
|
2018-03-26 00:46:45 +05:30
|
|
|
state = {
|
2018-11-04 11:52:04 +05:30
|
|
|
isLoading: false
|
2018-03-26 00:46:45 +05:30
|
|
|
};
|
|
|
|
|
2018-05-05 13:12:29 +05:30
|
|
|
componentDidMount() {
|
2018-03-26 00:46:45 +05:30
|
|
|
!this.props.user.isGuest && this.loadApplicationsList();
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-05-05 13:12:29 +05:30
|
|
|
const { user, apps, resetApp, deleteApp, location } = this.props;
|
2018-03-26 00:46:45 +05:30
|
|
|
const { isLoading } = this.state;
|
2018-05-05 13:12:29 +05:30
|
|
|
const clientId = location.hash.substr(1) || null;
|
2018-03-26 00:46:45 +05:30
|
|
|
|
|
|
|
return (
|
|
|
|
<ApplicationsIndex
|
|
|
|
displayForGuest={user.isGuest}
|
|
|
|
applications={apps}
|
|
|
|
isLoading={isLoading}
|
|
|
|
deleteApp={deleteApp}
|
|
|
|
resetApp={resetApp}
|
2018-05-05 13:12:29 +05:30
|
|
|
clientId={clientId}
|
2018-11-04 11:52:04 +05:30
|
|
|
resetClientId={this.resetClientId}
|
2018-03-26 00:46:45 +05:30
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
loadApplicationsList = async () => {
|
2018-11-04 11:52:04 +05:30
|
|
|
this.setState({ isLoading: true });
|
2018-03-26 00:46:45 +05:30
|
|
|
await this.props.fetchAvailableApps();
|
2018-11-04 11:52:04 +05:30
|
|
|
this.setState({ isLoading: false });
|
|
|
|
};
|
|
|
|
|
|
|
|
resetClientId = () => {
|
|
|
|
const { history, location } = this.props;
|
|
|
|
|
|
|
|
if (location.hash) {
|
|
|
|
history.push({ ...location, hash: '' });
|
|
|
|
}
|
2018-03-26 00:46:45 +05:30
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-11-04 11:52:04 +05:30
|
|
|
export default connect(
|
|
|
|
(state) => ({
|
|
|
|
user: state.user,
|
|
|
|
apps: state.apps.available
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
fetchAvailableApps,
|
|
|
|
resetApp,
|
|
|
|
deleteApp
|
|
|
|
}
|
|
|
|
)(ApplicationsListPage);
|