import React, { useState } from 'react'; import { motion } from 'framer-motion'; import toast from 'react-hot-toast'; import type { EventRequestFormData } from './EventRequestForm'; import InvoiceBuilder from './InvoiceBuilder'; import type { InvoiceData } from './InvoiceBuilder'; // Animation variants const itemVariants = { hidden: { opacity: 0, y: 20 }, visible: { opacity: 1, y: 0, transition: { type: "spring", stiffness: 300, damping: 24 } } }; interface ASFundingSectionProps { formData: EventRequestFormData; onDataChange: (data: Partial) => void; } const ASFundingSection: React.FC = ({ formData, onDataChange }) => { const [invoiceFile, setInvoiceFile] = useState(formData.invoice); const [invoiceFiles, setInvoiceFiles] = useState(formData.invoice_files || []); // Handle single invoice file upload (for backward compatibility) const handleInvoiceFileChange = (e: React.ChangeEvent) => { if (e.target.files && e.target.files.length > 0) { const file = e.target.files[0]; setInvoiceFile(file); onDataChange({ invoice: file }); } }; // Handle multiple invoice files upload const handleMultipleInvoiceFilesChange = (e: React.ChangeEvent) => { if (e.target.files && e.target.files.length > 0) { const files = Array.from(e.target.files); // Check file sizes const MAX_FILE_SIZE = 10 * 1024 * 1024; // 10MB limit per file const oversizedFiles = files.filter(file => file.size > MAX_FILE_SIZE); if (oversizedFiles.length > 0) { toast.error(`Some files exceed the 10MB size limit: ${oversizedFiles.map(f => f.name).join(', ')}`); return; } // Update state with new files const updatedFiles = [...invoiceFiles, ...files]; setInvoiceFiles(updatedFiles); onDataChange({ invoice_files: updatedFiles }); // Also set the first file as the main invoice file for backward compatibility if (files.length > 0 && !formData.invoice) { setInvoiceFile(files[0]); onDataChange({ invoice: files[0] }); } toast.success(`Added ${files.length} file${files.length > 1 ? 's' : ''} successfully`); } }; // Remove an invoice file const handleRemoveInvoiceFile = (index: number) => { const updatedFiles = [...invoiceFiles]; const removedFileName = updatedFiles[index].name; updatedFiles.splice(index, 1); setInvoiceFiles(updatedFiles); onDataChange({ invoice_files: updatedFiles }); // Update the main invoice file if needed if (invoiceFile && invoiceFile.name === removedFileName) { const newMainFile = updatedFiles.length > 0 ? updatedFiles[0] : null; setInvoiceFile(newMainFile); onDataChange({ invoice: newMainFile }); } toast.success(`Removed ${removedFileName}`); }; // Handle invoice data change const handleInvoiceDataChange = (invoiceData: InvoiceData) => { // Update the invoiceData in the form onDataChange({ invoiceData }); // For backward compatibility, create a properly formatted JSON string const jsonFormat = { items: invoiceData.items.map(item => ({ item: item.description, quantity: item.quantity, unit_price: item.unitPrice })), tax: invoiceData.taxAmount, tip: invoiceData.tipAmount, total: invoiceData.total, vendor: invoiceData.vendor }; // For backward compatibility, still update the itemized_invoice field // but with a more structured format that's easier to parse if needed const itemizedText = JSON.stringify(jsonFormat, null, 2); // Update the itemized_invoice field for backward compatibility onDataChange({ itemized_invoice: itemizedText }); }; return (

AS Funding Information

Please make sure the restaurant is a valid AS Funding food vendor! An invoice can be an unofficial receipt. Just make sure that the restaurant name and location, desired pickup or delivery date and time, all the items ordered plus their prices, discount/fees/tax/tip, and total are on the invoice! We don't recommend paying out of pocket because reimbursements can be a hassle when you're not a Principal Member.

{/* Invoice Builder Instructions */}

How to Use the Invoice Builder

  1. Enter the vendor/restaurant name in the field provided.
  2. Add each item from your invoice by filling in the description, quantity, and unit price, then click "Add Item".
  3. The subtotal, tax, and tip will be calculated automatically based on the tax rate and tip percentage.
  4. You can adjust the tax rate (default is 7.75% for San Diego) and tip percentage as needed.
  5. Remove items by clicking the "X" button next to each item.
  6. Upload your actual invoice file (receipt, screenshot, etc.) using the file upload below.

Note: The invoice builder helps you itemize your expenses for AS funding. You must still upload the actual invoice file.

{/* Invoice Builder */} {/* Invoice file upload */} {invoiceFiles.length > 0 && (

Uploaded files:

{invoiceFiles.map((file, index) => (
{file.name}
))}
)}

Official food invoices will be required 2 weeks before the start of your event. Please use the following naming format: EventName_OrderLocation_DateOfEvent (i.e. QPWorkathon#1_PapaJohns_01/06/2025)

Important Note

AS Funding requests must be submitted at least 6 weeks before your event. Please check the Funding Guide or the Google Calendar for the funding request deadlines.
); }; export default ASFundingSection;