Skip to content

Commit 2598224

Browse files
committed
Refactor Metadata component to improve conditional rendering for publisher and organization details
1 parent b1baabb commit 2598224

File tree

1 file changed

+25
-35
lines changed

1 file changed

+25
-35
lines changed

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

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,22 @@ import { formatDate } from '@/lib/utils';
66
import { Icons } from '@/components/icons';
77

88
const Metadata = ({ data, setOpen }: { data: any; setOpen?: any }) => {
9-
109
const metadata = [
1110
{
12-
label: 'Publisher',
13-
value: data.useCase.publishers[0]?.name || 'N/A',
11+
label: data.useCase.isIndividualUsecase ? 'Publisher' : 'Organization',
12+
value: data.useCase.isIndividualUsecase
13+
? data.useCase.user.fullName
14+
: data?.useCase.organization?.name,
1415
},
15-
// {
16-
// label: 'Website',
17-
// value: (
18-
// <Link
19-
// href={data.useCase.website}
20-
// target="_blank"
21-
// rel="noopener noreferrer"
22-
// className="text-primaryBlue underline"
23-
// >
24-
// Visit Website
25-
// </Link>
26-
// ),
27-
// },
2816
{
2917
label: 'Contact',
3018
value: (
3119
<Link
3220
className="text-primaryBlue underline"
33-
href={`mailto:${data.useCase.publishers[0]?.contactEmail}`}
21+
href={`${data.useCase.isIndividualUsecase ? `mailto:${data.useCase.user.email}` : `mailto:${data.useCase.organization.contactEmail}`}`}
3422
>
35-
Contact Publisher{' '}
23+
Contact{' '}
24+
{data.useCase.isIndividualUsecase ? 'Publisher' : 'Organization'}
3625
</Link>
3726
),
3827
},
@@ -94,6 +83,13 @@ const Metadata = ({ data, setOpen }: { data: any; setOpen?: any }) => {
9483
),
9584
},
9685
];
86+
const image = data.useCase.isIndividualUsecase
87+
? data.useCase?.user?.profilePicture
88+
? `${process.env.NEXT_PUBLIC_BACKEND_URL}/${data.useCase.user.profilePicture.url}`
89+
: '/profile.png'
90+
: data?.useCase.organization?.logo
91+
? `${process.env.NEXT_PUBLIC_BACKEND_URL}/${data.useCase.organization.logo.url}`
92+
: '/org.png';
9793

9894
return (
9995
<div className="flex flex-col gap-10 px-7 py-10">
@@ -119,23 +115,17 @@ const Metadata = ({ data, setOpen }: { data: any; setOpen?: any }) => {
119115
<Divider />
120116
<div className=" flex flex-col gap-8">
121117
<div className=" hidden rounded-2 border-1 border-solid border-greyExtralight p-2 lg:block">
122-
{data?.organization?.logo?.url ? (
123-
<Image
124-
height={140}
125-
width={100}
126-
src={`${process.env.NEXT_PUBLIC_BACKEND_URL}/${data.useCase.publishers[0]?.logo?.url}`}
127-
alt={`${data.useCase.publishers?.name} logo`}
128-
className="w-full object-contain"
129-
/>
130-
) : (
131-
<Image
132-
height={140}
133-
width={100}
134-
src={'/fallback.svg'}
135-
alt={'fallback logo'}
136-
className="fill-current w-full object-contain"
137-
/>
138-
)}
118+
<Image
119+
height={140}
120+
width={100}
121+
src={image}
122+
alt={
123+
data.useCase.isIndividualUsecase
124+
? 'Publisher logo'
125+
: 'Organization logo'
126+
}
127+
className="w-full object-contain"
128+
/>
139129
</div>
140130
<div className="flex flex-col gap-8">
141131
{metadata.map((item, index) => (

0 commit comments

Comments
 (0)