Skip to content

Commit

Permalink
Merge branch 'develop' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
clothe09986 committed Oct 19, 2023
2 parents 6083d41 + c45f5e4 commit 786656f
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 27 deletions.
8 changes: 4 additions & 4 deletions src/components/package/ProgramPackageCollectionBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
import dayjs from 'dayjs'
import { CommonTitleMixin, MultiLineTruncationMixin } from 'lodestar-app-element/src/components/common'
import { useApp } from 'lodestar-app-element/src/contexts/AppContext'
import { useAuth } from 'lodestar-app-element/src/contexts/AuthContext'
import React, { Fragment, useState } from 'react'
import { BiSearch, BiSort } from 'react-icons/bi'
import { FiGrid, FiList } from 'react-icons/fi'
Expand Down Expand Up @@ -137,6 +136,7 @@ const sortOptions = [
]

const ProgramPackageCollectionBlock: React.VFC<{
memberId: string
onProgramTabClick: (tab: string) => void
programTab: string
programPackageEnrollment: ProgramPackageEnrollment[]
Expand All @@ -146,6 +146,7 @@ const ProgramPackageCollectionBlock: React.VFC<{
loading: boolean
isError: boolean
}> = ({
memberId,
programTab,
onProgramTabClick,
programPackageEnrollment,
Expand All @@ -155,7 +156,6 @@ const ProgramPackageCollectionBlock: React.VFC<{
loading,
isError,
}) => {
const { currentMemberId } = useAuth()
const { formatMessage } = useIntl()
const { settings } = useApp()
const [isExpired, setIsExpired] = useState(false)
Expand Down Expand Up @@ -368,7 +368,7 @@ const ProgramPackageCollectionBlock: React.VFC<{
to={
isExpired
? `/program-packages/${programPackage.id}`
: `/program-packages/${programPackage.id}/contents?memberId=${currentMemberId}`
: `/program-packages/${programPackage.id}/contents?memberId=${memberId}`
}
>
<StyledCard>
Expand Down Expand Up @@ -399,7 +399,7 @@ const ProgramPackageCollectionBlock: React.VFC<{
to={
isExpired
? `/program-packages/${programPackage.id}`
: `/program-packages/${programPackage.id}/contents?memberId=${currentMemberId}`
: `/program-packages/${programPackage.id}/contents?memberId=${memberId}`
}
>
<StyledCard>
Expand Down
3 changes: 1 addition & 2 deletions src/containers/podcast/PodcastProgramTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ export type PodcastProgramProps = PodcastProgramPopoverProps &
supportLocales?: string[] | null
}
const PodcastProgramTimeline: React.VFC<{
memberId: string | null
podcastPrograms: PodcastProgramProps[]
renderItem?: (item: {
podcastProgram: PodcastProgramProps
isEnrolled: boolean
isSubscribed: boolean
}) => React.ReactElement
}> = ({ memberId, podcastPrograms, renderItem }) => {
}> = ({ podcastPrograms, renderItem }) => {
const { data: podcastEnrollment } = useProductEnrollment('podcast')
const { data: podcastPlanEnrollment } = useProductEnrollment('podcast-plan')

Expand Down
8 changes: 4 additions & 4 deletions src/containers/program/EnrolledProgramCollectionBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
useRadioGroup,
} from '@chakra-ui/react'
import { useApp } from 'lodestar-app-element/src/contexts/AppContext'
import { useAuth } from 'lodestar-app-element/src/contexts/AuthContext'
import React, { Fragment, useState } from 'react'
import { BiSearch, BiSort } from 'react-icons/bi'
import { FiGrid, FiList } from 'react-icons/fi'
Expand Down Expand Up @@ -102,6 +101,7 @@ const filterOptions = [
]

const EnrolledProgramCollectionBlock: React.VFC<{
memberId: string
onProgramTabClick: (tab: string) => void
programTab: string
programEnrollment: ProgramEnrollment[]
Expand All @@ -111,6 +111,7 @@ const EnrolledProgramCollectionBlock: React.VFC<{
isError: boolean
loading: boolean
}> = ({
memberId,
onProgramTabClick,
programTab,
programEnrollment,
Expand All @@ -120,7 +121,6 @@ const EnrolledProgramCollectionBlock: React.VFC<{
isError,
loading,
}) => {
const { currentMemberId } = useAuth()
const { formatMessage } = useIntl()
const [isExpired, setIsExpired] = useState(false)
const localStorageView = localStorage.getItem('programView')
Expand Down Expand Up @@ -434,7 +434,7 @@ const EnrolledProgramCollectionBlock: React.VFC<{
viewRate={program.viewRate}
withProgress={!isExpired}
isExpired={isExpired}
previousPage={`members_${currentMemberId}`}
previousPage={`members_${memberId}`}
/>
</Box>
)}
Expand All @@ -454,7 +454,7 @@ const EnrolledProgramCollectionBlock: React.VFC<{
viewRate={program.viewRate}
withProgress={!isExpired}
isExpired={isExpired}
previousPage={`members_${currentMemberId}`}
previousPage={`members_${memberId}`}
/>
</Box>
)}
Expand Down
15 changes: 11 additions & 4 deletions src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,12 +493,19 @@ const getLodestarRoute = (product: MemberPageProductType) => {
}
}

export const getProductEnrollmentFromLodestar = async (product: MemberPageProductType, authToken: string) => {
export const getProductEnrollmentFromLodestar = async (
product: MemberPageProductType,
authToken: string,
memberId?: string,
) => {
const route = getLodestarRoute(product)
if (route) {
const { data } = await axios.get(`${process.env.REACT_APP_LODESTAR_SERVER_ENDPOINT}${route}`, {
headers: { authorization: `Bearer ${authToken}` },
})
const { data } = await axios.get(
`${process.env.REACT_APP_LODESTAR_SERVER_ENDPOINT}${route}${memberId ? `/?memberId=${memberId}` : ''}`,
{
headers: { authorization: `Bearer ${authToken}` },
},
)

return data
}
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ export const useMemberPageEnrollmentsCounts = (memberId: string) => {
}
}

export const useProductEnrollment = <T extends MemberPageProductType>(product: T) => {
export const useProductEnrollment = <T extends MemberPageProductType>(product: T, memberId?: string) => {
const { authToken } = useAuth()
const [loading, setLoading] = useState(false)
const [error, setError] = useState<any>()
Expand All @@ -769,7 +769,7 @@ export const useProductEnrollment = <T extends MemberPageProductType>(product: T
if (authToken) {
try {
setLoading(true)
const programEnrollmentData = await getProductEnrollmentFromLodestar(product, authToken)
const programEnrollmentData = await getProductEnrollmentFromLodestar(product, authToken, memberId)
setData(programEnrollmentData)
} catch (err) {
console.log(err)
Expand Down
3 changes: 1 addition & 2 deletions src/pages/CreatorPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ const CreatorTabs: React.VFC<{
})

const { posts } = usePostPreviewCollection({ authorId: creatorId })
const { data: podcastPlanEnrollment } = useProductEnrollment('podcast-plan')
const { data: podcastPlanEnrollment } = useProductEnrollment('podcast-plan', currentMemberId || undefined)

const { podcastPrograms } = usePodcastProgramCollection(creatorId)
const { appointmentPlans } = useAppointmentPlanCollection(
Expand Down Expand Up @@ -329,7 +329,6 @@ const CreatorTabs: React.VFC<{
<div className="row">
<div className="col-12 col-lg-8 mb-3">
<PodcastProgramTimeline
memberId={currentMemberId}
podcastPrograms={podcastPrograms}
renderItem={({ podcastProgram, isEnrolled, isSubscribed }) => {
const elem = (
Expand Down
5 changes: 2 additions & 3 deletions src/pages/MemberPage/PodcastProgramCollectionBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ const PodcastProgramCollectionBlock: React.VFC<{
const { formatMessage } = useIntl()
const history = useHistory()
const { setup } = useContext(PodcastPlayerContext)
const { data: podcastPlanEnrollment } = useProductEnrollment('podcast-plan')
const { data: podcastPlanEnrollment } = useProductEnrollment('podcast-plan', memberId)

const { playlists, totalPodcastProgramCount, refetchPlaylists } = usePlaylistCollection(memberId)
const { playlists, totalPodcastProgramCount, refetchPlaylists } = usePlaylistCollection(memberId || '')
const updatePlaylist = useUpdatePlaylist()
const deletePlaylist = useDeletePlaylist()

Expand All @@ -59,7 +59,6 @@ const PodcastProgramCollectionBlock: React.VFC<{
<StyledTitle>{formatMessage(productMessages.podcast.title.podcast)}</StyledTitle>

<PodcastProgramTimeline
memberId={memberId}
podcastPrograms={podcastEnrollment}
renderItem={({ podcastProgram, isEnrolled }) => (
<Link to={`/podcasts/${podcastProgram.id}`} key={podcastProgram.id}>
Expand Down
13 changes: 8 additions & 5 deletions src/pages/MemberPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,33 +72,34 @@ const MemberPage: React.VFC<{ renderText?: (member: MemberPublicProps) => React.
} = useMemberPageEnrollmentsCounts(memberId)
const [activeKey, setActiveKey] = useQueryParam('tabkey', StringParam)
const [programTab, setProgramTab] = useState('program')

const {
fetch: fetchProgramEnrollment,
data: programEnrollment,
error: programEnrollmentError,
loading: programEnrollmentLoading,
} = useProductEnrollment('program')
} = useProductEnrollment('program', memberId)
const {
fetch: fetchExpiredProgramEnrollment,
data: expiredProgramEnrollment,
error: expiredProgramEnrollmentError,
loading: expiredProgramEnrollmentLoading,
} = useProductEnrollment('expiredProgram')
} = useProductEnrollment('expiredProgram', memberId)
const {
data: programPackageEnrollment,
loading: programPackageEnrollmentLoading,
error: programPackageEnrollmentError,
} = useProductEnrollment('programPackage')
} = useProductEnrollment('programPackage', memberId)
const {
data: expiredProgramPackageEnrollment,
loading: expiredProgramPackageEnrollmentLoading,
error: expiredProgramPackageEnrollmentError,
} = useProductEnrollment('expiredProgramPackage')
} = useProductEnrollment('expiredProgramPackage', memberId)
const {
data: podcastEnrollment,
loading: podcastEnrollmentLoading,
error: podcastEnrollmentError,
} = useProductEnrollment('podcast')
} = useProductEnrollment('podcast', memberId)
const programCounts = programEnrollment.length + expiredProgramEnrollment.length
const programPackageCounts = programPackageEnrollment.length + expiredProgramPackageEnrollment.length
let content = null
Expand All @@ -124,6 +125,7 @@ const MemberPage: React.VFC<{ renderText?: (member: MemberPublicProps) => React.
<>
{programTab === 'program' && (
<EnrolledProgramCollectionBlock
memberId={memberId}
onProgramTabClick={tab => setProgramTab(tab)}
programTab={programTab}
programEnrollment={programEnrollment}
Expand All @@ -136,6 +138,7 @@ const MemberPage: React.VFC<{ renderText?: (member: MemberPublicProps) => React.
)}
{programTab === 'programPackage' && (
<ProgramPackageCollectionBlock
memberId={memberId}
onProgramTabClick={tab => setProgramTab(tab)}
programTab={programTab}
programPackageEnrollment={programPackageEnrollment}
Expand Down
1 change: 0 additions & 1 deletion src/pages/PodcastProgramCollectionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ const PodcastProgramCollectionPage: React.VFC = () => {
<div className="row">
<div className="col-12 col-lg-8 mb-5">
<PodcastProgramTimeline
memberId={currentMemberId}
podcastPrograms={podcastPrograms
.filter(
podcastProgram =>
Expand Down

0 comments on commit 786656f

Please sign in to comment.