Skip to content

Commit e859e09

Browse files
committed
fix: url and crm
1 parent 74f9036 commit e859e09

6 files changed

Lines changed: 49 additions & 13 deletions

File tree

src/components/Blocks/FeaturesBlock.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { FeaturesBlock as FeaturesBlockProps } from '@/payload-types'
33
import { cn } from '@/lib/utils/cn'
44
import React from 'react'
55
import { RichText } from '@/components/Payload/RichText'
6+
import { getLinkHref } from '@/lib/utils/getLinkHref'
67
import type { Page } from '@/payload-types'
78
import { ContentCard, FeatureCard } from '../Cards'
89
// type Props = {
@@ -134,10 +135,7 @@ const IconFeature = ({ section, index }: { section: Section; index: number }) =>
134135
)
135136
return section.link ? (
136137
<a
137-
href={
138-
section.link.url ? section.link.url : '#'
139-
// : `/${section.link.reference?.relationTo}/${(section.link.reference?.value as Page)?.slug || '#'}`
140-
}
138+
href={getLinkHref(section.link)}
141139
key={index}
142140
className="no-underline group"
143141
>

src/components/CRM/DealDetails.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ try {
134134
}
135135

136136
const getUserById = (userId: string) => {
137-
return users?.find((user) => (user as User).id === Number(userId));
137+
return users?.find((user) => (user as User).id === userId);
138138
};
139139

140140
return (

src/components/CRM/NewDealForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export function NewDealForm({
157157
}
158158

159159
const getUserById = (userId: string) => {
160-
return users?.find((user) => (user as User).id === Number(userId))
160+
return users?.find((user) => (user as User).id === userId)
161161
}
162162

163163
const getCustomerById = (customerID: string) => {

src/components/CRM/mockData.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ export const mockCategories: DealCategory[] = [
1818

1919

2020
export const mockUsers: User[] = [
21-
{ id: 1, name: "John Doe", email: "john.doe@example.com", role: "user", createdAt: "2023-01-01", updatedAt: "2023-01-01" },
22-
{ id: 2, name: "Jane Smith", email: "jane.smith@example.com", role: "user", createdAt: "2023-01-01", updatedAt: "2023-01-01" },
23-
{ id: 3, name: "Bob Johnson", email: "bob.johnson@example.com", role: "user", createdAt: "2023-01-01", updatedAt: "2023-01-01" },
24-
{ id: 4, name: "Alice Brown", email: "alice.brown@example.com", role: "user", createdAt: "2023-01-01", updatedAt: "2023-01-01" },
25-
{ id: 5, name: "Charlie Davis", email: "charlie.davis@example.com", role: "user", createdAt: "2023-01-01", updatedAt: "2023-01-01" },
21+
{ id: "1", name: "John Doe", email: "john.doe@example.com", role: "user", createdAt: "2023-01-01", updatedAt: "2023-01-01" },
22+
{ id: "2", name: "Jane Smith", email: "jane.smith@example.com", role: "user", createdAt: "2023-01-01", updatedAt: "2023-01-01" },
23+
{ id: "3", name: "Bob Johnson", email: "bob.johnson@example.com", role: "user", createdAt: "2023-01-01", updatedAt: "2023-01-01" },
24+
{ id: "4", name: "Alice Brown", email: "alice.brown@example.com", role: "user", createdAt: "2023-01-01", updatedAt: "2023-01-01" },
25+
{ id: "5", name: "Charlie Davis", email: "charlie.davis@example.com", role: "user", createdAt: "2023-01-01", updatedAt: "2023-01-01" },
2626
];
2727

2828
export const mockDeals: Deal[] = [
@@ -44,7 +44,7 @@ export const mockDeals: Deal[] = [
4444
id: 2,
4545
customer: { id: 2, name: "GlobalTech", active: true, createdAt: "2023-01-01", updatedAt: "2023-01-01" },
4646
value: 75000,
47-
assignee: { id: 2, name: "Jane Smith", email: "jane.smith@example.com", role: "user", createdAt: "2023-01-01", updatedAt: "2023-01-01" },
47+
assignee: { id: "2", name: "Jane Smith", email: "jane.smith@example.com", role: "user", createdAt: "2023-01-01", updatedAt: "2023-01-01" },
4848
status: "Proposal Made",
4949
categories: mockCategories.slice(0, 3), // Pass in 3 of the mockCategories
5050
dateLogged: "2023-02-01",

src/components/Cards/FeatureCard.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Sparkles } from 'lucide-react'
44
import { RichText } from '@/components/Payload/RichText'
55
import { DynamicIcon, type DynamicIconProps, type IconType } from '../Images'
66
import Image, { type StaticImageData } from 'next/image'
7+
import { getLinkHref } from '@/lib/utils/getLinkHref'
78

89
import type { FeaturesBlock as FeaturesBlockProps, Media } from '@/payload-types'
910
type Section = NonNullable<FeaturesBlockProps['features']>[number]
@@ -68,7 +69,7 @@ export function FeatureCard({
6869

6970
return (
7071
<a
71-
href={link?.url || '#'}
72+
href={getLinkHref(link)}
7273
className={cn(
7374
'min-w-56 max-w-xl h-full flex flex-col group bg-background',
7475
image ? 'p-0' : 'p-6 md:p-8',

src/utils/getLinkHref.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import type { Page } from '@/payload-types'
2+
3+
/**
4+
* Constructs a link href from either a direct URL or a reference structure
5+
* @param link - Link object with optional url and reference
6+
* @returns The constructed href string or '#'
7+
*/
8+
export function getLinkHref(link?: {
9+
url?: string | null
10+
reference?: {
11+
relationTo?: string
12+
value?: any
13+
} | null
14+
}): string {
15+
if (!link) return '#'
16+
17+
// If a direct URL exists, use it
18+
if (link.url) return link.url
19+
20+
// If reference exists, build URL from relationTo and slug
21+
if (link.reference?.value) {
22+
const { relationTo, value } = link.reference
23+
const slug = (value as Page)?.slug
24+
25+
if (!slug) return '#'
26+
27+
// For pages, just use the slug
28+
if (relationTo === 'pages') {
29+
return `/${slug}`
30+
}
31+
32+
// For other relationTo types, use relationTo/slug format
33+
return `/${relationTo}/${slug}`
34+
}
35+
36+
return '#'
37+
}

0 commit comments

Comments
 (0)