Read txns for charity card and charity page.
This commit is contained in:
parent
ac14b3eb94
commit
5ca8c9a705
|
@ -1,12 +1,11 @@
|
||||||
export interface Charity {
|
export interface Charity {
|
||||||
id: string
|
id: string
|
||||||
slug: string // Note, slugs double as charity IDs
|
slug: string
|
||||||
name: string
|
name: string
|
||||||
website: string
|
website: string
|
||||||
ein: string
|
ein: string
|
||||||
photo: string
|
photo: string
|
||||||
blurb: string
|
blurb: string
|
||||||
raised?: number
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const charities: Charity[] = [
|
export const charities: Charity[] = [
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
|
import _ from 'lodash'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import { Charity } from '../../../common/charity'
|
import { Charity } from '../../../common/charity'
|
||||||
|
import { useCharityTxns } from '../../hooks/use-charity-txns'
|
||||||
import { Row } from '../layout/row'
|
import { Row } from '../layout/row'
|
||||||
|
|
||||||
export function CharityCard(props: { charity: Charity }) {
|
export function CharityCard(props: { charity: Charity }) {
|
||||||
const { name, slug, photo, raised, blurb } = props.charity
|
const { name, slug, photo, blurb, id } = props.charity
|
||||||
|
|
||||||
|
const txns = useCharityTxns(id)
|
||||||
|
const raised = _.sumBy(txns, (txn) => txn.amount)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Link href={`/charity/${slug}`} passHref>
|
<Link href={`/charity/${slug}`} passHref>
|
||||||
|
|
|
@ -40,6 +40,11 @@ function CharityPage(props: { charity: Charity }) {
|
||||||
|
|
||||||
const txns = useCharityTxns(charity.id)
|
const txns = useCharityTxns(charity.id)
|
||||||
const totalRaised = _.sumBy(txns, (txn) => txn.amount)
|
const totalRaised = _.sumBy(txns, (txn) => txn.amount)
|
||||||
|
const fromYou = _.sumBy(
|
||||||
|
txns.filter((txn) => txn.fromId === user?.id),
|
||||||
|
(txn) => txn.amount
|
||||||
|
)
|
||||||
|
const numSupporters = _.uniqBy(txns, (txn) => txn.fromId).length
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page rightSidebar={<DonationBox user={user} charity={charity} />}>
|
<Page rightSidebar={<DonationBox user={user} charity={charity} />}>
|
||||||
|
@ -51,9 +56,9 @@ function CharityPage(props: { charity: Charity }) {
|
||||||
{photo && <img src={photo} alt="" className="w-40 rounded-2xl" />}
|
{photo && <img src={photo} alt="" className="w-40 rounded-2xl" />}
|
||||||
<Details
|
<Details
|
||||||
charity={charity}
|
charity={charity}
|
||||||
userDonated={4}
|
|
||||||
numSupporters={1}
|
|
||||||
totalRaised={totalRaised}
|
totalRaised={totalRaised}
|
||||||
|
userDonated={fromYou}
|
||||||
|
numSupporters={numSupporters}
|
||||||
/>
|
/>
|
||||||
</Row>
|
</Row>
|
||||||
<h2 className="mt-7 mb-2 text-xl text-indigo-700">About</h2>
|
<h2 className="mt-7 mb-2 text-xl text-indigo-700">About</h2>
|
||||||
|
@ -99,9 +104,9 @@ function Blurb({ text }: { text: string }) {
|
||||||
|
|
||||||
function Details(props: {
|
function Details(props: {
|
||||||
charity: Charity
|
charity: Charity
|
||||||
userDonated?: number
|
|
||||||
numSupporters: number
|
|
||||||
totalRaised: number
|
totalRaised: number
|
||||||
|
userDonated: number
|
||||||
|
numSupporters: number
|
||||||
}) {
|
}) {
|
||||||
const { charity, userDonated, numSupporters, totalRaised } = props
|
const { charity, userDonated, numSupporters, totalRaised } = props
|
||||||
const { website } = charity
|
const { website } = charity
|
||||||
|
@ -110,7 +115,7 @@ function Details(props: {
|
||||||
<div className="text-primary mb-2 text-4xl">
|
<div className="text-primary mb-2 text-4xl">
|
||||||
{manaToUSD(totalRaised ?? 0)} raised
|
{manaToUSD(totalRaised ?? 0)} raised
|
||||||
</div>
|
</div>
|
||||||
{userDonated && (
|
{userDonated > 0 && (
|
||||||
<div className="text-primary text-xl">
|
<div className="text-primary text-xl">
|
||||||
{manaToUSD(userDonated)} from you!
|
{manaToUSD(userDonated)} from you!
|
||||||
</div>
|
</div>
|
||||||
|
@ -139,8 +144,6 @@ function DonationBox(props: { user?: User | null; charity: Charity }) {
|
||||||
setError(undefined)
|
setError(undefined)
|
||||||
await transact({
|
await transact({
|
||||||
amount,
|
amount,
|
||||||
// TODO hardcode in Manifold Markets official account.
|
|
||||||
// Or should we just have it go into a void?
|
|
||||||
fromId: user.id,
|
fromId: user.id,
|
||||||
fromType: 'user',
|
fromType: 'user',
|
||||||
toId: charity.id,
|
toId: charity.id,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user