2019-12-07 16:58:52 +05:30
|
|
|
import React from 'react';
|
2019-12-08 01:13:08 +05:30
|
|
|
import clsx from 'clsx';
|
2018-03-26 00:46:45 +05:30
|
|
|
import { FormattedMessage as Message } from 'react-intl';
|
|
|
|
import { Helmet } from 'react-helmet';
|
2019-12-08 00:32:00 +05:30
|
|
|
import { LinkButton } from 'app/components/ui/form';
|
|
|
|
import { COLOR_GREEN, COLOR_BLUE } from 'app/components/ui';
|
|
|
|
import { ContactLink } from 'app/components/contact';
|
|
|
|
import { OauthAppResponse } from 'app/services/api/oauth';
|
2018-03-26 00:46:45 +05:30
|
|
|
|
|
|
|
import styles from './applicationsIndex.scss';
|
|
|
|
import messages from './ApplicationsIndex.intl.json';
|
|
|
|
import cubeIcon from './icons/cube.svg';
|
|
|
|
import loadingCubeIcon from './icons/loading-cube.svg';
|
|
|
|
import toolsIcon from './icons/tools.svg';
|
2018-11-04 11:01:31 +05:30
|
|
|
import ApplicationsList from './list';
|
2018-03-26 00:46:45 +05:30
|
|
|
|
|
|
|
type Props = {
|
2019-12-07 16:58:52 +05:30
|
|
|
clientId: string | null;
|
|
|
|
resetClientId: () => void; // notify parent to remove clientId from current location.href
|
|
|
|
displayForGuest: boolean;
|
|
|
|
applications: Array<OauthAppResponse>;
|
|
|
|
isLoading: boolean;
|
|
|
|
deleteApp: (clientId: string) => Promise<any>;
|
|
|
|
resetApp: (clientId: string, resetClientSecret: boolean) => Promise<any>;
|
2018-03-26 00:46:45 +05:30
|
|
|
};
|
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
export default class ApplicationsIndex extends React.Component<Props> {
|
2019-11-27 14:33:32 +05:30
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div className={styles.container}>
|
|
|
|
<div className={styles.welcomeContainer}>
|
|
|
|
<Message {...messages.accountsForDevelopers}>
|
|
|
|
{(pageTitle: string) => (
|
|
|
|
<h2 className={styles.welcomeTitle}>
|
|
|
|
<Helmet title={pageTitle} />
|
|
|
|
{pageTitle}
|
|
|
|
</h2>
|
|
|
|
)}
|
|
|
|
</Message>
|
|
|
|
<div className={styles.welcomeTitleDelimiter} />
|
|
|
|
<div className={styles.welcomeParagraph}>
|
|
|
|
<Message
|
|
|
|
{...messages.accountsAllowsYouYoUseOauth2}
|
|
|
|
values={{
|
|
|
|
ourDocumentation: (
|
|
|
|
<a href="https://docs.ely.by/en/oauth.html" target="_blank">
|
|
|
|
<Message {...messages.ourDocumentation} />
|
|
|
|
</a>
|
|
|
|
),
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className={styles.welcomeParagraph}>
|
|
|
|
<Message
|
|
|
|
{...messages.ifYouHaveAnyTroubles}
|
|
|
|
values={{
|
|
|
|
feedback: (
|
|
|
|
<ContactLink>
|
|
|
|
<Message {...messages.feedback} />
|
|
|
|
</ContactLink>
|
|
|
|
),
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2018-03-26 00:46:45 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
{this.getContent()}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2018-11-04 11:01:31 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
getContent() {
|
|
|
|
const {
|
|
|
|
displayForGuest,
|
|
|
|
applications,
|
|
|
|
isLoading,
|
|
|
|
resetApp,
|
|
|
|
deleteApp,
|
|
|
|
clientId,
|
|
|
|
resetClientId,
|
|
|
|
} = this.props;
|
2019-01-24 05:04:02 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
if (applications.length > 0) {
|
|
|
|
return (
|
|
|
|
<ApplicationsList
|
|
|
|
applications={applications}
|
|
|
|
resetApp={resetApp}
|
|
|
|
deleteApp={deleteApp}
|
|
|
|
clientId={clientId}
|
|
|
|
resetClientId={resetClientId}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2018-11-04 11:01:31 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
if (displayForGuest) {
|
|
|
|
return <Guest />;
|
2018-11-04 11:01:31 +05:30
|
|
|
}
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
return <Loader noApps={!isLoading} />;
|
|
|
|
}
|
|
|
|
}
|
2019-01-15 02:22:42 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
function Loader({ noApps }: { noApps: boolean }) {
|
|
|
|
return (
|
|
|
|
<div className={styles.emptyState} data-e2e={noApps ? 'noApps' : 'loading'}>
|
|
|
|
<img
|
|
|
|
src={noApps ? cubeIcon : loadingCubeIcon}
|
|
|
|
className={styles.emptyStateIcon}
|
|
|
|
/>
|
2019-01-15 02:22:42 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
<div
|
2019-12-08 01:13:08 +05:30
|
|
|
className={clsx(styles.noAppsContainer, {
|
2019-11-27 14:33:32 +05:30
|
|
|
[styles.noAppsAnimating]: noApps,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<div className={styles.emptyStateText}>
|
|
|
|
<div>
|
|
|
|
<Message {...messages.youDontHaveAnyApplication} />
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<Message {...messages.shallWeStart} />
|
|
|
|
</div>
|
2018-11-04 11:01:31 +05:30
|
|
|
</div>
|
2019-11-27 14:33:32 +05:30
|
|
|
|
|
|
|
<LinkButton
|
|
|
|
to="/dev/applications/new"
|
|
|
|
data-e2e="newApp"
|
|
|
|
label={messages.addNew}
|
|
|
|
color={COLOR_GREEN}
|
|
|
|
className={styles.emptyStateActionButton}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2018-11-04 11:01:31 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
function Guest() {
|
2019-11-27 14:33:32 +05:30
|
|
|
return (
|
|
|
|
<div className={styles.emptyState}>
|
|
|
|
<img src={toolsIcon} className={styles.emptyStateIcon} />
|
|
|
|
<div className={styles.emptyStateText}>
|
|
|
|
<div>
|
|
|
|
<Message {...messages.weDontKnowAnythingAboutYou} />
|
2018-11-04 11:01:31 +05:30
|
|
|
</div>
|
2019-11-27 14:33:32 +05:30
|
|
|
<div>
|
|
|
|
<Message {...messages.youMustAuthToBegin} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<LinkButton
|
|
|
|
to="/login"
|
|
|
|
label={messages.authorization}
|
|
|
|
color={COLOR_BLUE}
|
|
|
|
className={styles.emptyStateActionButton}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
2018-11-04 11:01:31 +05:30
|
|
|
}
|