Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subjects active status v2 #592

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/AdditionalSubjectsDropDown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ export default {

methods: {
isComplete(includedSubjects) {
// Check if the user has all required certifications for the subject
return includedSubjects.every(subject =>
this.user.subjects.includes(subject.key)
this.user.subjects.some(s => s.subject === subject.key)
);
},
progressStatus(includedSubjects) {
Expand Down
5 changes: 3 additions & 2 deletions src/components/SubjectCertsDropDown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ export default {
return this.user.certifications[cert].passed;
},
hasUnlockedSubject(cert) {
if (cert === "algebra") return this.user.subjects.includes("algebraOne");
return this.user.subjects.includes(cert);
if (cert === "algebra")
return this.user.subjects.some(s => s.subject === "algebraOne");
return this.user.subjects.some(s => s.subject === cert);
},
progressStatus(cert) {
if (this.isComplete(cert)) return "Completed";
Expand Down
4 changes: 3 additions & 1 deletion src/views/DashboardView/VolunteerDashboard/ListSessions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ export default {

if (
Object.keys(allSubtopics()).some(
s => s === subTopic && this.user.subjects.includes(s)
s =>
s === subTopic &&
this.user.subjects.some(({ subject }) => subject === s)
)
) {
results.push(session);
Expand Down
74 changes: 44 additions & 30 deletions src/views/ProfileView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,35 @@
<div class="subheader">Unlocked Subjects</div>
<div class="container-content cert">
<div
v-for="(value, key) in subjects"
:key="`certification-${key}-${value}`"
v-for="{ subject } in user.subjects"
:key="`certification-${subject}`"
>
<div v-if="value" class="certBox">
<div :class="certKey[key]" class="certKey">
{{ certKey[key] }}
<div v-if="subject" class="certBox">
<div>
<span :class="certKey[subject].subjectType" class="certKey">
{{ certKey[subject].subjectType }}
</span>
<span class="certValue">{{
certKey[subject].displayName
}}</span>
</div>
<div class="certValue">{{ key }}</div>
<toggle-button
:value="
modifiedSubjects.some(
s => s.subject === subject && s.isActivated
)
"
:disabled="!activeEdit"
:labels="{ checked: 'Active', unchecked: 'Deactivated' }"
:width="95"
:color="{
checked: '#16D2AA',
unchecked: '#F44747',
disabled: '#AAAAAA'
}"
@change="event => toggleSubjectActivated(event, subject)"
:sync="true"
/>
</div>
</div>
</div>
Expand All @@ -123,7 +144,7 @@
import PhoneNumber from "awesome-phonenumber";
import { mapGetters, mapState } from "vuex";
import UserService from "@/services/UserService";
import { topics, allSubtopics } from "@/utils/topics";
import { topics } from "@/utils/topics";
import DeactivateAccountModal from "./DeactivateAccountModal";

export default {
Expand All @@ -141,10 +162,12 @@ export default {
phoneNational: "",
phoneInputInfo: {},
isAccountActive: true,
showDeactivateAccountModal: false
showDeactivateAccountModal: false,
modifiedSubjects: []
};
},
created() {
this.modifiedSubjects = this.user.subjects;
this.isAccountActive = !this.user.isDeactivated;
if (this.user.isVolunteer && this.user.phone) {
const num =
Expand Down Expand Up @@ -189,26 +212,14 @@ export default {
for (let topic in topicData.subtopics) {
if (topicData.subtopics.hasOwnProperty(topic)) {
const { displayName } = topicData.subtopics[topic];
subtopicObj[displayName] = topicName.toUpperCase();
subtopicObj[topic] = {
subjectType: topicName.toUpperCase(),
displayName
};
}
}
}
return subtopicObj;
},
subjects() {
const user = this.$store.state.user.user;

const subjects = user.subjects.reduce((displayObj, key) => {
const subtopics = allSubtopics();

if (subtopics[key]) {
displayObj[subtopics[key].displayName || subtopics[key]] = true;
}

return displayObj;
}, {});

return subjects;
}
},
methods: {
Expand Down Expand Up @@ -268,11 +279,10 @@ export default {
if (!this.errors.length) {
// form fields valid, so set profile
this.user.phone = this.phoneInputInfo.e164;
this.user.isDeactivated = !this.isAccountActive;

this.user.subjects = this.modifiedSubjects;
// send only the necessary data
const payloadUser = {};
const keys = ["phone", "isDeactivated"];
const keys = ["phone", "isDeactivated", "subjects"];

keys.forEach(key => (payloadUser[key] = this.user[key]));

Expand All @@ -288,6 +298,11 @@ export default {
}
);
}
},
toggleSubjectActivated({ value }, subject) {
for (const s of this.modifiedSubjects) {
if (s.subject === subject) s.isActivated = value;
}
}
}
};
Expand Down Expand Up @@ -485,10 +500,9 @@ button:hover {
}

.certBox {
display: flex;
@include flex-container(row, space-between, center);
height: 60px;
align-items: center;
padding-left: 20px;
padding: 0 20px;
border-top: 1px solid #cccccf;
font-weight: 600;
}
Expand Down