Skip to content

Commit 9da124b

Browse files
Feature Flag for MITxOnline API Call (#2305)
* feature flag current user call * load non-org tabs asap * get profile from user directly
1 parent 3844d19 commit 9da124b

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

frontends/api/src/mitxonline/hooks/user/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useQuery } from "@tanstack/react-query"
22
import { usersApi } from "../../clients"
33
import type { User } from "@mitodl/mitxonline-api-axios/v1"
44

5-
const useMitxOnlineCurrentUser = () =>
5+
const useMitxOnlineCurrentUser = (opts: { enabled?: boolean } = {}) =>
66
useQuery({
77
queryKey: ["mitxonline", "currentUser"],
88
queryFn: async (): Promise<User> => {
@@ -11,6 +11,7 @@ const useMitxOnlineCurrentUser = () =>
1111
...response.data,
1212
}
1313
},
14+
...opts,
1415
})
1516

1617
export { useMitxOnlineCurrentUser }

frontends/main/src/app-pages/DashboardPage/DashboardLayout.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,15 @@ const DashboardPage: React.FC<{
308308
}> = ({ children }) => {
309309
const pathname = usePathname()
310310
const { isLoading: isLoadingUser, data: user } = useUserMe()
311-
const { isLoading: isLoadingMitxOnlineUser, data: mitxOnlineUser } =
312-
useMitxOnlineCurrentUser()
313311
const orgsEnabled = useFeatureFlagEnabled(FeatureFlags.OrganizationDashboard)
312+
const { isLoading: isLoadingMitxOnlineUser, data: mitxOnlineUser } =
313+
useMitxOnlineCurrentUser({ enabled: !!orgsEnabled })
314314

315315
const tabData = useMemo(
316316
() =>
317-
isLoadingMitxOnlineUser ? [] : getTabData(orgsEnabled, mitxOnlineUser),
317+
isLoadingMitxOnlineUser
318+
? getTabData(orgsEnabled)
319+
: getTabData(orgsEnabled, mitxOnlineUser),
318320
[isLoadingMitxOnlineUser, orgsEnabled, mitxOnlineUser],
319321
)
320322

frontends/main/src/app-pages/DashboardPage/HomeContent.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import {
1313
FREE_COURSES_CAROUSEL,
1414
} from "@/common/carousels"
1515
import ResourceCarousel from "@/page-components/ResourceCarousel/ResourceCarousel"
16-
import { useProfileMeQuery } from "api/hooks/profile"
1716
import { EnrollmentDisplay } from "./CoursewareDisplay/EnrollmentDisplay"
1817
import { useFeatureFlagEnabled } from "posthog-js/react"
1918
import { FeatureFlags } from "@/common/feature_flags"
19+
import { useUserMe } from "api/hooks/user"
2020

2121
const SubTitleText = styled(Typography)(({ theme }) => ({
2222
color: theme.custom.colors.darkGray2,
@@ -66,9 +66,9 @@ const TitleText = styled(Typography)(({ theme }) => ({
6666
})) as typeof Typography
6767

6868
const HomeContent: React.FC = () => {
69-
const { isLoading: isLoadingProfile, data: profile } = useProfileMeQuery()
70-
const topics = profile?.preference_search_filters.topic
71-
const certification = profile?.preference_search_filters.certification
69+
const { isLoading: isLoadingProfile, data: user } = useUserMe()
70+
const topics = user?.profile?.preference_search_filters.topic
71+
const certification = user?.profile?.preference_search_filters.certification
7272
const showEnrollments = useFeatureFlagEnabled(
7373
FeatureFlags.EnrollmentDashboard,
7474
)
@@ -93,7 +93,7 @@ const HomeContent: React.FC = () => {
9393
titleComponent="h2"
9494
title="Top picks for you"
9595
isLoading={isLoadingProfile}
96-
config={TopPicksCarouselConfig(profile)}
96+
config={TopPicksCarouselConfig(user?.profile)}
9797
/>
9898
{topics?.map((topic, index) => (
9999
<StyledResourceCarousel

0 commit comments

Comments
 (0)