2025-08-18 16:04:03 +01:00
|
|
|
import { Form, Formik } from "formik";
|
|
|
|
|
import type { HotlistUploadType } from "../../../types/types";
|
2025-09-17 11:39:26 +01:00
|
|
|
import { useSystemConfig } from "../../../hooks/useSystemConfig";
|
2025-09-25 10:38:49 +01:00
|
|
|
import { CAM_BASE } from "../../../utils/config";
|
2025-08-18 16:04:03 +01:00
|
|
|
|
|
|
|
|
const NPEDHotlist = () => {
|
2025-09-17 11:39:26 +01:00
|
|
|
const { uploadSettings } = useSystemConfig();
|
2025-08-18 16:04:03 +01:00
|
|
|
const initialValue = {
|
|
|
|
|
file: null,
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-17 11:39:26 +01:00
|
|
|
const handleSubmit = (values: HotlistUploadType) => {
|
|
|
|
|
const settings = {
|
|
|
|
|
file: values.file,
|
|
|
|
|
opts: {
|
|
|
|
|
timeoutMs: 30000,
|
|
|
|
|
fieldName: "upload",
|
2025-09-25 10:38:49 +01:00
|
|
|
uploadUrl: `${CAM_BASE}/upload/hotlist-upload/2`,
|
2025-09-17 11:39:26 +01:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
uploadSettings(settings);
|
|
|
|
|
};
|
|
|
|
|
|
2025-08-18 16:04:03 +01:00
|
|
|
return (
|
|
|
|
|
<Formik initialValues={initialValue} onSubmit={handleSubmit}>
|
|
|
|
|
{({ setFieldValue, setErrors, errors }) => {
|
|
|
|
|
return (
|
2025-09-26 13:58:14 +01:00
|
|
|
<Form className="flex flex-col space-y-2 px-2">
|
2025-08-18 16:04:03 +01:00
|
|
|
<input
|
|
|
|
|
type="file"
|
|
|
|
|
name="file"
|
|
|
|
|
id="file"
|
|
|
|
|
className="file:px-3 file:border file:border-gray-500 file:rounded-lg file:bg-blue-800 file:mr-5"
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
if (e.target.files) {
|
|
|
|
|
if (e.target.files[0].type !== "text/csv") {
|
|
|
|
|
setErrors({
|
|
|
|
|
file: "This file is not a CSV, please select a different one",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
setFieldValue("file", e.target.files[0]);
|
2025-09-17 11:39:26 +01:00
|
|
|
} else {
|
|
|
|
|
setErrors({ file: "no file" });
|
2025-08-18 16:04:03 +01:00
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<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"
|
2025-09-17 11:39:26 +01:00
|
|
|
// disabled={errors ? true : false}
|
2025-08-18 16:04:03 +01:00
|
|
|
>
|
|
|
|
|
Upload
|
|
|
|
|
</button>
|
2025-09-17 11:39:26 +01:00
|
|
|
<p>{errors.file && errors.file}</p>
|
2025-08-18 16:04:03 +01:00
|
|
|
</Form>
|
|
|
|
|
);
|
|
|
|
|
}}
|
|
|
|
|
</Formik>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default NPEDHotlist;
|