Almost completed appending excel file to existing array

This commit is contained in:
Khalim Conn-Kowlessar 2023-10-13 00:29:37 +08:00
parent c6dec2b56c
commit aa7819136c
2 changed files with 34 additions and 8 deletions

View file

@ -1,6 +1,6 @@
"use client";
import { useMemo, useState } from "react";
import { useState } from "react";
import { SelectFolder } from "../components/due-considerations/SelectFolder";
import { Button } from "../shadcn_components/ui/button";
import { useSession } from "next-auth/react";

View file

@ -1,11 +1,10 @@
"use client";
import { useMemo, useState } from "react";
import { useState } from "react";
import { SelectFolder } from "../components/due-considerations/SelectFolder";
import { Button } from "../shadcn_components/ui/button";
import { useSession } from "next-auth/react";
import { useMutation } from "@tanstack/react-query";
import { Input } from "../shadcn_components/ui/input";
const Spinner = () => {
return (
@ -193,7 +192,7 @@ export default function EcoSpreadsheetHome() {
setUploadMessage("");
} else {
setUploadMessage(
"Please select the .xml, the epr and the ventilation and condition report"
"Please select the xml, the epr and the ventilation and condition report"
);
setButtonDisabled(true);
}
@ -203,6 +202,28 @@ export default function EcoSpreadsheetHome() {
}
}
function handleOnChangeExcel(e: React.ChangeEvent<HTMLInputElement>) {
if (e.target.files && e.target.files.length === 1) {
const ExcelfilesArray = Array.from(e.target.files);
const extensions = ExcelfilesArray.map((file) =>
file.name.split(".").pop()?.toLowerCase()
);
if (extensions.includes("xlsx")) {
// Append the excel onto the existing files
// TODO
setFiles();
setUploadMessage("");
} else {
setUploadMessage("Please select the existing ECO spreadsheet excel");
setButtonDisabled(true);
}
} else {
setUploadMessage("Please select exactly one Excel files");
setButtonDisabled(true);
}
}
return (
<div className="flex flex-col items-center mt-20 tracking-wider leading-loose">
<div className="text-center">
@ -212,10 +233,6 @@ export default function EcoSpreadsheetHome() {
<li>EPR pdf</li>
<li>Ventilation and Condition pdf</li>
</ul>
<div className="mb-4">
Additionally, you can upload an optional ECO spreadsheet if you wish
to add new records to an already populated spreadsheet
</div>
<div className="mb-4">
Make sure these documents all relate to the same property
@ -225,6 +242,15 @@ export default function EcoSpreadsheetHome() {
<SelectFolder handleOnChange={handleOnChange} />
</div>
<div className="mb-4">
Additionally, you can upload an optional ECO Excel spreadsheet if you
wish to add new records to an already populated spreadsheet
</div>
<div className="mb-5">
<SelectFolder handleOnChange={handleOnChangeExcel} />
</div>
<div className="mb-4"></div>
<div className="flex justify-between w-full">