1- import React , { FunctionComponent } from 'react' ;
1+ import React , { FunctionComponent , useState } from 'react' ;
22import fromnow from 'fromnow' ;
33
44import { AwardIcon } from '../Icons/common' ;
5- import { CampaignWithFundings } from '../../services/airtable' ;
5+ import { CampaignWithFundings , Funding } from '../../services/airtable' ;
66import { truncateString } from '../../utils' ;
77
88interface Props {
@@ -11,6 +11,12 @@ interface Props {
1111
1212export const DonorsList : FunctionComponent < Props > = ( { campaign } ) => {
1313 const { fundings } = campaign ;
14+ const [ showRecent , setShowRecent ] = useState ( true ) ;
15+ const sortedFundings = ( ) =>
16+ showRecent
17+ ? fundings . sort ( ( a , b ) => + new Date ( b . created_at ) - + new Date ( a . created_at ) )
18+ : fundings . sort ( ( a , b ) => b . donated_amount - a . donated_amount ) ;
19+
1420 if ( fundings . length === 0 ) {
1521 return (
1622 < div className = "bg-white shadow my-4 py-2 rounded-lg px-4" >
@@ -21,27 +27,42 @@ export const DonorsList: FunctionComponent<Props> = ({ campaign }) => {
2127 </ div >
2228 ) ;
2329 }
30+ const tabCommonClass = 'bg-white inline-block py-2 px-4 hover:text-pink-800 font-semibold' ;
31+ const tabClass = `${ tabCommonClass } text-pink-500` ;
32+ const tabActiveClass = `${ tabCommonClass } text-pink-700 border-b border-pink-500` ;
2433 return (
25- < ul className = "w-full overflow-y-scroll" style = { { height : 500 } } >
26- { fundings . map ( item => (
27- < li key = { item . id } className = "flex items-center bg-white shadow my-4 py-2 rounded-lg" >
28- < div className = "px-4" >
29- < AwardIcon />
30- </ div >
31- < div className = "flex-1" >
32- < h6 className = "font-medium text-gray-800" title = { item . name } >
33- { truncateString ( item . name , 15 ) }
34- </ h6 >
35- < p className = "text-xs text-gray-600" > { fromnow ( new Date ( item . created_at ) , { max : 2 , suffix : true } ) } </ p >
36- < p className = "text-xs text-gray-600" > { item . message } </ p >
37- </ div >
38- < div className = "px-4" >
39- < span className = "inline-block bg-green-600 text-xs rounded-full px-3 py-1 text-white" >
40- ₹ { item . donated_amount }
41- </ span >
42- </ div >
34+ < >
35+ < h2 className = "text-xl mb-1 font-medium text-gray-800" > Contributions</ h2 >
36+ < p className = "text-sm text-gray-700" > A special thanks to all who raised the funds for this campaign.</ p >
37+ < ul className = "flex border-b mt-2" >
38+ < li className = "-mb-px mr-1 cursor-pointer" onClick = { ( ) => setShowRecent ( true ) } >
39+ < a className = { showRecent ? tabActiveClass : tabClass } > Most Recent</ a >
40+ </ li >
41+ < li className = "mr-1 cursor-pointer" onClick = { ( ) => setShowRecent ( false ) } >
42+ < a className = { showRecent ? tabClass : tabActiveClass } > Top Contributions</ a >
4343 </ li >
44- ) ) }
45- </ ul >
44+ </ ul >
45+ < ul className = "w-full overflow-y-scroll" style = { { height : 500 } } >
46+ { sortedFundings ( ) . map ( item => (
47+ < li key = { item . id } className = "flex items-center bg-white shadow my-4 py-2 rounded-lg" >
48+ < div className = "px-4 text-center" >
49+ < AwardIcon />
50+ </ div >
51+ < div className = "flex-1" >
52+ < h6 className = "font-medium text-gray-800" title = { item . name } >
53+ { truncateString ( item . name , 15 ) }
54+ </ h6 >
55+ < p className = "text-xs text-gray-600" > { fromnow ( new Date ( item . created_at ) , { max : 2 , suffix : true } ) } </ p >
56+ < p className = "text-xs text-gray-600" > { item . message } </ p >
57+ </ div >
58+ < div className = "px-4" >
59+ < span className = "inline-block bg-pink-600 text-xs rounded-full px-3 py-1 text-white" >
60+ ₹ { item . donated_amount }
61+ </ span >
62+ </ div >
63+ </ li >
64+ ) ) }
65+ </ ul >
66+ </ >
4667 ) ;
4768} ;
0 commit comments