2019-12-07 16:58:52 +05:30
|
|
|
import React from 'react';
|
|
|
|
import { RouteComponentProps } from 'react-router-dom';
|
2018-05-05 13:12:29 +05:30
|
|
|
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,
|
2019-12-08 00:32:00 +05:30
|
|
|
} from 'app/components/dev/apps/actions';
|
|
|
|
import ApplicationsIndex from 'app/components/dev/apps/ApplicationsIndex';
|
|
|
|
import { User } from 'app/components/user';
|
|
|
|
import { OauthAppResponse } from 'app/services/api/oauth';
|
|
|
|
import { RootState } from 'app/reducers';
|
2018-03-26 00:46:45 +05:30
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
interface Props extends RouteComponentProps {
|
|
|
|
user: User;
|
|
|
|
apps: OauthAppResponse[];
|
|
|
|
fetchAvailableApps: () => Promise<void>;
|
|
|
|
deleteApp: (clientId: string) => Promise<void>;
|
|
|
|
resetApp: (clientId: string, resetClientSecret: boolean) => Promise<void>;
|
|
|
|
}
|
2019-01-24 05:04:02 +05:30
|
|
|
|
2019-06-30 19:02:50 +05:30
|
|
|
type State = {
|
2019-12-07 16:58:52 +05:30
|
|
|
isLoading: boolean;
|
|
|
|
forceUpdate: boolean;
|
2019-11-27 14:33:32 +05:30
|
|
|
};
|
2019-01-24 05:04:02 +05:30
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
class ApplicationsListPage extends React.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-12-07 16:58:52 +05:30
|
|
|
export default connect(
|
|
|
|
(state: RootState) => ({
|
2019-01-24 05:04:02 +05:30
|
|
|
user: state.user,
|
|
|
|
apps: state.apps.available,
|
2019-11-27 14:33:32 +05:30
|
|
|
}),
|
|
|
|
{
|
2019-01-24 05:04:02 +05:30
|
|
|
fetchAvailableApps,
|
|
|
|
resetApp,
|
|
|
|
deleteApp,
|
2019-11-27 14:33:32 +05:30
|
|
|
},
|
|
|
|
)(ApplicationsListPage);
|