From 16b0c693f68b6ef10b45fa96b59b06a3647b0f55 Mon Sep 17 00:00:00 2001 From: Nicoll Date: Fri, 13 Dec 2024 14:40:40 -0600 Subject: [PATCH] feat: improve megabundle page --- .../templates/purchased-product-template.tsx | 170 +++++++++++++++--- .../skill-lesson/video/module-progress.tsx | 14 +- 2 files changed, 160 insertions(+), 24 deletions(-) diff --git a/apps/epic-web/src/templates/purchased-product-template.tsx b/apps/epic-web/src/templates/purchased-product-template.tsx index 7435c26c88..8e45376849 100644 --- a/apps/epic-web/src/templates/purchased-product-template.tsx +++ b/apps/epic-web/src/templates/purchased-product-template.tsx @@ -115,6 +115,129 @@ const PurchasedProductTemplate: React.FC = ({ product?.welcomeVideo?.poster || 'https://res.cloudinary.com/epic-web/image/upload/v1697358228/after-purchase-video-poster.jpg' + const EPIC_REACT_SLUGS = [ + 'react-fundamentals', + 'react-hooks', + 'advanced-react-apis', + 'react-suspense', + 'advanced-react-patterns', + 'react-performance', + 'react-server-components', + 'epic-react-v1-classic', + 'react-interviews-with-experts', + ] + + const TESTING_JS_SLUGS = ['testing-javascript-classic'] + + const groupModules = () => { + if (!product?.modules) return null + + return { + epicWeb: product.modules.filter( + (module) => + !EPIC_REACT_SLUGS.includes(module.slug) && + !TESTING_JS_SLUGS.includes(module.slug), + ), + epicReact: product.modules.filter((module) => + EPIC_REACT_SLUGS.includes(module.slug), + ), + testingJs: product.modules.filter((module) => + TESTING_JS_SLUGS.includes(module.slug), + ), + } + } + + const getModuleWithOverridesLink = (module: any, category: string) => { + switch (category) { + case 'epicReact': { + switch (module.slug) { + case 'react-interviews-with-experts': + return { + ...module, + slug: 'https://www.epicreact.dev/bonuses/interviews-with-experts', + } + case 'epic-react-v1-classic': + return { + ...module, + slug: 'https://www.epicreact.dev/learn', + } + default: + return { + ...module, + slug: `https://www.epicreact.dev/workshops/${module.slug}`, + } + } + } + case 'testingJs': + return { + ...module, + slug: `https://testingjavascript.com`, + } + default: + return module + } + } + + const renderModules = () => { + if (!product?.modules) return null + + if (product.slug !== 'megabundle-2024') { + return ( + <> + + Workshops + + {product.modules.map((module) => ( + + + + ))} + + ) + } + + const groupedModules = groupModules() + if (!groupedModules) return null + + return ( + <> + {Object.entries(groupedModules).map(([category, modules]) => { + if (modules.length === 0) return null + + const titles = { + epicReact: 'Epic React', + testingJs: 'Testing JavaScript', + epicWeb: 'Epic Web', + } as const + + return ( +
+ + {titles[category as keyof typeof titles]} + + {modules.map((module) => { + const modifiedModule = getModuleWithOverridesLink( + module, + category, + ) + + return ( + + + + ) + })} +
+ ) + })} + + ) + } + return ( {withWelcomeBanner ? ( @@ -319,21 +442,7 @@ const PurchasedProductTemplate: React.FC = ({ /> )} {product?.type === 'self-paced' && product.modules && ( -
- - Workshops - - {product.modules.map((module) => { - return ( - - - - ) - })} -
+
{renderModules()}
)} @@ -495,6 +604,26 @@ const ModuleItem: React.FC<{ module?.sections && module?.lessons && (sectionsFlatMap(module?.sections).length || module?.lessons.length) + + const isExternalLink = slug.startsWith('http') + + const LinkComponent = isExternalLink + ? ({children, href}: {children: React.ReactNode; href: string}) => ( + + {children} + + ) + : ({children, href}: {children: React.ReactNode; href: string}) => ( + + {children} + + ) + return (
{module.image.url && ( @@ -506,12 +635,13 @@ const ModuleItem: React.FC<{ /> )}
- {module.title} - +
{module.sections && ( @@ -526,7 +656,7 @@ const ModuleItem: React.FC<{ )}
- {isModuleInProgress && ( + {isModuleInProgress && !isExternalLink && ( <> > = ({ children, moduleSlug, + skipQuery = false, }) => { const {data: moduleProgress} = - trpcSkillLessons.moduleProgress.bySlug.useQuery({ - slug: moduleSlug, - }) + trpcSkillLessons.moduleProgress.bySlug.useQuery( + { + slug: moduleSlug, + }, + { + enabled: !skipQuery, + }, + ) return ( - + {children} )