Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 9 additions & 27 deletions components/work/AwardProposalCard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use client';

import type { ReactNode } from 'react';
import Link from 'next/link';
import { Check, PenLine, Trophy } from 'lucide-react';
import { FundButton } from '@/components/Funding/FundButton';
import { Button } from '@/components/ui/Button';
Expand All @@ -13,7 +12,6 @@ import {
getAwardPhase,
} from '@/components/Funding/lib/fundingMechanism';
import { isFundraiseActive } from '@/components/Fund/lib/fundraiseUtils';
import { getLinkedGrantLink } from '@/components/work/lib/linkedGrant';
import { isWorkAuthor } from '@/components/work/lib/workAuthors';
import { useShowProposalTab } from '@/components/work/lib/workTabs';
import { useCurrencyPreference } from '@/contexts/CurrencyPreferenceContext';
Expand All @@ -30,10 +28,8 @@ interface TimelineStep {
readonly label: string;
/** When it happened, beside the label. */
readonly date?: string;
/** The line under the label: the RFP's name, a date, what is waited on. */
/** The line under the label: what was awarded, what is waited on. */
readonly detail?: ReactNode;
/** The detail stays on one line, cut short: the RFP's name can run long. */
readonly truncate?: boolean;
readonly done: boolean;
/** It can no longer happen: the RFP closed or the proposal expired. */
readonly disabled: boolean;
Expand Down Expand Up @@ -79,7 +75,7 @@ export function AwardProposalCard({
grantOpen,
fundraise,
});
const who = linkedGrant.organization.trim() || 'The funder';
const funder = linkedGrant.organization.trim();
const headline =
phase === 'none'
? formatCurrency({
Expand All @@ -94,41 +90,29 @@ export function AwardProposalCard({
const isAuthor = isWorkAuthor(work.authors, user?.authorProfile?.id);
const hasUpdates = updatesCount > 0;

const rfp = getLinkedGrantLink({ linkedGrant } as Work);
// The award is the funder's payment into the fundraise: its first
// contribution dates it.
const awardedDate = awarded ? firstContributionDate(fundraise) : undefined;

const steps: TimelineStep[] = [
{
// The RFP itself is the card under this one.
key: 'rfp',
label: 'Applied to RFP',
label: 'Applied',
// Publishing the proposal is what submits it to the RFP.
date: publishedDate,
detail: rfp.title ? (
rfp.href ? (
<Link
href={rfp.href}
className="underline decoration-white/30 underline-offset-2 transition-colors hover:text-white hover:decoration-white/70"
>
{rfp.title}
</Link>
) : (
rfp.title
)
) : undefined,
truncate: true,
done: true,
disabled: false,
},
{
key: 'awarded',
label: 'Awarded',
date: awardedDate,
// Only a named funder says anything the step doesn't already.
detail: awarded
? `${headline} from ${who}`
? funder && `From ${funder}`
: stillOpen
? `${who} picks who wins the prize once results are posted.`
? funder && `${funder} picks who wins the prize once results are posted.`
: 'The prize has closed',
done: awarded,
disabled: !awarded && !stillOpen,
Expand All @@ -137,6 +121,7 @@ export function AwardProposalCard({
key: 'update',
label: 'Update posted',
date: hasUpdates ? latestUpdateDate : undefined,
// With none, the empty circle says so; only an author gets a nudge.
detail: hasUpdates ? (
<button
type="button"
Expand All @@ -147,9 +132,7 @@ export function AwardProposalCard({
</button>
) : isAuthor ? (
'Share your progress and results.'
) : (
'No updates yet'
),
) : undefined,
done: hasUpdates,
disabled: false,
},
Expand Down Expand Up @@ -233,7 +216,6 @@ export function AwardProposalCard({
<p
className={cn(
'mt-0.5 text-[13px] leading-[18px]',
step.truncate && 'truncate',
step.disabled ? 'text-white/30' : 'text-white/60'
)}
>
Expand Down
87 changes: 87 additions & 0 deletions components/work/LinkedRfpCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
'use client';

import Link from 'next/link';
import { ChevronRight } from 'lucide-react';
import { DocumentThumbnail } from '@/components/Funding/dashboard/DocumentThumbnail';
import { isAwardMechanism } from '@/components/Funding/lib/fundingMechanism';
import { SidebarCard } from '@/components/ui/SidebarCard';
import { getLinkedGrantLink } from '@/components/work/lib/linkedGrant';
import { useCurrencyPreference } from '@/contexts/CurrencyPreferenceContext';
import { useExchangeRate } from '@/contexts/ExchangeRateContext';
import type { Work } from '@/types/work';
import { formatCurrencyAmount } from '@/utils/currency';
import { pluralizeSuffix } from '@/utils/stringUtils';
import { cn } from '@/utils/styles';

/**
* The RFP a proposal answers, in its sidebar under the funding card: the RFP's
* image, name, funder and amount, whether it is still open and how many
* proposals it has. The whole row opens the RFP.
*/
export function LinkedRfpCard({ work }: { work: Work }) {

Check warning on line 21 in components/work/LinkedRfpCard.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Mark the props of the component as read-only.

See more on https://sonarcloud.io/project/issues?id=ResearchHub_web&issues=AaH0EUmVpb6OmVeDEJQj&open=AaH0EUmVpb6OmVeDEJQj&pullRequest=1314
const { showUSD } = useCurrencyPreference();
const { exchangeRate } = useExchangeRate();
const grant = work.linkedGrant;
const { title, href } = getLinkedGrantLink(work);
if (!grant || !title) return null;

const isPrize = isAwardMechanism(grant.fundingMechanism);
const isOpen = grant.status === 'OPEN';
const count = grant.applicantCount;
const amount =
grant.fundingAmount > 0
? formatCurrencyAmount({
amount: grant.fundingAmount,
currency: grant.currency === 'USD' ? 'USD' : 'RSC',
showUSD,
exchangeRate,
shorten: true,
})
: undefined;
// The title falls back to the organization, so don't name it twice.
const funder = grant.organization.trim() !== title ? grant.organization.trim() : '';
const byline = [funder, amount].filter(Boolean).join(' · ');

const row = (
<>
<DocumentThumbnail image={grant.imageUrl} />
<span className="min-w-0 flex-1 text-[13px] leading-[18px]">
<span className="line-clamp-2 font-semibold text-gray-900">{title}</span>
{byline && <span className="mt-0.5 block truncate text-gray-500">{byline}</span>}
<span className="mt-0.5 flex items-center gap-1.5 text-gray-500">
<span
aria-hidden="true"
className={cn('h-1.5 w-1.5 rounded-full', isOpen ? 'bg-emerald-500' : 'bg-gray-400')}
/>
{isOpen ? 'Open' : 'Closed'}
{count > 0 && (
<>
<span aria-hidden="true">·</span>
{count} {isPrize ? 'competitor' : 'proposal'}
{pluralizeSuffix(count)}
</>
)}
</span>
</span>
</>
);

return (
<SidebarCard title={isPrize ? 'Competing for' : 'Submitted to'}>
{href ? (
<Link
href={href}
className="group -mx-2 mt-2 flex items-start gap-2.5 rounded-md px-2 py-2 transition-colors hover:bg-gray-50"
>
{row}
<ChevronRight
className="mt-2.5 h-4 w-4 shrink-0 text-gray-400 transition-colors group-hover:text-gray-600"
aria-hidden="true"
/>
</Link>
) : (
<div className="mt-2 flex items-start gap-2.5 py-2">{row}</div>
)}
</SidebarCard>
);
}
9 changes: 5 additions & 4 deletions components/work/ProposalByline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import { cn } from '@/utils/styles';
/**
* Over a proposal's Proposal tab: who proposes it, with the lead author's
* face, then chips for its review score, when it was posted, the RFP it
* answers, whether it went in privately, and its DOI. The other tabs open
* straight on their content.
* answers (below lg, where the sidebar is hidden), whether it went in
* privately, and its DOI. The other tabs open straight on their content.
*/
export function ProposalByline({ work, metadata }: { work: Work; metadata: WorkMetadata }) {
const showTab = useShowProposalTab(work);
Expand Down Expand Up @@ -83,13 +83,14 @@ export function ProposalByline({ work, metadata }: { work: Work; metadata: WorkM
Posted {formatTimestamp(postedDate, false)}
</span>
)}
{/* From lg up the sidebar's RFP card names it; below, the sidebar is hidden. */}
{grantTitle &&
(grantHref ? (
<Link href={grantHref} className={BYLINE_LINK_CHIP_CLASS}>
<Link href={grantHref} className={cn(BYLINE_LINK_CHIP_CLASS, 'lg:hidden')}>
<span className="truncate">{grantTitle}</span>
</Link>
) : (
<span className={BYLINE_CHIP_CLASS}>
<span className={cn(BYLINE_CHIP_CLASS, 'lg:hidden')}>
<span className="truncate">{grantTitle}</span>
</span>
))}
Expand Down
4 changes: 3 additions & 1 deletion components/work/ProposalSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { WorkMetadata } from '@/services/metadata.service';
import type { Work } from '@/types/work';
import { isAwardMechanism } from '@/components/Funding/lib/fundingMechanism';
import { AwardProposalCard } from './AwardProposalCard';
import { LinkedRfpCard } from './LinkedRfpCard';
import { ProposalFundingCard } from './ProposalFundingCard';
import { ProposalReviewsCard } from './ProposalReviewsCard';
import { AiPeerReviewSection } from './components/AiPeerReviewSection';
Expand All @@ -20,7 +21,7 @@ interface ProposalSidebarProps {

/**
* The proposal page's right sidebar, in the RFP sidebar's style: the funding
* card over who reviewed it, then the AI's key insights and the nonprofit the
* card, the RFP it answers, who reviewed it, then the AI's key insights and the nonprofit the
* money goes to, where it has them.
*/
export function ProposalSidebar({
Expand All @@ -45,6 +46,7 @@ export function ProposalSidebar({
/>
)}
{fundraise && !isAward && <ProposalFundingCard fundraise={fundraise} />}
<LinkedRfpCard work={work} />
<ProposalReviewsCard work={work} />
<AiPeerReviewSection aiPeerReview={work.aiPeerReview} />
{fundraise && <NonprofitSection fundraiseId={fundraise.id} />}
Expand Down