diff --git a/src/app/components/portfolio/UploadCsvModal.tsx b/src/app/components/portfolio/UploadCsvModal.tsx index bdf68ee..cf5410e 100644 --- a/src/app/components/portfolio/UploadCsvModal.tsx +++ b/src/app/components/portfolio/UploadCsvModal.tsx @@ -72,11 +72,37 @@ export const SubmitPlan = ({ ); }; -export function InputFile() { +export function InputFile({ + handleButtonDisabled, + setCsvFile, + selectedGoal, + fundingScheme, + goalValue, +}: { + handleButtonDisabled: ( + goal?: string, + scheme?: string, + value?: string, + file?: File | null + ) => void; + setCsvFile: (file: File) => void; + selectedGoal: string; + fundingScheme: string; + goalValue: string; +}) { return (
- + { + const file = event.target.files[0]; + setCsvFile(file); // Assuming you have a state to keep the file + handleButtonDisabled(selectedGoal, fundingScheme, goalValue, file); + }} + />
); } @@ -210,6 +236,12 @@ export default function UploadCsvModal({ const [fundingScheme, setFundingScheme] = useState(""); const [goalValue, setGoalValue] = useState(""); + const [csvFile, setCsvFile] = useState(null); + + function handleFileChange(e: React.ChangeEvent) { + setCsvFile(e.target.files ? e.target.files[0] : null); + } + function handleBudgeChange(e: React.ChangeEvent) { setBudget(e.target.valueAsNumber); } @@ -217,7 +249,8 @@ export default function UploadCsvModal({ function handleButtonDisabled( goal?: string, scheme?: string, - value?: string + value?: string, + file?: File | null ) { // This function is defined as such to accomodate for the asynchonous nature of state setting // The first time this is called, the setState function will be run before this but the state value @@ -225,7 +258,8 @@ export default function UploadCsvModal({ if ( (goal || selectedGoal) && (scheme || fundingScheme) && - (value || goalValue) + (value || goalValue) && + (file || csvFile) ) { setButtonDisabled(false); } @@ -283,19 +317,25 @@ export default function UploadCsvModal({ Budget * -

+

If you don't set a budget, we will aim to minimise cost anyway

- handleBudgeChange(e)} - className="p-2 border border-gray-200 rounded-md focus:outline-none bg-gray-100" - /> +
+ £ + handleBudgeChange(e)} + onKeyDown={(e) => + (e.key === "e" || e.key === "E") && e.preventDefault() + } + className="p-2 focus:outline-none bg-transparent w-full" + /> +
@@ -314,7 +354,8 @@ export default function UploadCsvModal({ handleButtonDisabled( selectedGoal, option.value, - goalValue + goalValue, + csvFile ); }} /> @@ -333,7 +374,8 @@ export default function UploadCsvModal({ handleButtonDisabled( option.value, fundingScheme, - goalValue + goalValue, + csvFile ); }} /> @@ -354,7 +396,8 @@ export default function UploadCsvModal({ handleButtonDisabled( selectedGoal, fundingScheme, - option.value + option.value, + csvFile ); }} /> @@ -364,7 +407,13 @@ export default function UploadCsvModal({
- +