Upload Modal - Zanegerous/CopperToGold GitHub Wiki

This modal formats and stores a draft that is to be sent to ebay

const UploadDraftModal = ({ visible, onClose, itemName, itemPrice, itemCondition, itemImage }: UploadDraftModalProps) =

Visisble controls the modal visibility onClose turns the modal off

ItemName is the title of the reference item Price references the price condition references the conditions image is the previous image

This uploads the stuff from the modal

export const uploadDraft = async (title: string, description: string, condition: string, price: string, sku: string, imageurl: string[], quantity: string) => { const database = getDatabase(); const user = auth.currentUser; const userUID = user!.uid; const time = new Date(); const formattedTime = time.toISOString().replace(/[:.-]/g, ""); const saveRef =users/${userUID}/draftListing/${time}`; const itemRef = dbRef(database, saveRef); const userLevel = await getUserLevel();

if (userLevel == "admin") { try { const draftData = { title, description, condition, price, sku, imageurl, quantity, };

  await set(itemRef, draftData);
  alert('Upload Success');
  console.log("Draft uploaded successfully.");
  return true;
} catch (error) {
  console.error("Failed to upload draft:", error);
  throw new Error("Draft upload failed.");
}

} else { alert(Not High Enough Security); return true; } }

`