Skip to content

Commit 3138b13

Browse files
fix(company): fix logo link for companies
1 parent 4d58522 commit 3138b13

7 files changed

Lines changed: 40 additions & 17 deletions

File tree

src/components/companies/company-badge.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ export default function CompanyBadge({ company }: { company: Company }) {
99
}}
1010
avatarProps={{
1111
radius: 'lg',
12-
src: `${company?.logo}`,
12+
src: company.domain
13+
? `https://img.logo.dev/${company.domain}?token=${process.env.NEXT_PUBLIC_LOGO_DEV_TOKEN}`
14+
: (company.logo ?? ''),
1315
size: 'md',
14-
className:'shrink-0'
16+
className: 'shrink-0',
1517
}}
1618
description={company.domain}
1719
name={company.name}

src/components/companies/create-company-form.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
'use client';
22

33
import { Key, useEffect, useState } from 'react';
4+
45
import { useRouter } from 'next/navigation';
6+
57
import { createCompany } from '@/actions';
8+
import { getCompanyLogo } from '@/helpers/companies';
69
import {
710
Autocomplete,
811
AutocompleteItem,
@@ -17,7 +20,12 @@ import { toast } from 'react-toastify';
1720

1821
const renderOption = (company: any) => (
1922
<div className="flex gap-2 items-center">
20-
<Avatar alt={company?.name} src={company?.logo} size="sm" isBordered />
23+
<Avatar
24+
alt={company?.name}
25+
src={getCompanyLogo(company)}
26+
size="sm"
27+
isBordered
28+
/>
2129
<div className="flex flex-col">
2230
<span>{company?.name}</span>
2331
<span className="text-tiny text-default-400">{company?.domain}</span>

src/components/reports/reports-table.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import React from 'react';
44

55
import { useRouter } from 'next/navigation';
66

7+
import { getCompanyLogo } from '@/helpers/companies';
78
import { pascalToSentenceCase } from '@/helpers/strings/pascalToSentenceCase';
89
import { ReportWithTags, UserWithCompanies } from '@/types';
910
import {
@@ -140,7 +141,7 @@ export default function ReportsTable({
140141
}}
141142
avatarProps={{
142143
radius: 'lg',
143-
src: `${report?.company?.logo}` || '',
144+
src: getCompanyLogo(report?.company!) || '',
144145
size: 'md',
145146
className: 'shrink-0',
146147
}}

src/components/sites/site-badge.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getCompanyLogo } from '@/helpers/companies';
12
import { Avatar } from '@nextui-org/react';
23
import { Company } from '@prisma/client';
34

@@ -7,7 +8,7 @@ export default function SiteBadge({ company }: { company: Company }) {
78
{/* <div className="flex gap-2 items-center flex-wrap justify-center"> */}
89
<Avatar
910
alt={company?.name}
10-
src={`${company?.logo}`}
11+
src={getCompanyLogo(company)}
1112
className="shrink-0"
1213
isBordered
1314
radius="sm"

src/components/sites/sites-list.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { useRouter } from 'next/navigation';
44

5+
import { getCompanyLogo } from '@/helpers/companies';
56
import { CompanyWithReports } from '@/types';
67
import {
78
Avatar,
@@ -28,13 +29,13 @@ export default function SitesList({
2829
companies: CompanyWithReports[];
2930
}) {
3031
const router = useRouter();
31-
return (companies || []).map((c) => {
32-
const link = getHost(c.domain ?? undefined);
32+
return (companies || []).map((company) => {
33+
const link = getHost(company.domain ?? undefined);
3334

3435
return (
3536
<Card
3637
className="w-4/5 sm:w-2/3 md:w-1/2 lg:w-10/12"
37-
key={c.id}
38+
key={company.id}
3839
isPressable
3940
onPress={() => {
4041
router.push(`/sites/${link}`);
@@ -43,27 +44,29 @@ export default function SitesList({
4344
<CardHeader className="flex justify-between items-center bg-blue-400">
4445
<div className="flex gap-3 items-center">
4546
<Avatar
46-
alt={c.name + ' logo'}
47+
alt={company.name + ' logo'}
4748
radius="sm"
48-
src={`${c.logo}`}
49-
name={c.name}
49+
src={getCompanyLogo(company)}
50+
name={company.name}
5051
/>
5152
<div className="flex flex-col">
52-
<p className="text-md">{c.name}</p>
53-
<p className="text-small text-foreground">{c.domain}</p>
53+
<p className="text-md">{company.name}</p>
54+
<p className="text-small text-foreground">{company.domain}</p>
5455
</div>
5556
</div>
56-
<p className="text-md">{c.reports.length} reports</p>
57+
<p className="text-md">{company.reports.length} reports</p>
5758
</CardHeader>
5859
<CardBody>
5960
<p>
6061
Categories:{' '}
61-
{c.reports.map((r) => r.tags.map((tag) => tag.name).join(', '))}
62+
{company.reports.map((r) =>
63+
r.tags.map((tag) => tag.name).join(', '),
64+
)}
6265
</p>
6366
</CardBody>
6467
<CardFooter className="flex justify-end">
65-
<Link showAnchorIcon href={`${c.domain}`}>
66-
{c.domain}
68+
<Link showAnchorIcon href={`${company.domain}`}>
69+
{company.domain}
6770
</Link>
6871
</CardFooter>
6972
</Card>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Company } from "@prisma/client";
2+
export const getCompanyLogo = (company: Company) => {
3+
if (company.logo) return company.logo;
4+
if (company.domain)
5+
return `https://img.logo.dev/${company.domain}?token=${process.env.NEXT_PUBLIC_LOGO_DEV_TOKEN}`;
6+
return `https://placehold.co/200x200?text=${company.name}`;
7+
};

src/helpers/companies/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './getCompanyLogo';

0 commit comments

Comments
 (0)