-
Couldn't load subscription status.
- Fork 3
Subscription management page #1331
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
Merged
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
d94c3a8
adding initial method to return original url query params
shanbady 104560a
adding subscription management page
shanbady 7f263a9
switching name to preferences page
shanbady 72cb080
adding preferences to dashboard page
shanbady ba4ab69
changing icon
shanbady 9c93f0e
adding source types and labels and regenerating api to match
shanbady a21fd38
changing response for saved search
shanbady 5542dfa
updating frontend to match mocks
shanbady c22f07f
style changes
shanbady 6ea8846
fixing typechecks
shanbady cae76c9
removing log
shanbady 0a3e82f
fixing typecheck
shanbady 70a41bb
fixing tests
shanbady 03ba1c4
styling fix for mobile and preventing nav
shanbady f922d49
removing bad prop
shanbady a9caa58
switching to settings page instead of preferences page
shanbady cf7de0b
adding tests for percolate match labels
shanbady f4be241
adding tests for percolate match labels
shanbady 0b928b8
Update learning_resources_search/models.py
shanbady f2e04af
Update frontends/mit-open/src/pages/DashboardPage/SettingsPage.tsx
shanbady 28e5879
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 05fcb28
updating font size
shanbady 578fa1d
snake casing 'saved search'
shanbady aa045f1
switching to plainlist
shanbady bee5e8c
style fixes
shanbady 5a66e85
using custom listitem element
shanbady 1012018
removing divider param
shanbady eba3e8b
dropping support for comma-delim'd array params
shanbady 23e35a8
removing broken style
shanbady 2108735
fixing heading padding
shanbady b48ea13
remove defunct test
shanbady ed7ca31
Update frontends/mit-open/src/pages/DashboardPage/SettingsPage.tsx
shanbady 2e57307
Update frontends/mit-open/src/pages/DashboardPage/SettingsPage.tsx
shanbady 8860049
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 59a393b
simplify check for null profile
shanbady 2992f84
adding frontend tests
shanbady 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
66 changes: 66 additions & 0 deletions
66
frontends/mit-open/src/pages/DashboardPage/SettingsPage.test.tsx
This file contains hidden or 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,66 @@ | ||
| import React from "react" | ||
| import { SettingsPage } from "./SettingsPage" | ||
| import { renderWithProviders, screen, within, user } from "@/test-utils" | ||
| import { urls, setMockResponse, factories, makeRequest } from "api/test-utils" | ||
| import type { LearningResourcesUserSubscriptionApiLearningResourcesUserSubscriptionCheckListRequest as CheckSubscriptionRequest } from "api" | ||
|
|
||
| type SetupApisOptions = { | ||
| isAuthenticated?: boolean | ||
| isSubscribed?: boolean | ||
| subscriptionRequest?: CheckSubscriptionRequest | ||
| } | ||
| const setupApis = ({ | ||
| isAuthenticated = false, | ||
| isSubscribed = false, | ||
| subscriptionRequest = {}, | ||
| }: SetupApisOptions = {}) => { | ||
| setMockResponse.get(urls.userMe.get(), { | ||
| is_authenticated: isAuthenticated, | ||
| }) | ||
|
|
||
| const subscribeResponse = isSubscribed | ||
| ? factories.percolateQueries.percolateQueryList({ count: 5 }).results | ||
| : factories.percolateQueries.percolateQueryList({ count: 0 }).results | ||
| setMockResponse.get( | ||
| `${urls.userSubscription.check(subscriptionRequest)}`, | ||
| subscribeResponse, | ||
| ) | ||
| const unsubscribeUrl = urls.userSubscription.delete(subscribeResponse[0]?.id) | ||
| setMockResponse.delete(unsubscribeUrl, subscribeResponse[0]) | ||
| return { | ||
| unsubscribeUrl, | ||
| } | ||
| } | ||
|
|
||
| describe("SettingsPage", () => { | ||
| it("Renders user subscriptions in a list", async () => { | ||
| setupApis({ | ||
| isAuthenticated: true, | ||
| isSubscribed: true, | ||
| subscriptionRequest: {}, | ||
| }) | ||
| renderWithProviders(<SettingsPage />) | ||
|
|
||
| const followList = await screen.findByTestId("follow-list") | ||
| expect(followList.children.length).toBe(5) | ||
| }) | ||
|
|
||
| test("Clicking 'Unfollow' removes the subscription", async () => { | ||
| const { unsubscribeUrl } = setupApis({ | ||
| isAuthenticated: true, | ||
| isSubscribed: true, | ||
| subscriptionRequest: {}, | ||
| }) | ||
| renderWithProviders(<SettingsPage />) | ||
|
|
||
| const followList = await screen.findByTestId("follow-list") | ||
| const unsubscribeButton = within(followList).getAllByText("Unfollow")[0] | ||
| await user.click(unsubscribeButton) | ||
|
|
||
| expect(makeRequest).toHaveBeenCalledWith( | ||
| "delete", | ||
| unsubscribeUrl, | ||
| undefined, | ||
| ) | ||
| }) | ||
| }) | ||
128 changes: 128 additions & 0 deletions
128
frontends/mit-open/src/pages/DashboardPage/SettingsPage.tsx
This file contains hidden or 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,128 @@ | ||
| import React from "react" | ||
| import { PlainList, Typography, Link, styled } from "ol-components" | ||
| import { useUserMe } from "api/hooks/user" | ||
| import { | ||
| useSearchSubscriptionDelete, | ||
| useSearchSubscriptionList, | ||
| } from "api/hooks/searchSubscription" | ||
|
|
||
| const SOURCE_LABEL_DISPLAY = { | ||
| topic: "Topic", | ||
| unit: "MIT Unit", | ||
| department: "MIT Academic Department", | ||
| saved_search: "Saved Search", | ||
| } | ||
|
|
||
| const FollowList = styled(PlainList)(({ theme }) => ({ | ||
| borderRadius: "8px", | ||
| background: theme.custom.colors.white, | ||
| border: `1px solid ${theme.custom.colors.lightGray2}`, | ||
| })) | ||
|
|
||
| const StyledLink = styled(Link)(({ theme }) => ({ | ||
| color: theme.custom.colors.red, | ||
| })) | ||
|
|
||
| const TitleText = styled(Typography)(({ theme }) => ({ | ||
| marginTop: "16px", | ||
| marginBottom: "8px", | ||
|
|
||
| color: theme.custom.colors.darkGray2, | ||
| ...theme.typography.h5, | ||
| })) | ||
|
|
||
| const SubTitleText = styled(Typography)(({ theme }) => ({ | ||
| marginBottom: "16px", | ||
| color: theme.custom.colors.darkGray2, | ||
| ...theme.typography.body2, | ||
| })) | ||
|
|
||
| const ListItem = styled.li(({ theme }) => [ | ||
| { | ||
| padding: "16px 32px", | ||
| display: "flex", | ||
| gap: "16px", | ||
| alignItems: "center", | ||
| borderBottom: `1px solid ${theme.custom.colors.lightGray2}`, | ||
| ":last-child": { | ||
| borderBottom: "none", | ||
| }, | ||
| }, | ||
| ]) | ||
| const _ListItemBody = styled.div({ | ||
| display: "flex", | ||
| flexDirection: "column", | ||
| justifyContent: "center", | ||
| gap: "4px", | ||
| flex: "1 0 0", | ||
| }) | ||
| const Title = styled.span(({ theme }) => ({ | ||
| ...theme.typography.subtitle1, | ||
| color: theme.custom.colors.darkGray2, | ||
| })) | ||
| const Subtitle = styled.span(({ theme }) => ({ | ||
| ...theme.typography.body2, | ||
| color: theme.custom.colors.silverGrayDark, | ||
| })) | ||
| type ListItemBodyProps = { | ||
| children?: React.ReactNode | ||
| title?: string | ||
| subtitle?: string | ||
| } | ||
| const ListItemBody: React.FC<ListItemBodyProps> = ({ | ||
| children, | ||
| title, | ||
| subtitle, | ||
| }) => { | ||
| return ( | ||
| <_ListItemBody> | ||
| {children} | ||
| <Title>{title}</Title> | ||
| <Subtitle>{subtitle}</Subtitle> | ||
| </_ListItemBody> | ||
| ) | ||
| } | ||
|
|
||
| const SettingsPage: React.FC = () => { | ||
| const { data: user } = useUserMe() | ||
| const subscriptionDelete = useSearchSubscriptionDelete() | ||
| const subscriptionList = useSearchSubscriptionList({ | ||
| enabled: !!user?.is_authenticated, | ||
| }) | ||
|
|
||
| const unsubscribe = subscriptionDelete.mutate | ||
| if (!user || subscriptionList.isLoading) return null | ||
|
|
||
| return ( | ||
| <> | ||
| <TitleText>Following</TitleText> | ||
| <SubTitleText> | ||
| All topics, academic departments, and MIT units you are following. | ||
| </SubTitleText> | ||
| <FollowList data-testid="follow-list"> | ||
| {subscriptionList?.data?.map((subscriptionItem) => ( | ||
| <ListItem key={subscriptionItem.id}> | ||
| <ListItemBody | ||
| title={subscriptionItem.source_description} | ||
| subtitle={ | ||
| SOURCE_LABEL_DISPLAY[ | ||
| subscriptionItem.source_label as keyof typeof SOURCE_LABEL_DISPLAY | ||
| ] | ||
| } | ||
| /> | ||
| <StyledLink | ||
| onClick={(event) => { | ||
| event.preventDefault() | ||
| unsubscribe(subscriptionItem.id) | ||
| }} | ||
| > | ||
| Unfollow | ||
| </StyledLink> | ||
| </ListItem> | ||
| ))} | ||
| </FollowList> | ||
| </> | ||
| ) | ||
| } | ||
|
|
||
| export { SettingsPage } |
This file contains hidden or 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
Oops, something went wrong.
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.
I try to use
getByRole*for most things, since it effectively adds an assertion about the role in the accessibility treat. E.g., if we know it's an element with role link, it's almost certainly tab-navigable[^1][^1] I say "almost certainly" because it's probably an anchor tag. If someone did
<div role="link" />(don't!), that would show up as a link in the browser's accessibility treat, but wouldn't be tab navigable.