Skip to content

Commit 6d7b6cc

Browse files
authored
refactor: improve PAT login experience (#999)
1 parent 8ab322a commit 6d7b6cc

File tree

5 files changed

+75
-54
lines changed

5 files changed

+75
-54
lines changed

src/components/fields/FieldInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const FieldInput: FC<IProps> = ({
3131

3232
<input
3333
type={type}
34-
className="appearance-none block w-full dark:text-gray-800 bg-gray-100 border border-red rounded py-1.5 px-4 mb-2 focus:bg-gray-200 focus:outline-none"
34+
className="appearance-none block w-full dark:text-gray-800 bg-gray-100 border border-red rounded py-1.5 px-4 mb-2 focus:bg-gray-200 focus:outline-none text-sm"
3535
id={input.name}
3636
placeholder={placeholder}
3737
required={required}

src/routes/LoginWithToken.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe('routes/LoginWithToken.tsx', () => {
7272
expect(validate(values).token).toBe('Invalid token.');
7373
});
7474

75-
it("should click on the 'personal access tokens' link and open the browser", async () => {
75+
it("should click on the 'Generate a PAT' link and open the browser", async () => {
7676
render(
7777
<AppContext.Provider value={{ validateToken: mockValidateToken }}>
7878
<MemoryRouter>
@@ -81,7 +81,7 @@ describe('routes/LoginWithToken.tsx', () => {
8181
</AppContext.Provider>,
8282
);
8383

84-
fireEvent.click(screen.getByText('personal access tokens'));
84+
fireEvent.click(screen.getByText('Generate a PAT'));
8585

8686
expect(openExternalMock).toHaveBeenCalledTimes(1);
8787
});

src/routes/LoginWithToken.tsx

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import type { AuthTokenOptions } from '../types';
1010
import { openExternalLink } from '../utils/comms';
1111
import { Constants } from '../utils/constants';
1212

13+
import { format } from 'date-fns';
14+
1315
interface IValues {
1416
token?: string;
1517
hostname?: string;
@@ -53,40 +55,46 @@ export const LoginWithToken: FC = () => {
5355
const renderForm = (formProps: FormRenderProps) => {
5456
const { handleSubmit, submitting, pristine, values } = formProps;
5557

58+
const buttonClasses =
59+
'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';
60+
5661
return (
5762
<form onSubmit={handleSubmit}>
5863
<FieldInput
5964
name="token"
6065
label="Token"
6166
placeholder="The 40 characters token generated on GitHub"
6267
helpText={
63-
<>
64-
To generate a token, go to GitHub,{' '}
65-
<button
66-
type="button"
67-
className="underline hover:text-gray-500 dark:hover:text-gray-300 cursor-pointer"
68-
onClick={() =>
69-
openLink(
70-
'https://github.com/settings/tokens/new?scopes=notifications,read:user,repo&description=gitify_token',
71-
)
72-
}
73-
>
74-
personal access tokens
75-
</button>{' '}
76-
and create one with the {Constants.AUTH_SCOPE.length} scopes{' '}
77-
<span className="underline font-extrabold text-yellow-500">
78-
{Constants.AUTH_SCOPE.join(', ')}{' '}
79-
</span>
80-
.
81-
</>
68+
<div>
69+
<div>
70+
Create a Personal Access Token on GitHub and paste above.
71+
</div>
72+
<div>
73+
The required scopes will be selected for you.{' '}
74+
<button
75+
type="button"
76+
className={`px-2 py-1 my-2 text-xs ${buttonClasses}`}
77+
onClick={() => openLink(getNewTokenURL())}
78+
>
79+
Generate a PAT
80+
</button>
81+
</div>
82+
</div>
8283
}
8384
/>
8485

8586
<FieldInput
8687
name="hostname"
8788
label="Hostname"
8889
placeholder="github.202132.xyzpany.com"
89-
helpText="Defaults to github.com. Change only if you are using GitHub for Enterprise."
90+
helpText={
91+
<div>
92+
<div>Defaults to github.com.</div>
93+
<div className="italic">
94+
Change only if you are using GitHub Enterprise Server.
95+
</div>
96+
</div>
97+
}
9098
/>
9199

92100
{!isValidToken && (
@@ -96,7 +104,7 @@ export const LoginWithToken: FC = () => {
96104
)}
97105

98106
<button
99-
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"
107+
className={`float-right px-4 py-2 my-4 ${buttonClasses}`}
100108
title="Submit Button"
101109
disabled={submitting || pristine}
102110
type="submit"
@@ -134,7 +142,7 @@ export const LoginWithToken: FC = () => {
134142
</button>
135143

136144
<h3 className="text-lg font-semibold">
137-
Login with personal access token
145+
Login with Personal Access Token
138146
</h3>
139147
</div>
140148

@@ -153,3 +161,12 @@ export const LoginWithToken: FC = () => {
153161
</div>
154162
);
155163
};
164+
165+
function getNewTokenURL(): string {
166+
const date = format(new Date(), 'PP p');
167+
const newTokenURL = new URL('https://github.com/settings/tokens/new');
168+
newTokenURL.searchParams.append('description', `Gitify (Created on ${date})`);
169+
newTokenURL.searchParams.append('scopes', Constants.AUTH_SCOPE.join(','));
170+
171+
return newTokenURL.toString();
172+
}

src/routes/__snapshots__/LoginEnterprise.test.tsx.snap

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/routes/__snapshots__/LoginWithToken.test.tsx.snap

Lines changed: 30 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)