Skip to content

Commit

Permalink
πŸ§‘πŸΎβ€πŸŽ€ Fix issue #839 (#840)
Browse files Browse the repository at this point in the history
* Fix issue #839

#839

* remove comment
  • Loading branch information
SolMon9099 authored Dec 7, 2023
1 parent c858689 commit dd2d3e8
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 124 deletions.
1 change: 1 addition & 0 deletions backend/api/views/appointment.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ def get_mentors_appointments():
{
"name": mentor.name,
"id": str(mentor.id),
"image": mentor.image,
"appointments": mentor_appts,
"numOfAppointments": len(mentor_appts),
"appointmentsAvailable": "Yes"
Expand Down
73 changes: 22 additions & 51 deletions frontend/src/components/AdminDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ function AdminDataTable({
data = newData;
}
const [accounts, setAccounts] = useState([]);
const [mentorAccounts, setMentorAccounts] = useState([]);
const [loading, setLoading] = useState(false);
const [isModalVisible, setIsModalVisible] = useState(false);
const [selectedPartner, setSelectedPartner] = useState(null);
Expand All @@ -87,19 +86,6 @@ function AdminDataTable({
);
}
}, [data]);
useEffect(() => {
if (
mentors &&
(mentors.length !== mentorAccounts.length ||
(mentors.length > 0 && mentors[0].id !== mentorAccounts[0].id))
) {
setMentorAccounts(
mentors.map((d) => {
return { id: d._id.$oid, image: d.image ? d.image : null };
})
);
}
}, [mentors]);

