Skip to content
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

fix: redirect to course page #1507

Merged
merged 3 commits into from
Feb 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 49 additions & 12 deletions src/pages/[post].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,45 @@ import {
} from '@/hooks/mux/use-video-player-overlay'
import VideoPlayerOverlay from '@/components/posts/video-player-overlay'
import {MuxPlayerProvider, useMuxPlayer} from '@/hooks/use-mux-player'
import router from 'next/router'

export const PostTypeSchema = z.union([
z.literal('article'),
z.literal('lesson'),
z.literal('podcast'),
z.literal('tip'),
z.literal('course'),
])

export const PostStateSchema = z.union([
z.literal('draft'),
z.literal('published'),
z.literal('archived'),
z.literal('deleted'),
])

export const PostVisibilitySchema = z.union([
z.literal('public'),
z.literal('private'),
z.literal('unlisted'),
])

export const PostAccessSchema = z.union([z.literal('free'), z.literal('pro')])

export const FieldsSchema = z.object({
body: z.string().optional(),
slug: z.string().optional(),
state: z.string().optional(),
title: z.string().optional(),
access: z.string().optional(),
github: z.string().optional(),
gitpod: z.string().optional(),
postType: z.string().optional(),
visibility: z.string().optional(),
description: z.string().optional(),
eggheadLessonId: z.number().optional(),
title: z.string(),
postType: PostTypeSchema.default('lesson'),
summary: z.string().optional().nullable(),
body: z.string().nullable().optional(),
state: PostStateSchema.default('draft'),
visibility: PostVisibilitySchema.default('public'),
access: PostAccessSchema.default('pro'),
eggheadLessonId: z.number().nullish(),
eggheadPlaylistId: z.number().nullish(),
slug: z.string(),
description: z.string().nullish(),
github: z.string().nullish(),
gitpod: z.string().nullish(),
Comment on lines 65 to +78
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figured it's good to keep shape of PostSchema consistent with builder

primaryTagId: z.string().nullish(),
})
export type Fields = z.infer<typeof FieldsSchema>
Expand Down Expand Up @@ -286,6 +312,7 @@ export const getStaticProps: GetServerSideProps = async function ({params}) {
}

const {post, videoResource, tags} = result

const lesson = await fetch(
`${process.env.NEXT_PUBLIC_AUTH_DOMAIN}/api/v1/lessons/${post.fields.eggheadLessonId}`,
).then((res) => res.json())
Expand Down Expand Up @@ -366,11 +393,21 @@ export default function PostPage({
const imageParams = new URLSearchParams()
imageParams.set('title', post.fields?.title ?? '')

React.useEffect(() => {
if (post.fields.postType === 'course') {
router.replace(`/courses/${post.fields.slug}`)
}
}, [post.fields.postType, post.fields.slug, router])

if (post.fields.postType === 'course') {
return null
}

return (
<div>
<NextSeo
title={post.fields.title}
description={post.fields.description}
description={post.fields.description ?? ''}
canonical={`${process.env.NEXT_PUBLIC_DEPLOYMENT_URL}/${post.fields.slug}`}
twitter={{
cardType: 'summary_large_image',
Expand Down