|
| 1 | +/** |
| 2 | + * Component to render tabs in challenge view page |
| 3 | + */ |
| 4 | +import React, { useState, useMemo } from 'react' |
| 5 | +import PropTypes from 'prop-types' |
| 6 | +import { Tab, Tabs, TabList, TabPanel } from 'react-tabs' |
| 7 | + |
| 8 | +import ChallengeViewComponent from '../ChallengeView' |
| 9 | +import Registrants from '../Registrants' |
| 10 | +import { getResourceRoleByName } from '../../../util/tc' |
| 11 | +import 'react-tabs/style/react-tabs.css' |
| 12 | +import styles from './ChallengeViewTabs.module.scss' |
| 13 | + |
| 14 | +const ChallengeViewTabs = ({ |
| 15 | + projectDetail, |
| 16 | + challenge, |
| 17 | + attachments, |
| 18 | + isBillingAccountExpired, |
| 19 | + metadata, |
| 20 | + challengeResources, |
| 21 | + token, |
| 22 | + isLoading, |
| 23 | + challengeId, |
| 24 | + assignedMemberDetails, |
| 25 | + enableEdit, |
| 26 | + onLaunchChallenge, |
| 27 | + onCloseTask |
| 28 | +}) => { |
| 29 | + const [selectedTab, setSelectedTab] = useState(0) |
| 30 | + |
| 31 | + const registrants = useMemo(() => { |
| 32 | + const { resourceRoles } = metadata |
| 33 | + const role = getResourceRoleByName(resourceRoles, 'Submitter') |
| 34 | + if (role && challengeResources) { |
| 35 | + return challengeResources.filter(resource => resource.roleId === role.id) |
| 36 | + } else { |
| 37 | + return [] |
| 38 | + } |
| 39 | + }, [metadata, challengeResources]) |
| 40 | + |
| 41 | + return ( |
| 42 | + <div className={styles.list}> |
| 43 | + <Tabs |
| 44 | + selectedIndex={selectedTab} |
| 45 | + className={styles.tabsContainer} |
| 46 | + onSelect={index => { |
| 47 | + setSelectedTab(index) |
| 48 | + }} |
| 49 | + > |
| 50 | + <TabList> |
| 51 | + <Tab>DETAILS</Tab> |
| 52 | + <Tab>REGISTRANTS({registrants.length})</Tab> |
| 53 | + </TabList> |
| 54 | + <TabPanel /> |
| 55 | + <TabPanel /> |
| 56 | + <TabPanel /> |
| 57 | + </Tabs> |
| 58 | + {selectedTab === 0 && ( |
| 59 | + <ChallengeViewComponent |
| 60 | + isLoading={isLoading} |
| 61 | + isBillingAccountExpired={isBillingAccountExpired} |
| 62 | + metadata={metadata} |
| 63 | + projectDetail={projectDetail} |
| 64 | + challenge={challenge} |
| 65 | + attachments={attachments} |
| 66 | + challengeResources={challengeResources} |
| 67 | + token={token} |
| 68 | + challengeId={challengeId} |
| 69 | + assignedMemberDetails={assignedMemberDetails} |
| 70 | + enableEdit={enableEdit} |
| 71 | + onLaunchChallenge={onLaunchChallenge} |
| 72 | + onCloseTask={onCloseTask} |
| 73 | + /> |
| 74 | + )} |
| 75 | + {selectedTab === 1 && ( |
| 76 | + <Registrants |
| 77 | + challenge={challenge} |
| 78 | + registrants={registrants} |
| 79 | + /> |
| 80 | + )} |
| 81 | + </div> |
| 82 | + ) |
| 83 | +} |
| 84 | + |
| 85 | +ChallengeViewTabs.defaultProps = { |
| 86 | + projectDetail: {}, |
| 87 | + challenge: {}, |
| 88 | + metadata: {}, |
| 89 | + challengeResources: {}, |
| 90 | + token: '' |
| 91 | +} |
| 92 | + |
| 93 | +ChallengeViewTabs.propTypes = { |
| 94 | + projectDetail: PropTypes.object, |
| 95 | + challenge: PropTypes.object, |
| 96 | + isBillingAccountExpired: PropTypes.bool, |
| 97 | + attachments: PropTypes.array, |
| 98 | + metadata: PropTypes.object, |
| 99 | + token: PropTypes.string, |
| 100 | + isLoading: PropTypes.bool.isRequired, |
| 101 | + challengeId: PropTypes.string.isRequired, |
| 102 | + challengeResources: PropTypes.arrayOf(PropTypes.object), |
| 103 | + assignedMemberDetails: PropTypes.shape(), |
| 104 | + enableEdit: PropTypes.bool, |
| 105 | + onLaunchChallenge: PropTypes.func, |
| 106 | + onCloseTask: PropTypes.func |
| 107 | +} |
| 108 | + |
| 109 | +export default ChallengeViewTabs |
0 commit comments