This commit is contained in:
Kenneth Jannette
2024-02-24 02:14:39 -06:00
parent 2d30b4e5b8
commit 89bb3fbe26
3 changed files with 49 additions and 11 deletions

View File

@@ -32,7 +32,8 @@ const UploadModal = (props) => {
const [fileToUpload, setFileToUpload] = useState();
const [fileToParse, setFileToParse] = useState("");
const [fileChanged, setFileChanged] = useState();
const [radioValue, setRadioValue] = useState("");
const [radioValue, setRadioValue] = useState(null);
const [radioValueError, setRadioValueError] = useState("");
const [showFileDetails, setShowFileDetails] = useState("");
const [titleError, setShowTitleError] = useState("");
const [docError, setShowDocError] = useState("");
@@ -43,11 +44,12 @@ const UploadModal = (props) => {
process.env.NODE_ENV === "development"
? process.env.REACT_APP_API_DEV
: process.env.REACT_APP_API_PROD;
const radioOptions = [
{
name: "Discovery request",
label: "Discovery request",
value: "discoveryRequest",
value: "discovery-request",
},
{ name: "Complaint", label: "Complaint", value: "complaint" },
];
@@ -84,15 +86,24 @@ const UploadModal = (props) => {
setFileToParse(file);
setFileChanged(true);
}
console.log("full request url:", `${apiUrl}/parseNewDoc`);
async function uploadFile(file) {
try {
const response = await fetch(`${apiUrl}/parseNewDoc`, {
method: "POST",
body: file,
});
const res = response;
return res;
if (true) {
const response = await fetch(`${apiUrl}/parseNewDoc`, {
method: "POST",
body: file,
});
const res = response;
return res;
} else {
const response = await fetch(`${apiUrl}/parseNewDoc`, {
method: "POST",
body: file,
});
const res = response;
return res;
}
} catch (error) {
console.error("Error:", error);
}
@@ -127,9 +138,10 @@ const UploadModal = (props) => {
}
async function handleUpload() {
if (!docTitle && !fileToParse) {
if (!docTitle && !fileToParse && !radioValue) {
setShowDocError("Please select a document to upload.");
setShowTitleError("Please enter a document title");
setRadioValueError("Please select document type");
return;
} else if (!docTitle) {
setShowTitleError("Please enter a document title");
@@ -255,6 +267,7 @@ const UploadModal = (props) => {
title="Document type"
options={radioOptions}
value={radioValue}
radioError={radioValueError}
onClick={(e) => handleSetRadioValue(e, "documentType")}
/>
</div>
@@ -295,7 +308,7 @@ const UploadModal = (props) => {
<Button
labelText="Upload"
className="primary-button pr-1 pl-1"
onClick={handleUpload}
onClick={() => handleUpload(radioValue)}
/>
</Modal.Footer>
</Modal>