2022-04-30 19:47:47 +00:00
|
|
|
import { StarIcon } from '@heroicons/react/solid'
|
2022-05-22 08:36:05 +00:00
|
|
|
import { sumBy } from 'lodash'
|
2022-04-29 23:35:56 +00:00
|
|
|
import Link from 'next/link'
|
2022-05-03 14:00:33 +00:00
|
|
|
import Image from 'next/image'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { Charity } from 'common/charity'
|
|
|
|
import { useCharityTxns } from 'web/hooks/use-charity-txns'
|
2022-05-10 18:14:24 +00:00
|
|
|
import { manaToUSD } from '../../../common/util/format'
|
2022-04-29 23:35:56 +00:00
|
|
|
import { Row } from '../layout/row'
|
2022-06-14 03:53:29 +00:00
|
|
|
import { Col } from '../layout/col'
|
2022-04-29 23:35:56 +00:00
|
|
|
|
2022-06-14 03:53:29 +00:00
|
|
|
export function CharityCard(props: { charity: Charity; match?: number }) {
|
|
|
|
const { charity, match } = props
|
|
|
|
const { slug, photo, preview, id, tags } = charity
|
2022-04-29 23:35:56 +00:00
|
|
|
|
|
|
|
const txns = useCharityTxns(id)
|
2022-05-22 08:36:05 +00:00
|
|
|
const raised = sumBy(txns, (txn) => txn.amount)
|
2022-04-29 23:35:56 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Link href={`/charity/${slug}`} passHref>
|
2022-04-30 03:55:32 +00:00
|
|
|
<div className="card card-compact transition:shadow flex-1 cursor-pointer border-2 bg-white hover:shadow-md">
|
2022-05-07 12:15:40 +00:00
|
|
|
<Row className="mt-6 mb-2">
|
2022-04-30 19:47:47 +00:00
|
|
|
{tags?.includes('Featured') && <FeaturedBadge />}
|
|
|
|
</Row>
|
2022-05-03 15:12:42 +00:00
|
|
|
<div className="px-8">
|
|
|
|
<figure className="relative h-32">
|
|
|
|
{photo ? (
|
|
|
|
<Image src={photo} alt="" layout="fill" objectFit="contain" />
|
|
|
|
) : (
|
|
|
|
<div className="h-full w-full bg-gradient-to-r from-slate-300 to-indigo-200" />
|
|
|
|
)}
|
|
|
|
</figure>
|
|
|
|
</div>
|
2022-04-29 23:35:56 +00:00
|
|
|
<div className="card-body">
|
2022-05-02 12:45:05 +00:00
|
|
|
{/* <h3 className="card-title line-clamp-3">{name}</h3> */}
|
2022-04-29 23:35:56 +00:00
|
|
|
<div className="line-clamp-4 text-sm">{preview}</div>
|
2022-04-30 19:47:47 +00:00
|
|
|
{raised > 0 && (
|
2022-06-14 03:53:29 +00:00
|
|
|
<>
|
|
|
|
<Row className="mt-4 flex-1 items-end justify-center gap-6 text-gray-900">
|
|
|
|
<Col>
|
|
|
|
<span className="text-3xl font-semibold">
|
|
|
|
{formatUsd(raised)}
|
|
|
|
</span>
|
|
|
|
<span>raised</span>
|
|
|
|
</Col>
|
|
|
|
{match && (
|
|
|
|
<Col className="text-gray-500">
|
|
|
|
<span className="text-xl">+{formatUsd(match)}</span>
|
|
|
|
<span className="">match</span>
|
|
|
|
</Col>
|
|
|
|
)}
|
|
|
|
</Row>
|
|
|
|
</>
|
2022-04-30 19:47:47 +00:00
|
|
|
)}
|
2022-04-29 23:35:56 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Link>
|
|
|
|
)
|
|
|
|
}
|
2022-04-30 19:47:47 +00:00
|
|
|
|
2022-06-14 03:53:29 +00:00
|
|
|
function formatUsd(mana: number) {
|
|
|
|
return mana < 100 ? manaToUSD(mana) : '$' + Math.floor(mana / 100)
|
|
|
|
}
|
|
|
|
|
2022-04-30 19:47:47 +00:00
|
|
|
function FeaturedBadge() {
|
|
|
|
return (
|
|
|
|
<span className="inline-flex items-center gap-1 bg-yellow-100 px-3 py-0.5 text-sm font-medium text-yellow-800">
|
|
|
|
<StarIcon className="h-4 w-4" aria-hidden="true" /> Featured
|
|
|
|
</span>
|
|
|
|
)
|
|
|
|
}
|