-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discord Id Check #69
Open
ntxnick
wants to merge
27
commits into
AmericanAirlines:main
Choose a base branch
from
ntxnick:discordButton
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+135
−16
Open
Discord Id Check #69
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
1dba8de
initial commit
ntxnick a31d654
minor changes
ntxnick 66e83c5
updating
ntxnick 404971b
working! just needs tests
ntxnick 445b257
new api created, test for it made, routes updated
ntxnick 59ab54b
working with tests!
ntxnick f18921a
lint/prettier run
ntxnick cf8f5f7
clean up
ntxnick c786513
updated me api, updated format
ntxnick 6a74dd3
fixed and working!
ntxnick 1679da0
complete
ntxnick 20bf075
updated
ntxnick 78fd692
updated buttonCheck.tsx
ntxnick 87b7c8f
working tests again
ntxnick f21d4c6
updated with changes
ntxnick 7f5ec04
updated test
ntxnick c498e01
updated from main
ntxnick 87b350a
ran prettier
ntxnick 996430d
Merge branch 'main' into discordButton
SpencerKaiser 178a061
changes made
ntxnick 6309bf6
Merge branch 'main' of https://github.com/AmericanAirlines/Project-X …
ntxnick e6ec393
Merge branch 'discordButton' of https://github.com/ntxnick/Project-X …
ntxnick a21235d
cleaned up unused import
ntxnick 93c652a
updated button style
ntxnick 489d123
adding undefined
ntxnick 419ddcd
updated button and exported user from userprofile
ntxnick e0200f3
file name changes
ntxnick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
packages/web/src/components/DiscordButton/DiscordButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React from 'react'; | ||
import { Button, Box, Alert, AlertIcon } from '@chakra-ui/react'; | ||
import { FaDiscord } from 'react-icons/fa'; | ||
import { User } from '../userprofile/UserProfile'; | ||
|
||
export const DiscordButton: React.FC = () => { | ||
const [user, setUser] = React.useState<User | undefined>(); | ||
const [errorMessage, setErrorMessage] = React.useState<string>(''); | ||
|
||
React.useEffect(() => { | ||
const fetchUser = async () => { | ||
try { | ||
const res = await fetch(`/api/users/me`); | ||
const data = await res.json(); | ||
|
||
setUser(data); | ||
} catch { | ||
setErrorMessage('User could not be found'); | ||
} | ||
}; | ||
|
||
fetchUser(); | ||
}, []); | ||
|
||
if (!user) { | ||
if (errorMessage == '') return null; | ||
else | ||
return ( | ||
<Alert status="error"> | ||
<AlertIcon /> | ||
{errorMessage} | ||
</Alert> | ||
); | ||
} else { | ||
return ( | ||
<Box> | ||
{user.discordId ? ( | ||
<Button | ||
as="a" | ||
href="https://discord.com/" | ||
bg="discord.400" | ||
textColor="white" | ||
leftIcon={<FaDiscord color="white" />} | ||
> | ||
Go to Discord | ||
</Button> | ||
) : ( | ||
<Button | ||
as="a" | ||
href="/api/auth/discord/login" | ||
bg="discord.400" | ||
textColor="white" | ||
leftIcon={<FaDiscord color="white" />} | ||
> | ||
Join our Discord | ||
</Button> | ||
)} | ||
</Box> | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './DiscordButton'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
packages/web/tests/components/DiscordButton/DiscordButton.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React from 'react'; | ||
import fetchMock from 'fetch-mock-jest'; | ||
import { DiscordButton } from '../../../src/components/DiscordButton'; | ||
import { render, screen, waitFor } from '../../testUtils/testTools'; | ||
import { User } from '../../../src/components/userprofile/UserProfile'; | ||
|
||
const sampleUser: Partial<User> = { | ||
name: 'James', | ||
discordId: undefined, | ||
}; | ||
|
||
const sampleUser2: User = { | ||
name: 'James', | ||
discordId: '34523452345', | ||
}; | ||
|
||
describe('DiscordButton component', () => { | ||
beforeEach(async () => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('shows an error message when the user is not found', async () => { | ||
fetchMock.get('/api/users/me', 500); | ||
|
||
render(<DiscordButton />); | ||
|
||
await waitFor(() => { | ||
expect(fetchMock).toHaveFetched('/api/users/me'); | ||
expect(screen.getByText('User could not be found')).toBeVisible(); | ||
}); | ||
}); | ||
|
||
it('renders the Join Discord button when user has no discord id', async () => { | ||
fetchMock.get('/api/users/me', sampleUser); | ||
|
||
render(<DiscordButton />); | ||
|
||
await waitFor(() => { | ||
const JoinDiscord = screen.queryByText('Join our Discord'); | ||
expect(fetchMock).toHaveFetched('/api/users/me'); | ||
|
||
expect(JoinDiscord).toBeVisible(); | ||
expect(JoinDiscord).toHaveAttribute('href', '/api/auth/discord/login'); | ||
}); | ||
}); | ||
|
||
it('renders Go to Discord button when user has a discordId', async () => { | ||
fetchMock.get('/api/users/me', sampleUser2); | ||
|
||
render(<DiscordButton />); | ||
|
||
await waitFor(() => { | ||
const GoToDiscord = screen.queryByText('Go to Discord'); | ||
expect(fetchMock).toHaveFetched('/api/users/me'); | ||
|
||
expect(GoToDiscord).toBeVisible(); | ||
expect(GoToDiscord).toHaveAttribute('href', 'https://discord.com/'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this change made?
null
doesn't match the type above (string
in conjunction with?
becomesstring | undefined
which is not the same asstring | null
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was made because I don't think the database knows what undefined was. Unless we change it to null the discord ID is not actually removed from the profile. it just selects the profile but doesn't actually remove the Discord ID.