code quality improvements and improved file error handling
This commit is contained in:
@@ -1,13 +1,26 @@
|
||||
import { Form, Formik } from "formik";
|
||||
import type { HotlistUploadType } from "../../../types/types";
|
||||
import { useSystemConfig } from "../../../hooks/useSystemConfig";
|
||||
|
||||
const NPEDHotlist = () => {
|
||||
const { uploadSettings } = useSystemConfig();
|
||||
const initialValue = {
|
||||
file: null,
|
||||
};
|
||||
|
||||
const handleSubmit = (values: HotlistUploadType) => console.log(values.file);
|
||||
// upload/hotlist-upload/2
|
||||
const handleSubmit = (values: HotlistUploadType) => {
|
||||
const settings = {
|
||||
file: values.file,
|
||||
opts: {
|
||||
timeoutMs: 30000,
|
||||
fieldName: "upload",
|
||||
uploadUrl: "http://192.168.75.11/upload/hotlist-upload/2",
|
||||
},
|
||||
};
|
||||
|
||||
uploadSettings(settings);
|
||||
};
|
||||
|
||||
return (
|
||||
<Formik initialValues={initialValue} onSubmit={handleSubmit}>
|
||||
{({ setFieldValue, setErrors, errors }) => {
|
||||
@@ -24,21 +37,21 @@ const NPEDHotlist = () => {
|
||||
setErrors({
|
||||
file: "This file is not a CSV, please select a different one",
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
setFieldValue("file", e.target.files[0]);
|
||||
} else {
|
||||
setErrors({ file: "no file" });
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
className="w-1/4 text-white bg-green-700 hover:bg-green-800 font-small rounded-lg text-sm px-2 py-2.5"
|
||||
disabled={errors ? true : false}
|
||||
// disabled={errors ? true : false}
|
||||
>
|
||||
Upload
|
||||
</button>
|
||||
<p>{errors && errors.file}</p>
|
||||
<p>{errors.file && errors.file}</p>
|
||||
</Form>
|
||||
);
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user