Skip to content

Commit

Permalink
Adding duplicate admin bug fix to hosting branch (#105)
Browse files Browse the repository at this point in the history
* Fix adding duplicate admin bug

* Update order title on exec dashboard
  • Loading branch information
nirmalunc authored Apr 29, 2024
1 parent 1832fb2 commit 308c397
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions src/pages/Admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,9 @@ export default function Admin() {
) {
setEditedIds([...editedIds, editId]);
}

const newData = [...data];
newData[ind] = editedData;
newData[ind] = { ...editedData, id: parseInt(editedData.id, 10) };
setData(newData);
setEditIndex(null);
};
Expand Down Expand Up @@ -326,27 +326,23 @@ export default function Admin() {
};

const handleAdd = () => {
const addId = data[data.length - 1].id + 1;
let addDocId = "";
if (currTab === "Donations") {
addDocId = editedData.orgName;
} else if (currTab === "Executives") {
addDocId = editedData.position;
addDocId = addDocId.replace(/\s+/g, "");
addDocId = addDocId.charAt(0).toLowerCase() + addDocId.slice(1);
// Convert the manually entered ID to a number
const idNumber = parseInt(editedData.id, 10);
addDocId = `exec-${idNumber}`;
} else if (currTab === "Recent Toys" || currTab === "Old Toys") {
addDocId = editedData.name;
addDocId = addDocId.replace(/\s+/g, "").toLowerCase();
}

if (addDocId !== "") {
setAddedIds([...addedIds, addDocId]);
}

const newData = [
...data,
{ ...editedData, id: addId, documentId: addDocId },
];

const newData = [...data, { ...editedData, id: parseInt(editedData.id, 10), documentId: addDocId }];
setData(newData);
setEditIndex(null);
};
Expand Down Expand Up @@ -399,9 +395,9 @@ export default function Admin() {
for (const id in addedIds) {
const newDoc = {
...findDoc(addedIds[id]),
current: currTab === "Recent Toys", // Allow this field to be edited?
current: currTab === "Recent Toys",
donated: 0,
imageName: "", // Add this field to the Admin dashboard?
imageName: "",
inventory: 0,
ordered: 0,
};
Expand All @@ -415,9 +411,6 @@ export default function Admin() {
} else {
for (const id in addedIds) {
const newDoc = findDoc(addedIds[id]);
if (currTab !== "Executives") {
delete newDoc.id;
}
await setDoc(doc(db, dataRef, addedIds[id]), newDoc);
}
if (addedIds.length !== 0) {
Expand All @@ -435,6 +428,9 @@ export default function Admin() {
if (currTab !== "Media" && currTab !== "Executives") {
delete newDoc.id;
}
if (currTab === "Executives") {
newDoc.id = parseInt(newDoc.id, 10);
}
await updateDoc(doc(db, dataRef, editedIds[id]), newDoc);
}
if (editedIds.length !== 0) {
Expand Down Expand Up @@ -834,8 +830,8 @@ export default function Admin() {
function RightView() {
switch (currTab) {
case "Executives":
const execInit = { name: "", position: "", imageID: "" };
const execHeaders = ["Name", "Position", "Image ID (PNG/JPEG)"];
const execInit = { id: "", name: "", position: "", imageID: "" };
const execHeaders = ["# in Order", "Name", "Position", "Image ID (PNG/JPEG)"];
return (
<Table
initial_state={execInit}
Expand Down

0 comments on commit 308c397

Please # to comment.