accounts-frontend/packages/app/components/dev/apps/ApplicationsIndex.tsx

157 lines
5.9 KiB
TypeScript
Raw Normal View History

2019-12-07 16:58:52 +05:30
import React from 'react';
2019-12-08 01:13:08 +05:30
import clsx from 'clsx';
import { defineMessages, FormattedMessage as Message } from 'react-intl';
import { Helmet } from 'react-helmet-async';
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';
import styles from './applicationsIndex.scss';
import cubeIcon from './icons/cube.svg';
import loadingCubeIcon from './icons/loading-cube.svg';
import toolsIcon from './icons/tools.svg';
import ApplicationsList from './list';
const labels = defineMessages({
addNew: 'Add new',
authorization: 'Authorization',
});
type Props = {
2020-05-24 04:38:24 +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>;
};
2019-12-07 16:58:52 +05:30
export default class ApplicationsIndex extends React.Component<Props> {
2020-05-24 04:38:24 +05:30
render() {
return (
<div className={styles.container}>
<div className={styles.welcomeContainer}>
<Message key="accountsForDevelopers" defaultMessage="Ely.by Accounts for developers">
2020-05-24 04:38:24 +05:30
{(pageTitle: string) => (
<h2 className={styles.welcomeTitle}>
<Helmet title={pageTitle} />
{pageTitle}
</h2>
)}
</Message>
<div className={styles.welcomeTitleDelimiter} />
<div className={styles.welcomeParagraph}>
<Message
key="accountsAllowsYouYoUseOauth2"
defaultMessage="Ely.by Accounts service provides users with a quick and easy-to-use way to login to your site, launcher or Minecraft server via OAuth2 authorization protocol. You can find more information about integration with Ely.by Accounts in {ourDocumentation}."
2020-05-24 04:38:24 +05:30
values={{
ourDocumentation: (
<a href="https://docs.ely.by/en/oauth.html" target="_blank">
<Message key="ourDocumentation" defaultMessage="our documentation" />
2020-05-24 04:38:24 +05:30
</a>
),
}}
/>
</div>
<div className={styles.welcomeParagraph}>
<Message
key="ifYouHaveAnyTroubles"
defaultMessage="If you are experiencing difficulties, you can always use {feedback}. We'll surely help you."
2020-05-24 04:38:24 +05:30
values={{
feedback: (
<ContactLink>
<Message key="feedback" defaultMessage="feedback" />
2020-05-24 04:38:24 +05:30
</ContactLink>
),
}}
/>
</div>
</div>
2020-05-24 04:38:24 +05:30
{this.getContent()}
</div>
);
}
2020-05-24 04:38:24 +05:30
getContent() {
const { displayForGuest, applications, isLoading, resetApp, deleteApp, clientId, resetClientId } = this.props;
2020-05-24 04:38:24 +05:30
if (applications.length > 0) {
return (
<ApplicationsList
applications={applications}
resetApp={resetApp}
deleteApp={deleteApp}
clientId={clientId}
resetClientId={resetClientId}
/>
);
}
2020-05-24 04:38:24 +05:30
if (displayForGuest) {
return <Guest />;
}
2020-05-24 04:38:24 +05:30
return <Loader noApps={!isLoading} />;
}
}
function Loader({ noApps }: { noApps: boolean }) {
2020-05-24 04:38:24 +05:30
return (
<div className={styles.emptyState} data-e2e={noApps ? 'noApps' : 'loading'}>
<img src={noApps ? cubeIcon : loadingCubeIcon} className={styles.emptyStateIcon} />
2020-05-24 04:38:24 +05:30
<div
className={clsx(styles.noAppsContainer, {
[styles.noAppsAnimating]: noApps,
})}
>
<div className={styles.emptyStateText}>
<div>
<Message
key="youDontHaveAnyApplication"
defaultMessage="You don't have any app registered yet."
/>
2020-05-24 04:38:24 +05:30
</div>
<div>
<Message key="shallWeStart" defaultMessage="Shall we start?" />
2020-05-24 04:38:24 +05:30
</div>
</div>
2020-05-24 04:38:24 +05:30
<LinkButton
to="/dev/applications/new"
data-e2e="newApp"
label={labels.addNew}
2020-05-24 04:38:24 +05:30
color={COLOR_GREEN}
className={styles.emptyStateActionButton}
/>
</div>
</div>
);
}
function Guest() {
2020-05-24 04:38:24 +05:30
return (
<div className={styles.emptyState}>
<img src={toolsIcon} className={styles.emptyStateIcon} />
<div className={styles.emptyStateText}>
<div>
<Message key="weDontKnowAnythingAboutYou" defaultMessage="We don't know anything about you yet." />
2020-05-24 04:38:24 +05:30
</div>
<div>
<Message key="youMustAuthToBegin" defaultMessage="You have to authorize to start." />
2020-05-24 04:38:24 +05:30
</div>
</div>
2020-05-24 04:38:24 +05:30
<LinkButton
to="/login"
label={labels.authorization}
2020-05-24 04:38:24 +05:30
color={COLOR_BLUE}
className={styles.emptyStateActionButton}
/>
</div>
);
}