Skip to content

Commit

Permalink
feat(login): add help docs to login flows
Browse files Browse the repository at this point in the history
  • Loading branch information
setchy committed May 17, 2024
1 parent e96fca2 commit f75cedb
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 32 deletions.
42 changes: 33 additions & 9 deletions src/routes/LoginEnterprise.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const ipcRenderer = require('electron').ipcRenderer;

import { ArrowLeftIcon } from '@primer/octicons-react';
import { ArrowLeftIcon, BookIcon } from '@primer/octicons-react';

import { type FC, useCallback, useContext, useEffect } from 'react';
import { Form, type FormRenderProps } from 'react-final-form';
Expand All @@ -9,6 +9,10 @@ import { useNavigate } from 'react-router-dom';
import { FieldInput } from '../components/fields/FieldInput';
import { AppContext } from '../context/App';
import type { AuthOptions } from '../types';
import { openExternalLink } from '../utils/comms';

const GITHUB_DOCS_URL =
'https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authenticating-to-the-rest-api-with-an-oauth-app';

interface IValues {
hostname?: string;
Expand Down Expand Up @@ -65,9 +69,16 @@ export const LoginEnterpriseRoute: FC = () => {
}
}, [enterpriseAccounts]);

const openLink = useCallback((url: string) => {
openExternalLink(url);
}, []);

const renderForm = (formProps: FormRenderProps) => {
const { handleSubmit, submitting, pristine } = formProps;

const buttonClasses =
'rounded bg-gray-300 font-semibold rounded text-sm text-center hover:bg-gray-500 hover:text-white dark:text-black focus:outline-none cursor-pointer';

return (
<form onSubmit={handleSubmit}>
<FieldInput
Expand All @@ -84,14 +95,27 @@ export const LoginEnterpriseRoute: FC = () => {
placeholder="ABC123DEF456"
/>

<button
className="float-right px-4 py-2 my-4 bg-gray-300 font-semibold rounded text-sm text-center hover:bg-gray-500 hover:text-white dark:text-black focus:outline-none"
title="Login Button"
disabled={submitting || pristine}
type="submit"
>
Login
</button>
<div className="flex justify-between items-center">
<div className="text-xs italic hover:text-blue-500 justify-center items-center">
<button
type="button"
className={`px-2 py-1 text-xs ${buttonClasses}`}
onClick={() => openLink(GITHUB_DOCS_URL)}
>
<BookIcon size={12} /> Docs
</button>
</div>
<div>
<button
className="float-right px-4 py-2 my-4 bg-gray-300 font-semibold rounded text-sm text-center hover:bg-gray-500 hover:text-white dark:text-black focus:outline-none"
title="Login Button"
disabled={submitting || pristine}
type="submit"
>
Login
</button>
</div>
</div>
</form>
);
};
Expand Down
34 changes: 25 additions & 9 deletions src/routes/LoginWithToken.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ArrowLeftIcon } from '@primer/octicons-react';
import { ArrowLeftIcon, BookIcon } from '@primer/octicons-react';

import { type FC, useCallback, useContext, useState } from 'react';
import { Form, type FormRenderProps } from 'react-final-form';
Expand All @@ -12,6 +12,9 @@ import { Constants } from '../utils/constants';

import { format } from 'date-fns';

const GITHUB_DOCS_URL =
'https://docs.github.com/en/enterprise-server@3.13/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens';

interface IValues {
token?: string;
hostname?: string;
Expand Down Expand Up @@ -103,14 +106,27 @@ export const LoginWithToken: FC = () => {
</div>
)}

<button
className={`float-right px-4 py-2 my-4 ${buttonClasses}`}
title="Submit Button"
disabled={submitting || pristine}
type="submit"
>
Submit
</button>
<div className="flex justify-between items-center">
<div className="text-xs italic hover:text-blue-500 justify-center items-center">
<button
type="button"
className={`px-2 py-1 text-xs ${buttonClasses}`}
onClick={() => openLink(GITHUB_DOCS_URL)}
>
<BookIcon size={12} /> Docs
</button>
</div>
<div>
<button
className={`float-right px-4 py-2 my-4 ${buttonClasses}`}
title="Submit Button"
disabled={submitting || pristine}
type="submit"
>
Submit
</button>
</div>
</div>
</form>
);
};
Expand Down
52 changes: 45 additions & 7 deletions src/routes/__snapshots__/LoginEnterprise.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 45 additions & 7 deletions src/routes/__snapshots__/LoginWithToken.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f75cedb

Please sign in to comment.