1
- import React , { FunctionComponent } from 'react' ;
1
+ import React , { FunctionComponent , useState } from 'react' ;
2
2
import fromnow from 'fromnow' ;
3
3
4
4
import { AwardIcon } from '../Icons/common' ;
5
- import { CampaignWithFundings } from '../../services/airtable' ;
5
+ import { CampaignWithFundings , Funding } from '../../services/airtable' ;
6
6
import { truncateString } from '../../utils' ;
7
7
8
8
interface Props {
@@ -11,6 +11,12 @@ interface Props {
11
11
12
12
export const DonorsList : FunctionComponent < Props > = ( { campaign } ) => {
13
13
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
+
14
20
if ( fundings . length === 0 ) {
15
21
return (
16
22
< div className = "bg-white shadow my-4 py-2 rounded-lg px-4" >
@@ -21,27 +27,42 @@ export const DonorsList: FunctionComponent<Props> = ({ campaign }) => {
21
27
</ div >
22
28
) ;
23
29
}
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` ;
24
33
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 justify-center" >
38
+ < li className = "-mb-px mr-1 cursor-pointer whitespace-no-wrap" onClick = { ( ) => setShowRecent ( true ) } >
39
+ < a className = { showRecent ? tabActiveClass : tabClass } > Most Recent</ a >
40
+ </ li >
41
+ < li className = "mr-1 cursor-pointer whitespace-no-wrap" onClick = { ( ) => setShowRecent ( false ) } >
42
+ < a className = { showRecent ? tabClass : tabActiveClass } > Top Contributions</ a >
43
43
</ 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
+ </ >
46
67
) ;
47
68
} ;
1 commit comments
vercel[bot] commentedon Aug 1, 2020
Successfully deployed to the following URLs: