Skip to content

Commit 8aace79

Browse files
committed
Add study right info to points balloon content
1 parent e983d77 commit 8aace79

4 files changed

Lines changed: 39 additions & 9 deletions

File tree

src/components/PointsBalloon/PartProgress.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,20 @@ const PartProgressContainer = styled.div`
66
margin-bottom: 0.5rem;
77
`
88

9+
const SmallP = styled.p`
10+
font-size: 0.8rem;
11+
`
12+
13+
const LargeP = styled.p`
14+
font-size: 1rem;
15+
`
16+
917
const CustomLabel = ({ x, y, stroke, value }) => {
1018
return (
1119
<text
1220
x={x}
1321
y={y}
14-
dy={25}
22+
dy={23}
1523
dx={12}
1624
fill={stroke}
1725
fontSize={10}
@@ -22,7 +30,7 @@ const CustomLabel = ({ x, y, stroke, value }) => {
2230
)
2331
}
2432

25-
const PartProgress = ({ name, data }) => {
33+
const PartProgress = ({ name, data, appliesForStudyRight }) => {
2634
const allChartData = Object.entries(data).map(([tool, data]) => {
2735
return { tool, progress: data.progress * 100 }
2836
})
@@ -58,11 +66,19 @@ const PartProgress = ({ name, data }) => {
5866
/>
5967
</Bar>
6068
</BarChart>
61-
<div>
69+
<LargeP>
6270
Osasta saadut kurssipisteet:{" "}
6371
{Math.floor(Math.min(100, totalProgress * 111.112))}
6472
/100.
65-
</div>
73+
</LargeP>
74+
{appliesForStudyRight && (
75+
<SmallP>
76+
Opinto-oikeuteen vaaditaan 90% ohjelmointitehtävien pisteistä.
77+
Edistymisesi tällä hetkellä:{" "}
78+
{allChartData.find(o => o.tool === "Ohjelmointitehtävät")?.progress}
79+
%.
80+
</SmallP>
81+
)}
6682
</div>
6783
</PartProgressContainer>
6884
)

src/components/PointsBalloon/PointsBalloonContent.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Loading from "../Loading"
66
import { fetchProgress } from "../../services/progress"
77
import PagesContext from "../../contexes/PagesContext"
88
import PartProgress from "./PartProgress"
9+
import { getCachedUserDetails } from "../../services/moocfi"
910

1011
const StyledModal = styled(Modal)`
1112
z-index: 500 !important;
@@ -44,13 +45,17 @@ class PointsBalloonContent extends React.Component {
4445
render: false,
4546
data: null,
4647
error: null,
48+
appliesForStudyRight: null,
4749
}
4850

4951
async componentDidMount() {
5052
this.setState({ render: true })
5153
try {
5254
let data = await fetchProgress(this.context)
53-
this.setState({ data })
55+
let userDetails = await getCachedUserDetails()
56+
const appliesForStudyRight =
57+
userDetails?.extra_fields?.applies_for_study_right === "t"
58+
this.setState({ data, appliesForStudyRight })
5459
} catch (e) {
5560
this.setState({ error: e.toString() })
5661
}
@@ -87,7 +92,13 @@ class PointsBalloonContent extends React.Component {
8792
<div>
8893
{this.state.data &&
8994
Object.entries(this.state.data).map(([name, data]) => {
90-
return <PartProgress name={name} data={data} />
95+
return (
96+
<PartProgress
97+
appliesForStudyRight={this.state.appliesForStudyRight}
98+
name={name}
99+
data={data}
100+
/>
101+
)
91102
})}
92103
</div>
93104
)}

src/components/user/CourseOptionsEditor.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ class CourseOptionsEditor extends React.Component {
4040
first_name: data.user_field?.first_name,
4141
last_name: data.user_field?.last_name,
4242
student_number: data.user_field?.organizational_id,
43-
applies_for_study_right: data.extra_fields?.applies_for_study_right,
44-
digital_education_for_all: data.extra_fields?.digital_education_for_all,
45-
marketing: data.extra_fields?.marketing,
43+
applies_for_study_right:
44+
data.extra_fields?.applies_for_study_right === "t",
45+
digital_education_for_all:
46+
data.extra_fields?.digital_education_for_all === "t",
47+
marketing: data.extra_fields?.marketing === "t",
4648
research: data.extra_fields?.research,
4749
loading: false,
4850
},

src/services/moocfi.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ export async function updateUserDetails({ extraFields, userField }) {
152152
},
153153
{ headers: { Authorization: `Bearer ${accessToken()}` } },
154154
)
155+
store.remove("tmc.user.details")
155156
await userDetails()
156157
return res
157158
}

0 commit comments

Comments
 (0)