From 6d7b6cc8b9a7df7e5ac2d3e152f6605ad09250c3 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Thu, 11 Apr 2024 15:58:25 +0000 Subject: [PATCH] refactor: improve PAT login experience (#999) --- src/components/fields/FieldInput.tsx | 2 +- src/routes/LoginWithToken.test.tsx | 4 +- src/routes/LoginWithToken.tsx | 61 ++++++++++++------- .../LoginEnterprise.test.tsx.snap | 6 +- .../LoginWithToken.test.tsx.snap | 56 +++++++++-------- 5 files changed, 75 insertions(+), 54 deletions(-) diff --git a/src/components/fields/FieldInput.tsx b/src/components/fields/FieldInput.tsx index 930932784..669c07630 100644 --- a/src/components/fields/FieldInput.tsx +++ b/src/components/fields/FieldInput.tsx @@ -31,7 +31,7 @@ export const FieldInput: FC = ({ { expect(validate(values).token).toBe('Invalid token.'); }); - it("should click on the 'personal access tokens' link and open the browser", async () => { + it("should click on the 'Generate a PAT' link and open the browser", async () => { render( @@ -81,7 +81,7 @@ describe('routes/LoginWithToken.tsx', () => { , ); - fireEvent.click(screen.getByText('personal access tokens')); + fireEvent.click(screen.getByText('Generate a PAT')); expect(openExternalMock).toHaveBeenCalledTimes(1); }); diff --git a/src/routes/LoginWithToken.tsx b/src/routes/LoginWithToken.tsx index fa533303d..2f05eaded 100644 --- a/src/routes/LoginWithToken.tsx +++ b/src/routes/LoginWithToken.tsx @@ -10,6 +10,8 @@ import type { AuthTokenOptions } from '../types'; import { openExternalLink } from '../utils/comms'; import { Constants } from '../utils/constants'; +import { format } from 'date-fns'; + interface IValues { token?: string; hostname?: string; @@ -53,6 +55,9 @@ export const LoginWithToken: FC = () => { const renderForm = (formProps: FormRenderProps) => { const { handleSubmit, submitting, pristine, values } = 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 (
{ label="Token" placeholder="The 40 characters token generated on GitHub" helpText={ - <> - To generate a token, go to GitHub,{' '} - {' '} - and create one with the {Constants.AUTH_SCOPE.length} scopes{' '} - - {Constants.AUTH_SCOPE.join(', ')}{' '} - - . - +
+
+ Create a Personal Access Token on GitHub and paste above. +
+
+ The required scopes will be selected for you.{' '} + +
+
} /> @@ -86,7 +87,14 @@ export const LoginWithToken: FC = () => { name="hostname" label="Hostname" placeholder="github.company.com" - helpText="Defaults to github.com. Change only if you are using GitHub for Enterprise." + helpText={ +
+
Defaults to github.com.
+
+ Change only if you are using GitHub Enterprise Server. +
+
+ } /> {!isValidToken && ( @@ -96,7 +104,7 @@ export const LoginWithToken: FC = () => { )}

- Login with personal access token + Login with Personal Access Token

@@ -153,3 +161,12 @@ export const LoginWithToken: FC = () => { ); }; + +function getNewTokenURL(): string { + const date = format(new Date(), 'PP p'); + const newTokenURL = new URL('https://github.com/settings/tokens/new'); + newTokenURL.searchParams.append('description', `Gitify (Created on ${date})`); + newTokenURL.searchParams.append('scopes', Constants.AUTH_SCOPE.join(',')); + + return newTokenURL.toString(); +} diff --git a/src/routes/__snapshots__/LoginEnterprise.test.tsx.snap b/src/routes/__snapshots__/LoginEnterprise.test.tsx.snap index c913860c7..109d0a93e 100644 --- a/src/routes/__snapshots__/LoginEnterprise.test.tsx.snap +++ b/src/routes/__snapshots__/LoginEnterprise.test.tsx.snap @@ -58,7 +58,7 @@ exports[`routes/LoginEnterprise.tsx renders correctly 1`] = ` Hostname - Login with personal access token + Login with Personal Access Token
- To generate a token, go to GitHub, - - - - and create one with the - 3 - scopes - - - read:user, notifications, repo - - - . +
+
+ Create a Personal Access Token on GitHub and paste above. +
+
+ The required scopes will be selected for you. + + +
+
- Defaults to github.com. Change only if you are using GitHub for Enterprise. +
+
+ Defaults to github.com. +
+
+ Change only if you are using GitHub Enterprise Server. +
+