Skip to content

Commit 0230e79

Browse files
committed
♻️ improve redirects using URL generator and update project links with type safety
1 parent 07e21cd commit 0230e79

File tree

10 files changed

+56
-18
lines changed

10 files changed

+56
-18
lines changed

frontend/apps/app/app/(app)/app/page.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createClient } from '@/libs/db/server'
2+
import { urlgen } from '@/utils/routes'
23
import { prisma } from '@liam-hq/db'
34
import { redirect } from 'next/navigation'
45

@@ -7,7 +8,7 @@ export default async function Page() {
78

89
const { data, error } = await supabase.auth.getUser()
910
if (error || !data?.user) {
10-
redirect('/app/login')
11+
redirect(urlgen('login'))
1112
}
1213

1314
const projects = await prisma.project.findMany({
@@ -18,8 +19,8 @@ export default async function Page() {
1819
})
1920

2021
if (projects.length > 0) {
21-
redirect('/app/projects')
22+
redirect(urlgen('projects'))
2223
}
2324

24-
redirect('/app/projects/new')
25+
redirect(urlgen('projects/new'))
2526
}

frontend/apps/app/app/(app)/app/projects/[projectId]/erd/[branchOrCommit]/[...slug]/page.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from 'node:path'
22
import type { PageProps } from '@/app/types'
33
import { createClient } from '@/libs/db/server'
4+
import { branchOrCommitSchema } from '@/utils/routes'
45
import {
56
type DBStructure,
67
applyOverrides,
@@ -64,7 +65,7 @@ const processOverrideFile = async (
6465

6566
const paramsSchema = v.object({
6667
projectId: v.string(),
67-
branchOrCommit: v.string(),
68+
branchOrCommit: branchOrCommitSchema,
6869
slug: v.array(v.string()),
6970
})
7071

frontend/apps/app/components/CommonLayout/CommonLayout.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { urlgen } from '@/utils/routes'
12
import Link from 'next/link'
23
import type React from 'react'
34
import type { ReactNode } from 'react'
@@ -18,7 +19,7 @@ export const CommonLayout: React.FC<CommonLayoutProps> = ({ children }) => {
1819
<nav className={styles.nav}>
1920
<ul>
2021
<li>
21-
<Link href="/app/projects" className={styles.link}>
22+
<Link href={urlgen('projects')} className={styles.link}>
2223
<span className={styles.icon}>📁</span>
2324
Projects
2425
</Link>

frontend/apps/app/features/migrations/pages/MigrationDetailPage/MigrationDetailPage.tsx

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { urlgen } from '@/utils/routes'
12
import { prisma } from '@liam-hq/db'
23
import { getPullRequestDetails, getPullRequestFiles } from '@liam-hq/github'
34
import { minimatch } from 'minimatch'
@@ -78,7 +79,11 @@ async function getMigrationContents(migrationId: string) {
7879
)
7980

8081
const erdLinks = matchedFiles.map((filename) => ({
81-
path: `/app/projects/${overallReview.projectId}/erd/${prDetails.head.ref}/${filename}`,
82+
path: urlgen('projects/[projectId]/erd/[branchOrCommit]/[...slug]', {
83+
projectId: `${overallReview.projectId}`,
84+
branchOrCommit: prDetails.head.ref,
85+
slug: filename,
86+
}),
8287
filename,
8388
}))
8489

@@ -101,7 +106,10 @@ export const MigrationDetailPage: FC<Props> = async ({ migrationId }) => {
101106

102107
return (
103108
<main className={styles.wrapper}>
104-
<Link href={`/app/projects/${projectId}`} className={styles.backLink}>
109+
<Link
110+
href={urlgen('projects/[projectId]', { projectId: `${projectId}` })}
111+
className={styles.backLink}
112+
>
105113
← Back to Project Detail
106114
</Link>
107115

frontend/apps/app/features/projects/actions/addProject.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use server'
22

3+
import { urlgen } from '@/utils/routes'
34
import { prisma } from '@liam-hq/db'
45
import { redirect } from 'next/navigation'
56

@@ -34,5 +35,5 @@ export const addProject = async (formData: FormData) => {
3435
return project
3536
})
3637

37-
redirect(`/app/projects/${result.id}`)
38+
redirect(urlgen('projects/[projectId]', { projectId: `${result.id}` }))
3839
}

frontend/apps/app/features/projects/actions/approveKnowledgeSuggestion.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use server'
22

3+
import { urlgen } from '@/utils/routes'
34
import { prisma } from '@liam-hq/db'
45
import { updateFileContent } from '@liam-hq/github'
56
import { redirect } from 'next/navigation'
@@ -84,7 +85,10 @@ export const approveKnowledgeSuggestion = async (formData: FormData) => {
8485

8586
// Redirect back to the knowledge suggestion detail page
8687
redirect(
87-
`/app/projects/${suggestion.projectId}/knowledge-suggestions/${suggestionId}`,
88+
urlgen('projects/[projectId]/knowledge-suggestions/[id]', {
89+
projectId: `${suggestion.projectId}`,
90+
id: `${suggestionId}`,
91+
}),
8892
)
8993
} catch (error) {
9094
console.error('Error approving knowledge suggestion:', error)

frontend/apps/app/features/projects/pages/KnowledgeSuggestionDetailPage/KnowledgeSuggestionDetailPage.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { urlgen } from '@/utils/routes'
12
import { prisma } from '@liam-hq/db'
23
import Link from 'next/link'
34
import { notFound } from 'next/navigation'
@@ -61,7 +62,9 @@ export const KnowledgeSuggestionDetailPage: FC<Props> = async ({
6162
<div>
6263
<div>
6364
<Link
64-
href={`/app/projects/${projectId}/knowledge-suggestions`}
65+
href={urlgen('projects/[projectId]/knowledge-suggestions', {
66+
projectId,
67+
})}
6568
aria-label="Back to knowledge suggestions list"
6669
>
6770
← Back to Knowledge Suggestions

frontend/apps/app/features/projects/pages/KnowledgeSuggestionsListPage/KnowledgeSuggestionsListPage.tsx

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { urlgen } from '@/utils/routes'
12
import { prisma } from '@liam-hq/db'
23
import Link from 'next/link'
34
import { notFound } from 'next/navigation'
@@ -47,7 +48,9 @@ export const KnowledgeSuggestionsListPage: FC<Props> = async ({
4748
<div>
4849
<div>
4950
<Link
50-
href={`/app/projects/${projectId}`}
51+
href={urlgen('projects/[projectId]', {
52+
projectId,
53+
})}
5154
aria-label="Back to project details"
5255
>
5356
← Back to Project
@@ -66,7 +69,13 @@ export const KnowledgeSuggestionsListPage: FC<Props> = async ({
6669
{knowledgeSuggestions.map((suggestion) => (
6770
<li key={suggestion.id}>
6871
<Link
69-
href={`/app/projects/${projectId}/knowledge-suggestions/${suggestion.id}`}
72+
href={urlgen(
73+
'projects/[projectId]/knowledge-suggestions/[id]',
74+
{
75+
projectId,
76+
id: `${suggestion.id}`,
77+
},
78+
)}
7079
>
7180
<div>{suggestion.title}</div>
7281
<div>

frontend/apps/app/features/projects/pages/ProjectDetailPage/ProjectDetailPage.tsx

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { urlgen } from '@/utils/routes'
12
import { prisma } from '@liam-hq/db'
23
import Link from 'next/link'
34
import { notFound } from 'next/navigation'
@@ -76,7 +77,7 @@ export const ProjectDetailPage: FC<Props> = async ({ projectId }) => {
7677
<div className={styles.header}>
7778
<div className={styles.headerLeft}>
7879
<Link
79-
href="/app/projects"
80+
href={urlgen('projects')}
8081
className={styles.backLink}
8182
aria-label="Back to projects list"
8283
>
@@ -86,13 +87,17 @@ export const ProjectDetailPage: FC<Props> = async ({ projectId }) => {
8687
</div>
8788
<div className={styles.headerActions}>
8889
<Link
89-
href={`/app/projects/${project.id}/migrations`}
90+
href={urlgen('projects/[projectId]/migrations', {
91+
projectId,
92+
})}
9093
className={styles.actionButton}
9194
>
9295
View Migrations
9396
</Link>
9497
<Link
95-
href={`/app/projects/${project.id}/docs`}
98+
href={urlgen('projects/[projectId]/docs', {
99+
projectId,
100+
})}
96101
className={styles.actionButton}
97102
>
98103
View Docs
@@ -111,7 +116,9 @@ export const ProjectDetailPage: FC<Props> = async ({ projectId }) => {
111116
{project.migrations.map((migration) => (
112117
<li key={migration.id}>
113118
<Link
114-
href={`/app/migrations/${migration.id}`}
119+
href={urlgen('migrations/[migrationId]', {
120+
migrationId: `${migration.id}`,
121+
})}
115122
style={{
116123
textDecoration: 'underline',
117124
}}

frontend/apps/app/features/projects/pages/ProjectsPage/ProjectsPage.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { urlgen } from '@/utils/routes'
12
import Link from 'next/link'
23
import type { FC } from 'react'
34
import styles from './ProjectsPage.module.css'
@@ -10,7 +11,7 @@ export const ProjectsPage: FC = async () => {
1011
<div className={styles.container}>
1112
<div className={styles.header}>
1213
<h1 className={styles.title}>Projects</h1>
13-
<Link href="/app/projects/new" className={styles.createButton}>
14+
<Link href={urlgen('projects/new')} className={styles.createButton}>
1415
Create New Project
1516
</Link>
1617
</div>
@@ -25,7 +26,9 @@ export const ProjectsPage: FC = async () => {
2526
{projects.map((project) => (
2627
<Link
2728
key={project.id}
28-
href={`/app/projects/${project.id}`}
29+
href={urlgen('projects/[projectId]', {
30+
projectId: `${project.id}`,
31+
})}
2932
className={styles.projectCard}
3033
>
3134
<h2>{project.name || 'Untitled Project'}</h2>

0 commit comments

Comments
 (0)