Skip to content

Commit cb6f83f

Browse files
authored
Merge branch 'master' into 2630-remove-flagged-exercises-in-accordance-with-design-doc-1
2 parents 53501b3 + a6589f1 commit cb6f83f

File tree

2 files changed

+54
-45
lines changed

2 files changed

+54
-45
lines changed

__tests__/pages/discord/success.test.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -133,32 +133,26 @@ describe('connect to Discord success page', () => {
133133
)
134134
})
135135

136-
it('should render discord error page when no userInfo is returned', async () => {
136+
it('should render discord account already used page', async () => {
137137
render(
138138
<ConnectToDiscordSuccess
139-
username="fakeUser"
140-
errorCode={ErrorCode.DISCORD_ERROR}
141-
error={{ message: 'errorMessage' }}
139+
errorCode={ErrorCode.DIFFERENT_ACCOUNT_IS_CONNECTED}
142140
/>
143141
)
144-
await waitFor(() => {
142+
await waitFor(() =>
145143
expect(
146-
screen.getByText(
147-
'Dear fakeUser, we had trouble connecting to Discord, please try again.',
148-
{
149-
exact: true
150-
}
151-
)
144+
screen.getByText('Discord account is already used', {
145+
exact: true
146+
})
152147
).toBeTruthy()
153-
expect(screen.getByText('{ "message": "errorMessage" }')).toBeTruthy()
154-
})
148+
)
155149
})
156150

157-
it('should render discord error page if another user is already connected to the Discord account', async () => {
151+
it('should render discord error page when no userInfo is returned', async () => {
158152
render(
159153
<ConnectToDiscordSuccess
160154
username="fakeUser"
161-
errorCode={ErrorCode.DIFFERENT_ACCOUNT_IS_CONNECTED}
155+
errorCode={ErrorCode.DISCORD_ERROR}
162156
error={{ message: 'errorMessage' }}
163157
/>
164158
)

pages/discord/success.tsx

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Image from 'next/image'
1010
import { DiscordUserInfo, getDiscordUserInfo } from '../../helpers/discordAuth'
1111
import { getSession } from 'next-auth/react'
1212
import { Session } from '../../@types/auth'
13+
import { CURRICULUM_PATH, LOGIN_PATH } from '../../constants'
1314

1415
type ConnectToDiscordSuccessProps = {
1516
errorCode: number
@@ -21,8 +22,7 @@ type ConnectToDiscordSuccessProps = {
2122
type DiscordErrorPageProps = {
2223
error: Error
2324
username: string
24-
navPath: string
25-
navText: string
25+
errorCode?: ErrorCode
2626
}
2727

2828
type Error = {
@@ -41,12 +41,22 @@ const DISCORD_BUGS_FEEDBACK_URL =
4141
const DiscordErrorPage: React.FC<DiscordErrorPageProps> = ({
4242
username,
4343
error,
44-
navPath,
45-
navText
44+
errorCode
4645
}) => {
47-
let errorMessage = <></>,
48-
errorLog = <></>
49-
if (!username) {
46+
const isDiscordError = errorCode === ErrorCode.DISCORD_ERROR
47+
const isUserNotLoggedIn = errorCode === ErrorCode.USER_NOT_LOGGED_IN
48+
const isDiscordAccountUsed =
49+
errorCode === ErrorCode.DIFFERENT_ACCOUNT_IS_CONNECTED
50+
51+
let errorMessage = <></>
52+
let errorLog = <></>
53+
let navText = isDiscordError ? 'Try Again' : 'Curriculum'
54+
let navPath = CURRICULUM_PATH
55+
56+
if (isUserNotLoggedIn) {
57+
navText = 'Log In Here'
58+
navPath = LOGIN_PATH
59+
5060
errorMessage = (
5161
<>
5262
<p>You need to be logged in to connect to Discord.</p>
@@ -66,6 +76,7 @@ const DiscordErrorPage: React.FC<DiscordErrorPageProps> = ({
6676
</>
6777
)
6878
}
79+
6980
if (error?.message) {
7081
errorLog = (
7182
<>
@@ -75,10 +86,33 @@ const DiscordErrorPage: React.FC<DiscordErrorPageProps> = ({
7586
</>
7687
)
7788
}
89+
90+
if (isDiscordAccountUsed) {
91+
errorMessage = (
92+
<>
93+
<p>
94+
Sorry, but it looks like the Discord account you are trying to link to
95+
your C0D3 account is already in use by another account.
96+
</p>
97+
<p>
98+
To fix this, you can either use a different Discord account or, if the
99+
account you are trying to link is already connected to a different
100+
C0D3 account, you can go to that account and unlink the Discord
101+
account. Then, come back to this account and try linking the Discord
102+
account again.
103+
</p>
104+
</>
105+
)
106+
}
107+
78108
return (
79109
<>
80110
<Title title="Error" />
81-
<Card title="Error">
111+
<Card
112+
title={
113+
isDiscordAccountUsed ? 'Discord account is already used' : 'Error'
114+
}
115+
>
82116
<div className="mt-3">{errorMessage}</div>
83117
<p>
84118
If this problem persists, please ask for help in our{' '}
@@ -102,36 +136,16 @@ const DiscordErrorPage: React.FC<DiscordErrorPageProps> = ({
102136

103137
export const ConnectToDiscordSuccess: React.FC<ConnectToDiscordSuccessProps> &
104138
WithLayout = ({ errorCode, username, userInfo, error }) => {
105-
if (errorCode === ErrorCode.DIFFERENT_ACCOUNT_IS_CONNECTED) {
139+
if (errorCode) {
106140
return (
107141
<DiscordErrorPage
108142
username={username}
109143
error={error}
110-
navPath="/curriculum"
111-
navText="Curriculum"
144+
errorCode={errorCode}
112145
/>
113146
)
114147
}
115148

116-
if (errorCode === ErrorCode.DISCORD_ERROR)
117-
return (
118-
<DiscordErrorPage
119-
username={username}
120-
error={error}
121-
navPath="/curriculum"
122-
navText="Try Again"
123-
/>
124-
)
125-
if (errorCode === ErrorCode.USER_NOT_LOGGED_IN)
126-
return (
127-
<DiscordErrorPage
128-
username=""
129-
error={error}
130-
navPath="/login"
131-
navText="Log In Here"
132-
/>
133-
)
134-
135149
return (
136150
<>
137151
<Title title="Success!" />
@@ -189,6 +203,7 @@ export const getServerSideProps = async ({
189203
id: sessionUser.id
190204
}
191205
})
206+
192207
if (!user) return { props: { errorCode: ErrorCode.USER_NOT_LOGGED_IN } }
193208

194209
const userInfo = await getDiscordUserInfo(user)

0 commit comments

Comments
 (0)