-
-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move endorsement modal to Profile page (#2283)
- Loading branch information
Showing
6 changed files
with
138 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,134 +1,129 @@ | ||
import * as React from 'react'; | ||
import isEqual from 'lodash/isEqual'; | ||
import { useMemo, useState } from 'react'; | ||
import { List, Typography, Button, Tag } from 'antd'; | ||
import CommonCard from './CommonCard'; | ||
import MentorStatsModal from './MentorStatsModal'; | ||
import { MentorStats, Student } from 'common/models/profile'; | ||
import { TeamOutlined, FullscreenOutlined } from '@ant-design/icons'; | ||
import { TeamOutlined, FullscreenOutlined, FileTextOutlined } from '@ant-design/icons'; | ||
import { MentorEndorsement } from 'modules/Profile/components/MentorEndorsement'; | ||
|
||
const { Text } = Typography; | ||
|
||
type Props = { | ||
isAdmin?: boolean; | ||
githubId: string; | ||
data: MentorStats[]; | ||
}; | ||
|
||
type State = { | ||
courseIndex: number; | ||
isMentorStatsModalVisible: boolean; | ||
}; | ||
|
||
class MentorStatsCard extends React.Component<Props, State> { | ||
state = { | ||
courseIndex: 0, | ||
isMentorStatsModalVisible: false, | ||
}; | ||
export function MentorStatsCard(props: Props) { | ||
const [courseIndex, setCourseIndex] = useState(0); | ||
const [isMentorStatsModalVisible, setIsMentorStatsModalVisible] = useState(false); | ||
const [isEndorsmentModalVisible, setIsEndorsmentModalVisible] = useState(false); | ||
|
||
private showMentorStatsModal = (courseIndex: number) => { | ||
this.setState({ courseIndex, isMentorStatsModalVisible: true }); | ||
const showMentorStatsModal = (courseIndex: number) => { | ||
setCourseIndex(courseIndex); | ||
setIsMentorStatsModalVisible(true); | ||
}; | ||
|
||
private hideMentortStatsModal = () => { | ||
this.setState({ isMentorStatsModalVisible: false }); | ||
const hideMentortStatsModal = () => { | ||
setIsMentorStatsModalVisible(false); | ||
}; | ||
|
||
private countStudents = (data: MentorStats[]) => | ||
data.reduce((acc: Student[], cur: MentorStats) => (cur?.students?.length ? acc.concat(cur.students) : acc), []) | ||
.length; | ||
const stats = props.data; | ||
const count = useMemo( | ||
() => props.data.reduce<Student[]>((acc, cur) => acc.concat(cur.students ?? []), []).length, | ||
[], | ||
); | ||
|
||
shouldComponentUpdate = (_nextProps: Props, nextState: State) => | ||
!isEqual(nextState.isMentorStatsModalVisible, this.state.isMentorStatsModalVisible); | ||
|
||
render() { | ||
const stats = this.props.data; | ||
const { courseIndex, isMentorStatsModalVisible } = this.state; | ||
|
||
return ( | ||
<> | ||
<MentorStatsModal | ||
stats={stats[courseIndex]} | ||
isVisible={isMentorStatsModalVisible} | ||
onHide={this.hideMentortStatsModal} | ||
/> | ||
<CommonCard | ||
title="Mentor Statistics" | ||
icon={<TeamOutlined />} | ||
content={ | ||
<> | ||
<div> | ||
<p> | ||
Mentored Students:{' '} | ||
<Text style={{ fontSize: 18 }} strong> | ||
{this.countStudents(stats)} | ||
</Text> | ||
</p> | ||
<p> | ||
Courses as Mentor:{' '} | ||
<Text style={{ fontSize: 18 }} strong> | ||
{stats.length} | ||
</Text> | ||
</p> | ||
</div> | ||
<List | ||
itemLayout="horizontal" | ||
dataSource={stats} | ||
renderItem={({ courseName, courseLocationName, students }, idx) => ( | ||
<List.Item style={{ display: 'flex', justifyContent: 'space-between' }}> | ||
<div style={{ flexGrow: 2 }}> | ||
<p style={{ fontSize: idx === 0 ? 20 : undefined, marginBottom: 5 }}> | ||
<Text strong> | ||
{courseName} | ||
{courseLocationName && ` / ${courseLocationName}`} | ||
</Text> | ||
</p> | ||
{students ? ( | ||
idx === 0 && ( | ||
<List | ||
itemLayout="horizontal" | ||
dataSource={students} | ||
renderItem={({ githubId, name, isExpelled, totalScore }) => ( | ||
<List.Item style={{ display: 'flex', justifyContent: 'space-between' }}> | ||
<div key={`mentor-students-${githubId} ${courseName}`} style={{ width: '100%' }}> | ||
<p | ||
style={{ | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
fontSize: 12, | ||
marginBottom: 5, | ||
}} | ||
> | ||
<a href={`/profile?githubId=${githubId}`}>{name}</a>{' '} | ||
{isExpelled ? <Tag color="red">expelled</Tag> : <Tag color="green">active</Tag>} | ||
</p> | ||
<p style={{ fontSize: 12, marginBottom: 0 }}> | ||
Score: <Text mark>{totalScore}</Text> | ||
</p> | ||
</div> | ||
</List.Item> | ||
)} | ||
/> | ||
) | ||
) : ( | ||
<p>Does not have students at this course yet</p> | ||
)} | ||
</div> | ||
{students && ( | ||
<Button | ||
style={{ marginLeft: 16 }} | ||
type="dashed" | ||
onClick={this.showMentorStatsModal.bind(null, idx)} | ||
> | ||
<FullscreenOutlined /> | ||
</Button> | ||
return ( | ||
<> | ||
<MentorStatsModal | ||
stats={stats[courseIndex]} | ||
isVisible={isMentorStatsModalVisible} | ||
onHide={hideMentortStatsModal} | ||
/> | ||
<MentorEndorsement | ||
onClose={() => setIsEndorsmentModalVisible(false)} | ||
open={isEndorsmentModalVisible} | ||
githubId={props.githubId} | ||
/> | ||
<CommonCard | ||
title="Mentor Statistics" | ||
icon={<TeamOutlined />} | ||
content={ | ||
<> | ||
<div> | ||
<p> | ||
Mentored Students:{' '} | ||
<Text style={{ fontSize: 18 }} strong> | ||
{count} | ||
</Text> | ||
</p> | ||
<p> | ||
Courses as Mentor:{' '} | ||
<Text style={{ fontSize: 18 }} strong> | ||
{stats.length} | ||
</Text> | ||
</p> | ||
</div> | ||
{props.isAdmin ? ( | ||
<Button onClick={() => setIsEndorsmentModalVisible(true)} icon={<FileTextOutlined />} size="small"> | ||
Get Endorsment | ||
</Button> | ||
) : null} | ||
<List | ||
itemLayout="horizontal" | ||
dataSource={stats} | ||
renderItem={({ courseName, courseLocationName, students }, idx) => ( | ||
<List.Item style={{ display: 'flex', justifyContent: 'space-between' }}> | ||
<div style={{ flexGrow: 2 }}> | ||
<p style={{ fontSize: idx === 0 ? 20 : undefined, marginBottom: 5 }}> | ||
<Text strong> | ||
{courseName} | ||
{courseLocationName && ` / ${courseLocationName}`} | ||
</Text> | ||
</p> | ||
{students ? ( | ||
idx === 0 && ( | ||
<List | ||
itemLayout="horizontal" | ||
dataSource={students} | ||
renderItem={({ githubId, name, isExpelled, totalScore }) => ( | ||
<List.Item style={{ display: 'flex', justifyContent: 'space-between' }}> | ||
<div key={`mentor-students-${githubId} ${courseName}`} style={{ width: '100%' }}> | ||
<p | ||
style={{ | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
fontSize: 12, | ||
marginBottom: 5, | ||
}} | ||
> | ||
<a href={`/profile?githubId=${githubId}`}>{name}</a>{' '} | ||
{isExpelled ? <Tag color="red">expelled</Tag> : <Tag color="green">active</Tag>} | ||
</p> | ||
<p style={{ fontSize: 12, marginBottom: 0 }}> | ||
Score: <Text mark>{totalScore}</Text> | ||
</p> | ||
</div> | ||
</List.Item> | ||
)} | ||
/> | ||
) | ||
) : ( | ||
<p>Does not have students at this course yet</p> | ||
)} | ||
</List.Item> | ||
)} | ||
/> | ||
</> | ||
} | ||
/> | ||
</> | ||
); | ||
} | ||
</div> | ||
{students && ( | ||
<Button style={{ marginLeft: 16 }} type="dashed" onClick={showMentorStatsModal.bind(null, idx)}> | ||
<FullscreenOutlined /> | ||
</Button> | ||
)} | ||
</List.Item> | ||
)} | ||
/> | ||
</> | ||
} | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
export default MentorStatsCard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters