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
|
|
|
|
2019-01-24 05:04:02 +05:30
|
|
|
interface Props {
|
|
|
|
location: Location;
|
|
|
|
history: RouterHistory;
|
|
|
|
user: User;
|
|
|
|
apps: Array<OauthAppResponse>;
|
|
|
|
fetchAvailableApps: () => Promise<void>;
|
|
|
|
deleteApp: string => Promise<void>;
|
|
|
|
resetApp: (string, bool) => Promise<void>;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface State {
|
|
|
|
isLoading: bool;
|
|
|
|
forceUpdate: bool;
|
|
|
|
}
|
|
|
|
|
|
|
|
class ApplicationsListPage extends Component<Props, State> {
|
2018-03-26 00:46:45 +05:30
|
|
|
state = {
|
2019-01-24 05:04:02 +05:30
|
|
|
isLoading: false,
|
|
|
|
forceUpdate: 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();
|
|
|
|
}
|
|
|
|
|
2019-01-24 05:04:02 +05:30
|
|
|
componentDidUpdate({ user }) {
|
|
|
|
if (this.props.user !== user) {
|
|
|
|
// eslint-disable-next-line react/no-did-update-set-state
|
|
|
|
this.setState({ forceUpdate: true });
|
|
|
|
this.loadApplicationsList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-26 00:46:45 +05:30
|
|
|
render() {
|
2018-05-05 13:12:29 +05:30
|
|
|
const { user, apps, resetApp, deleteApp, location } = this.props;
|
2019-01-24 05:04:02 +05:30
|
|
|
const { isLoading, forceUpdate } = 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}
|
2019-01-24 05:04:02 +05:30
|
|
|
applications={forceUpdate ? [] : apps}
|
2018-03-26 00:46:45 +05:30
|
|
|
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();
|
2019-01-24 05:04:02 +05:30
|
|
|
this.setState({
|
|
|
|
isLoading: false,
|
|
|
|
forceUpdate: false,
|
|
|
|
});
|
2018-11-04 11:52:04 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
resetClientId = () => {
|
|
|
|
const { history, location } = this.props;
|
|
|
|
|
|
|
|
if (location.hash) {
|
|
|
|
history.push({ ...location, hash: '' });
|
|
|
|
}
|
2018-03-26 00:46:45 +05:30
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-01-24 05:04:02 +05:30
|
|
|
export default connect((state) => ({
|
|
|
|
user: state.user,
|
|
|
|
apps: state.apps.available,
|
|
|
|
}), {
|
|
|
|
fetchAvailableApps,
|
|
|
|
resetApp,
|
|
|
|
deleteApp,
|
|
|
|
})(ApplicationsListPage);
|