useEffect(() => {
if (selectedPartner !== null) {
Expand All @@ -115,6 +101,12 @@ function AdminDataTable({
}
return false;
});
if (selectedPartner.assign_mentors) {
assign_mentors = [...assign_mentors, ...selectedPartner.assign_mentors];
}
if (selectedPartner.assign_mentees) {
assign_mentees = [...assign_mentees, ...selectedPartner.assign_mentees];
}
mentors.map((item) => {
var record = assign_mentors.find((x) => x.id === item._id["$oid"]);
if (record === null || record === undefined) {
Expand All @@ -125,9 +117,9 @@ function AdminDataTable({
setMentorArr(temp);
temp = [];
mentees.map((item) => {
var record = assign_mentees.find((x) => x.id === item.id);
var record = assign_mentees.find((x) => x.id === item._id["$oid"]);
if (record === null || record === undefined) {
temp.push({ id: item.id, name: item.name });
temp.push({ id: item._id["$oid"], name: item.name });
}
return false;
});
Expand Down Expand Up @@ -227,7 +219,7 @@ function AdminDataTable({
selected_partner.assign_mentees = [];
}
selectedMentees.map((mentee_id) => {
var mentee_record = mentees.find((x) => x.id === mentee_id);
var mentee_record = mentees.find((x) => x._id.$oid === mentee_id);
if (mentee_record !== null && mentee_record !== undefined) {
selected_partner.assign_mentees.push({
id: mentee_id,
Expand Down Expand Up @@ -653,11 +645,7 @@ function AdminDataTable({
size={30}
icon={<UserOutlined />}
className="modal-profile-icon2"
src={
data.profilePicUp
? mentorAccounts.find((m) => m.id === id)?.image?.url
: accounts.find((acc) => acc.id === id)?.image?.url
}
src={accounts.find((acc) => acc.id === id)?.image?.url}
/>
)}

Expand Down Expand Up @@ -685,35 +673,18 @@ function AdminDataTable({
ACCOUNT_TYPE.MENTOR
);
}
if (data.profilePicUp) {
setMentorAccounts((prev) => {
let newAccounts = [...prev];
let index = accounts.findIndex((a) => a.id == id);
newAccounts[index] = {
id: id,
image: {
url: URL.createObjectURL(
file.file.originFileObj
),
},
};
return newAccounts;
});
} else {
setAccounts((prev) => {
let newAccounts = [...prev];
let index = accounts.findIndex((a) => a.id == id);
newAccounts[index] = {
id: id,
image: {
url: URL.createObjectURL(
file.file.originFileObj
),
},
};
return newAccounts;
});
}

setAccounts((prev) => {
let newAccounts = [...prev];
let index = accounts.findIndex((a) => a.id === id);
newAccounts[index] = {
id: id,
image: {
url: URL.createObjectURL(file.file.originFileObj),
},
};
return newAccounts;
});

setLoading(false);
}}
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/components/AdminDropdowns.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ export function MenteeMentorDropdown(props) {
key: 4,
text: "Guests",
},
ALL: {
key: 3,
text: "All",
},
// ALL: {
// key: 3,
// text: "All",
// },
};

const [option, setOption] = useState(options.MENTORS);
Expand Down Expand Up @@ -95,9 +95,9 @@ export function MenteeMentorDropdown(props) {
<Menu.Item>
<a onClick={() => handleClick(options.GUESTS)}>Guests</a>
</Menu.Item>
<Menu.Item>
{/* <Menu.Item>
<a onClick={() => handleClick(options.ALL)}>All</a>
</Menu.Item>
</Menu.Item> */}
</Menu>
);
return (
Expand Down
122 changes: 55 additions & 67 deletions frontend/src/components/pages/AdminAccountData.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const keys = {
MENTORS: 0,
MENTEES: 1,
PARTNER: 2,
ALL: 3,
// ALL: 3,
GUEST: 4,
ASCENDING: 0,
DESCENDING: 1,
Expand All @@ -39,71 +39,76 @@ function AdminAccountData() {
const [isMenteeDownload, setIsMenteeDownload] = useState(false);
const [isPartnerDownload, setIsPartnerDownload] = useState(false);
const [reload, setReload] = useState(true);
const [resetFilters, setResetFilters] = useState(false);
const [mentorData, setMentorData] = useState([]);
const [menteeData, setMenteeData] = useState([]);
const [displayData, setDisplayData] = useState([]);
const [displayOption, setDisplayOption] = useState(keys.MENTORS);
const [filterData, setFilterData] = useState([]);
const [downloadFile, setDownloadFile] = useState(null);
const [uploadModalVisible, setUploadModalVisible] = useState(false);
const [guestModalVisible, setGuestModalVisible] = useState(false);
const [partnerData, setPartnerData] = useState([]);
const [guestData, setGuestData] = useState([]);
const [mentors, setMentors] = useState([]);
const [mentees, setMentees] = useState([]);

const { onAuthStateChanged } = useAuth();

useEffect(() => {
async function getData() {
setIsReloading(true);
const mentorRes = await fetchMentorsAppointments();
const mentors = await fetchAccounts(ACCOUNT_TYPE.MENTOR);
const menteeRes = await fetchMenteesAppointments();
const Partners = await fetchAccounts(ACCOUNT_TYPE.PARTNER);
const Guests = await fetchAccounts(ACCOUNT_TYPE.GUEST);
var partners_data = [];
if (Partners) {
Partners.map((item) => {
item.restricted_show = item.restricted ? "Yes" : "No";
item.mentor_nums = item.assign_mentors
? item.assign_mentors.length
: 0;
item.mentee_nums = item.assign_mentees
? item.assign_mentees.length
: 0;
partners_data.push(item);
return true;
});
}
if (mentorRes && menteeRes) {
const newMenteeData = menteeRes.menteeData.map((elem) => ({
...elem,
isMentee: true,
}));

setMentorData(mentorRes.mentorData);
setMenteeData(newMenteeData);
setPartnerData(partners_data);
setGuestData(Guests);
setDisplayData(mentorRes.mentorData);
setFilterData(mentorRes.mentorData);
if (displayOption === keys.MENTEES) {
setDisplayData(newMenteeData);
setFilterData(newMenteeData);
}
if (displayOption === keys.PARTNER) {
switch (displayOption) {
case keys.MENTEES:
const menteeRes = await fetchMenteesAppointments();
if (menteeRes) {
const newMenteeData = menteeRes.menteeData.map((elem) => ({
...elem,
isMentee: true,
}));
setDisplayData(newMenteeData);
setFilterData(newMenteeData);
} else {
message.error("Could not fetch account data");
}
break;
case keys.MENTORS:
const mentorRes = await fetchMentorsAppointments();
if (mentorRes) {
setDisplayData(mentorRes.mentorData);
setFilterData(mentorRes.mentorData);
} else {
message.error("Could not fetch account data");
}
break;
case keys.PARTNER:
const Partners = await fetchAccounts(ACCOUNT_TYPE.PARTNER);
var partners_data = [];
if (Partners) {
Partners.map((item) => {
item.restricted_show = item.restricted ? "Yes" : "No";
item.mentor_nums = item.assign_mentors
? item.assign_mentors.length
: 0;
item.mentee_nums = item.assign_mentees
? item.assign_mentees.length
: 0;
partners_data.push(item);
return true;
});
}
const mentors = await fetchAccounts(ACCOUNT_TYPE.MENTOR);
setMentors(mentors);
const mentees = await fetchAccounts(ACCOUNT_TYPE.MENTEE);
setMentees(mentees);

setDisplayData(partners_data);
setFilterData(partners_data);
}
if (displayOption === keys.GUEST) {
break;
case keys.GUEST:
const Guests = await fetchAccounts(ACCOUNT_TYPE.GUEST);

setDisplayData(Guests);
setFilterData(Guests);
}
// setResetFilters(!resetFilters);
setMentors(mentors);
} else {
message.error("Could not fetch account data");
break;
default:
break;
}
setIsReloading(false);
}
Expand Down Expand Up @@ -167,22 +172,8 @@ function AdminAccountData() {
};

const handleAccountDisplay = (key) => {
let newData = [];
if (key === keys.MENTORS) {
newData = mentorData;
} else if (key === keys.MENTEES) {
newData = menteeData;
} else if (key === keys.ALL) {
newData = mentorData.concat(menteeData);
} else if (key === keys.PARTNER) {
newData = partnerData;
} else if (key === keys.GUEST) {
newData = guestData;
}

setDisplayData(newData);
setFilterData(newData);
setDisplayOption(key);
setReload(!reload);
};

const handleSearchAccount = (name) => {
Expand Down Expand Up @@ -239,12 +230,10 @@ function AdminAccountData() {
<MenteeMentorDropdown
className="table-button"
onChange={(key) => handleAccountDisplay(key)}
onReset={resetFilters}
/>
<SortByApptDropdown
className="table-button"
onChange={(key) => handleSortData(key)}
onReset={resetFilters}
onChangeData={displayData}
/>
<Button
Expand Down Expand Up @@ -300,7 +289,6 @@ function AdminAccountData() {
spin={isReloading}
onClick={() => {
setReload(!reload);
// setResetFilters(!resetFilters);
}}
/>
</div>
Expand All @@ -314,7 +302,7 @@ function AdminAccountData() {
isPartner={displayOption === keys.PARTNER}
isGuest={displayOption === keys.GUEST}
mentors={mentors}
mentees={menteeData}
mentees={mentees}
/>
</Spin>
</div>
Expand Down

0 comments on commit dd2d3e8

Please sign in to comment.