Skip to content

Commit c1703ec

Browse files
committed
fetch and display website title for platform URLs in Metadata and Details components
1 parent 5cadee7 commit c1703ec

File tree

2 files changed

+97
-9
lines changed
  • app/[locale]

2 files changed

+97
-9
lines changed

app/[locale]/(user)/usecases/components/Metadata.tsx

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
1+
import { useEffect, useState } from 'react';
12
import Image from 'next/image';
23
import Link from 'next/link';
34
import { Button, Divider, Icon, Text, Tooltip } from 'opub-ui';
45

5-
import { formatDate } from '@/lib/utils';
6+
import { formatDate, getWebsiteTitle } from '@/lib/utils';
67
import { Icons } from '@/components/icons';
78

89
const Metadata = ({ data, setOpen }: { data: any; setOpen?: any }) => {
10+
const [platformTitle, setPlatformTitle] = useState<string | null>(null);
11+
12+
useEffect(() => {
13+
const fetchTitle = async () => {
14+
try {
15+
const urlItem = data.useCase.platformUrl;
16+
17+
if (urlItem && urlItem.value) {
18+
const title = await getWebsiteTitle(urlItem.value);
19+
setPlatformTitle(title);
20+
}
21+
} catch (error) {
22+
console.error('Error fetching website title:', error);
23+
}
24+
};
25+
26+
if (data.useCase.platformUrl === null) {
27+
setPlatformTitle('N/A');
28+
} else {
29+
fetchTitle();
30+
}
31+
}, [data.useCase.platformUrl]);
932
const metadata = [
1033
{
1134
label: data.useCase.isIndividualUsecase ? 'Publisher' : 'Organization',
@@ -27,18 +50,39 @@ const Metadata = ({ data, setOpen }: { data: any; setOpen?: any }) => {
2750
{data.useCase.isIndividualUsecase ? 'Publisher' : 'Organization'}
2851
</Link>
2952
),
53+
54+
},
55+
{
56+
label: 'Platform URL',
57+
value:
58+
data.useCase.platformUrl === null ? (
59+
'N/A'
60+
) : (
61+
<Link
62+
className="text-primaryBlue underline"
63+
href={data.useCase.platformUrl}
64+
>
65+
<Text className="underline" color="highlight" variant="bodyLg">
66+
{platformTitle?.trim() ? platformTitle : 'Visit Platform'}
67+
</Text>
68+
</Link>
69+
),
70+
tooltipContent: data.useCase.platformUrl === null ? 'N/A' : platformTitle,
3071
},
3172
{
3273
label: 'Started On',
3374
value: formatDate(data.useCase.created) || 'N/A',
75+
tooltipContent: formatDate(data.useCase.created) || 'N/A',
3476
},
3577
{
3678
label: 'Status',
3779
value: data.useCase.runningStatus.split('_').join('') || 'N/A',
80+
tooltipContent: data.useCase.runningStatus.split('_').join('') || 'N/A',
3881
},
3982
{
4083
label: 'Last Updated',
4184
value: formatDate(data.useCase.modified) || 'N/A',
85+
tooltipContent: formatDate(data.useCase.modified) || 'N/A',
4286
},
4387
{
4488
label: 'Sectors',
@@ -142,14 +186,14 @@ const Metadata = ({ data, setOpen }: { data: any; setOpen?: any }) => {
142186
{item.label}
143187
</Text>
144188
<Tooltip content={item?.tooltipContent}>
145-
<Text
146-
className="max-w-xs truncate"
147-
variant="bodyLg"
148-
fontWeight="medium"
149-
// title={item?.tooltipContent}
150-
>
151-
{typeof item.value === 'string' ? item.value : item.value}
152-
</Text>
189+
<Text
190+
className="max-w-xs truncate"
191+
variant="bodyLg"
192+
fontWeight="medium"
193+
// title={item?.tooltipContent}
194+
>
195+
{typeof item.value === 'string' ? item.value : item.value}
196+
</Text>
153197
</Tooltip>
154198
</div>
155199
))}

app/[locale]/dashboard/[entityType]/[entitySlug]/usecases/edit/[id]/publish/Details.tsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,34 @@
1+
import { useEffect, useState } from 'react';
12
import Image from 'next/image';
3+
import Link from 'next/link';
24
import { Text } from 'opub-ui';
35

6+
import { getWebsiteTitle } from '@/lib/utils';
7+
48
const Details = ({ data }: { data: any }) => {
9+
const [platformTitle, setPlatformTitle] = useState<string | null>(null);
10+
11+
useEffect(() => {
12+
const fetchTitle = async () => {
13+
try {
14+
const urlItem = data.useCases[0].platformUrl;
15+
16+
if (urlItem && urlItem.value) {
17+
const title = await getWebsiteTitle(urlItem.value);
18+
setPlatformTitle(title);
19+
}
20+
} catch (error) {
21+
console.error('Error fetching website title:', error);
22+
}
23+
};
24+
25+
if (data.useCases[0].platformUrl === null) {
26+
setPlatformTitle('N/A');
27+
} else {
28+
fetchTitle();
29+
}
30+
}, [data?.useCases[0]?.platformUrl]);
31+
532
const PrimaryDetails = [
633
{ label: 'Use Case Name', value: data?.useCases[0]?.title },
734
{ label: 'Summary', value: data?.useCases[0]?.summary },
@@ -38,6 +65,23 @@ const Details = ({ data }: { data: any }) => {
3865
</div>
3966
)
4067
)}
68+
69+
<div className="flex flex-wrap gap-2">
70+
<div className="md:w-1/6 lg:w-1/6">
71+
<Text variant="bodyMd">Platform URL:</Text>
72+
</div>
73+
<div>
74+
<Link
75+
className="text-primaryBlue underline"
76+
href={data.useCases[0].platformUrl}
77+
>
78+
<Text className="underline" color="highlight" variant="bodyLg">
79+
{platformTitle?.trim() ? platformTitle : 'Visit Platform'}
80+
</Text>
81+
</Link>
82+
</div>
83+
</div>
84+
4185
{data?.useCases[0]?.logo && (
4286
<div className="flex flex-wrap items-center gap-2">
4387
<div className="md:w-1/6 lg:w-1/6">

0 commit comments

Comments
 (0)