1+ import { TeamMember , TeamMemberStatus } from '@kaiyuanshe/openhackathon-service' ;
2+ import { Loading } from 'idea-react' ;
3+ import { computed } from 'mobx' ;
14import { observer } from 'mobx-react' ;
25import { ObservedComponent } from 'mobx-react-helper' ;
3- import { ScrollList } from 'mobx-restful-table' ;
6+ import { Column , FormField , RestTable } from 'mobx-restful-table' ;
47import { compose , router } from 'next-ssr-middleware' ;
58
69import {
710 TeamManageBaseParams ,
811 TeamManageBaseProps ,
912 TeamManageFrame ,
1013} from '../../../../../../components/Team/TeamManageFrame' ;
11- import { TeamParticipantTableLayout } from '../../../../../../components/Team/TeamParticipantTable ' ;
14+ import { UserBadge } from '../../../../../../components/User/HackathonAdminList ' ;
1215import activityStore from '../../../../../../models/Activity' ;
1316import { i18n , I18nContext } from '../../../../../../models/Base/Translation' ;
17+ import { convertDatetime } from '../../../../../../utils/time' ;
1418import { sessionGuard } from '../../../../../api/core' ;
1519
20+ const StatusName = ( { t } : typeof i18n ) : Record < TeamMemberStatus , string > => ( {
21+ approved : t ( 'status_approved' ) ,
22+ pendingApproval : t ( 'status_pending' ) ,
23+ } ) ;
24+
1625export const getServerSideProps = compose < TeamManageBaseParams > ( router , sessionGuard ) ;
1726
1827@observer
@@ -26,11 +35,48 @@ export default class TeamParticipantPage extends ObservedComponent<
2635 . teamOf ( this . props . route . params ! . name )
2736 . memberOf ( + this . props . route . params ! . tid ) ;
2837
38+ @computed
39+ get columns ( ) : Column < TeamMember > [ ] {
40+ const i18n = this . observedContext ;
41+ const { t } = i18n ;
42+
43+ return [
44+ { key : 'user' , renderHead : t ( 'user' ) , renderBody : ( { user } ) => < UserBadge { ...user } /> } ,
45+ {
46+ key : 'createdAt' ,
47+ renderHead : t ( 'apply_time' ) ,
48+ renderBody : ( { createdAt } ) => convertDatetime ( createdAt ) ,
49+ } ,
50+ {
51+ key : 'role' ,
52+ renderHead : t ( 'apply_role' ) ,
53+ renderBody : ( { role } ) => ( role === 'admin' ? t ( 'admin' ) : t ( 'member' ) ) ,
54+ } ,
55+ { key : 'description' , renderHead : t ( 'remark' ) } ,
56+ {
57+ key : 'status' ,
58+ renderHead : t ( 'status' ) ,
59+ renderBody : ( { status, user : { id } } ) => (
60+ < FormField
61+ label = { t ( 'status' ) }
62+ options = { Object . entries ( StatusName ( i18n ) ) . map ( ( [ value , label ] ) => ( { value, label } ) ) }
63+ defaultValue = { status }
64+ onChange = { ( { currentTarget : { value } } ) =>
65+ this . store . updateOne ( { status : value as TeamMemberStatus } , id )
66+ }
67+ />
68+ ) ,
69+ } ,
70+ ] ;
71+ }
72+
2973 render ( ) {
30- const { store } = this ,
74+ const { props , store, columns } = this ,
3175 { t } = this . observedContext ;
32- const { resolvedUrl, params } = this . props . route ;
33- const { name, tid } = params ! ;
76+ const { resolvedUrl, params } = props . route ,
77+ { downloading, uploading } = store ;
78+ const { name, tid } = params ! ,
79+ loading = downloading > 0 || uploading > 0 ;
3480
3581 return (
3682 < TeamManageFrame
@@ -40,16 +86,9 @@ export default class TeamParticipantPage extends ObservedComponent<
4086 path = { resolvedUrl }
4187 title = { t ( 'team_registration' ) }
4288 >
43- < ScrollList
44- translator = { i18n }
45- store = { store }
46- renderList = { allItems => (
47- < TeamParticipantTableLayout
48- defaultData = { allItems }
49- onApprove = { ( userId , status ) => store . updateOne ( { status } , userId ) }
50- />
51- ) }
52- />
89+ < RestTable translator = { i18n } { ...{ store, columns } } />
90+
91+ { loading && < Loading /> }
5392 </ TeamManageFrame >
5493 ) ;
5594 }
0 commit comments