2018-03-26 00:46:45 +05:30
|
|
|
// @flow
|
2019-06-30 19:02:50 +05:30
|
|
|
import type { Location, RouterHistory } from 'react-router-dom';
|
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 {
|
2019-11-27 14:33:32 +05:30
|
|
|
fetchAvailableApps,
|
|
|
|
resetApp,
|
|
|
|
deleteApp,
|
2018-11-04 11:52:04 +05:30
|
|
|
} 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-06-30 19:02:50 +05:30
|
|
|
type OwnProps = {|
|
2019-11-27 14:33:32 +05:30
|
|
|
location: Location,
|
|
|
|
history: RouterHistory,
|
2019-06-30 19:02:50 +05:30
|
|
|
|};
|
|
|
|
|
|
|
|
type Props = {
|
2019-11-27 14:33:32 +05:30
|
|
|
...OwnProps,
|
|
|
|
user: User,
|
|
|
|
apps: OauthAppResponse[],
|
|
|
|
fetchAvailableApps: () => Promise<void>,
|
|
|
|
deleteApp: string => Promise<void>,
|
|
|
|
resetApp: (string, boolean) => Promise<void>,
|
|
|
|
};
|
2019-01-24 05:04:02 +05:30
|
|
|
|
2019-06-30 19:02:50 +05:30
|
|
|
type State = {
|
2019-11-27 14:33:32 +05:30
|
|
|
isLoading: boolean,
|
|
|
|
forceUpdate: boolean,
|
|
|
|
};
|
2019-01-24 05:04:02 +05:30
|
|
|
|
|
|
|
class ApplicationsListPage extends Component<Props, State> {
|
2019-11-27 14:33:32 +05:30
|
|
|
state = {
|
|
|
|
isLoading: false,
|
|
|
|
forceUpdate: false,
|
|
|
|
};
|
2018-03-26 00:46:45 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
componentDidMount() {
|
|
|
|
!this.props.user.isGuest && this.loadApplicationsList();
|
|
|
|
}
|
2018-03-26 00:46:45 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
componentDidUpdate({ user }: Props) {
|
|
|
|
if (this.props.user !== user) {
|
|
|
|
// eslint-disable-next-line react/no-did-update-set-state
|
|
|
|
this.setState({ forceUpdate: true });
|
|
|
|
this.loadApplicationsList();
|
2019-01-24 05:04:02 +05:30
|
|
|
}
|
2019-11-27 14:33:32 +05:30
|
|
|
}
|
2019-01-24 05:04:02 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
render() {
|
|
|
|
const { user, apps, resetApp, deleteApp, location } = this.props;
|
|
|
|
const { isLoading, forceUpdate } = this.state;
|
|
|
|
const clientId = location.hash.substr(1) || null;
|
2018-03-26 00:46:45 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
return (
|
|
|
|
<ApplicationsIndex
|
|
|
|
displayForGuest={user.isGuest}
|
|
|
|
applications={forceUpdate ? [] : apps}
|
|
|
|
isLoading={isLoading}
|
|
|
|
deleteApp={deleteApp}
|
|
|
|
resetApp={resetApp}
|
|
|
|
clientId={clientId}
|
|
|
|
resetClientId={this.resetClientId}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2018-03-26 00:46:45 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
loadApplicationsList = async () => {
|
|
|
|
this.setState({ isLoading: true });
|
|
|
|
await this.props.fetchAvailableApps();
|
|
|
|
this.setState({
|
|
|
|
isLoading: false,
|
|
|
|
forceUpdate: false,
|
|
|
|
});
|
|
|
|
};
|
2018-11-04 11:52:04 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
resetClientId = () => {
|
|
|
|
const { history, location } = this.props;
|
2018-11-04 11:52:04 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
if (location.hash) {
|
|
|
|
history.push({ ...location, hash: '' });
|
|
|
|
}
|
|
|
|
};
|
2018-03-26 00:46:45 +05:30
|
|
|
}
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
export default connect<Props, OwnProps, _, _, _, _>(
|
|
|
|
state => ({
|
2019-01-24 05:04:02 +05:30
|
|
|
user: state.user,
|
|
|
|
apps: state.apps.available,
|
2019-11-27 14:33:32 +05:30
|
|
|
}),
|
|
|
|
// $FlowFixMe: we need a better action typings for thunks
|
|
|
|
{
|
2019-01-24 05:04:02 +05:30
|
|
|
fetchAvailableApps,
|
|
|
|
resetApp,
|
|
|
|
deleteApp,
|
2019-11-27 14:33:32 +05:30
|
|
|
},
|
|
|
|
)(ApplicationsListPage);
|