import { Link } from 'react-router-dom' import { useQuery } from '@tanstack/react-query' import api from '../lib/api' /** * Funds / Funded by on the organization page (#1073), from GET /api/organizations/{id}/funding (company_grant). * Every dollar figure is what the foundation's IRS 990 Schedule I reports, summed by the API; a blank amount stays * blank. Nothing is shown as a figure when there is no grant on record. */ interface YearTotal { tax_year: string | null amount: number | null grants: number } interface GrantLine { grant_id: string amount: number | null purpose: string | null tax_year: string | null source_url: string | null } interface FundsEntry { grantee_name: string grantee_ein: string | null grantee_master_org_id: string | null grantee_city: string | null grantee_state_code: string | null foundation_name: string foundation_ein: string total_amount: number | null grants: number by_year: YearTotal[] top_grants: GrantLine[] } interface FundedByEntry { company_key: string company_name: string master_org_id: string foundation_name: string foundation_ein: string foundation_master_org_id: string | null relationship: string | null foundation_source_url: string | null total_amount: number | null grants: number by_year: YearTotal[] top_grants: GrantLine[] } interface Foundation { company_key: string | null company_name: string | null foundation_name: string | null foundation_ein: string | null foundation_master_org_id: string | null relationship: string | null foundation_source_url: string | null } interface Funding { master_org_id: string foundations: Foundation[] funds_total: number | null funds_grants: number funds_by_year: YearTotal[] funds: FundsEntry[] funded_by: FundedByEntry[] } const RELATIONSHIP_LABEL: Record = { founded_by_company: 'founded by', governed_by_company: 'governed by executives of', controls_company: 'the nonprofit that controls', } const usd = (n: number | null) => (n === null ? '—' : n.toLocaleString('en-US', { style: 'currency', currency: 'USD', maximumFractionDigits: 0 })) const plural = (n: number, one: string, many: string) => `${n.toLocaleString('en-US')} ${n === 1 ? one : many}` const titleCase = (s: string) => s.toLowerCase().replace(/\b\w/g, (c) => c.toUpperCase()) const fmtEin = (e: string) => (e.length === 9 ? `${e.slice(0, 2)}-${e.slice(2)}` : e) function Years({ years }: { years: YearTotal[] }) { if (!years.length) return null return (

{years.map((y) => `${y.tax_year ?? 'Year not stated'}: ${usd(y.amount)}`).join(' · ')}

) } function Grants({ grants }: { grants: GrantLine[] }) { if (!grants.length) return null return ( ) } export default function OrganizationFunding({ masterOrgId, isCompany }: { masterOrgId: string; isCompany: boolean }) { const q = useQuery({ queryKey: ['organization', masterOrgId, 'funding'], queryFn: async () => (await api.get(`/organizations/${encodeURIComponent(masterOrgId)}/funding`)).data, enabled: Boolean(masterOrgId), retry: 1, }) if (q.isPending) return

Loading funding…

if (q.isError) return

Funding records are unavailable right now.

const f = q.data const showFunds = isCompany || f.funds.length > 0 return ( <> {showFunds && (

Funds

{f.foundations.length === 0 ? (

No foundation of this company is in our IRS 990 grant records. Our grant records cover nonprofits that file a 990; private foundations that file a 990-PF aren't loaded yet.

) : ( <>

Grants reported on the IRS 990 of{' '} {f.foundations.map((fd, i) => ( {i > 0 ? ', ' : ''} {fd.foundation_name} {fd.foundation_ein ? ` (EIN ${fmtEin(fd.foundation_ein)})` : ''} {fd.relationship && fd.company_name ? `, ${RELATIONSHIP_LABEL[fd.relationship] ?? 'tied to'} ${fd.company_name}` : ''} {fd.foundation_source_url && ( <> {' '} source )} ))} . {plural(f.funds_grants, 'grant', 'grants')} {f.funds_total !== null ? `, ${usd(f.funds_total)} in all` : ''}.

{f.funds.length === 0 ? (

No grants on record.

) : (
    {f.funds.map((g) => (
  • {g.grantee_master_org_id ? ( {titleCase(g.grantee_name)} ) : ( titleCase(g.grantee_name) )}

    {[g.grantee_city ? titleCase(g.grantee_city) : null, g.grantee_state_code].filter(Boolean).join(', ')} {g.grantee_city || g.grantee_state_code ? ' · ' : ''} {usd(g.total_amount)} in {plural(g.grants, 'grant', 'grants')}

  • ))}
)} )}
)}

Funded by

{f.funded_by.length === 0 ? (

No grants on record from the foundations of the companies we track.

) : (
    {f.funded_by.map((c) => (
  • {c.company_name} through {c.foundation_name}

    {usd(c.total_amount)} in {plural(c.grants, 'grant', 'grants')}, as reported on the foundation's IRS 990 {c.foundation_source_url && ( <> {' · '} how it's tied to {c.company_name} )}

  • ))}
)}
) }