From 25acb6c35eaecbc02e0ff3956daa805c22d6dbbb Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Thu, 8 Feb 2024 19:18:42 +0530 Subject: [PATCH] fix external results improper check --- .../ExternalResult/ExternalResultUpload.tsx | 28 ++++++------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/src/Components/ExternalResult/ExternalResultUpload.tsx b/src/Components/ExternalResult/ExternalResultUpload.tsx index a8f9e339254..85166b1c3c8 100644 --- a/src/Components/ExternalResult/ExternalResultUpload.tsx +++ b/src/Components/ExternalResult/ExternalResultUpload.tsx @@ -1,6 +1,6 @@ import _ from "lodash-es"; import { navigate } from "raviger"; -import { lazy, useEffect, useState } from "react"; +import { lazy, useState } from "react"; import CSVReader from "react-csv-reader"; import useConfig from "../../Common/hooks/useConfig"; import * as Notification from "../../Utils/Notifications.js"; @@ -12,6 +12,7 @@ import request from "../../Utils/request/request"; import routes from "../../Redux/api"; import { IExternalResult } from "./models"; import CareIcon from "../../CAREUI/icons/CareIcon"; +import useAuthUser from "../../Common/hooks/useAuthUser"; export default function ExternalResultUpload() { const { sample_format_external_result_import } = useConfig(); @@ -20,30 +21,18 @@ export default function ExternalResultUpload() { const [csvData, setCsvData] = useState(new Array()); const [errors, setErrors] = useState([]); const [validationErrorCount, setValidationErrorCount] = useState(0); - const [user, setUser] = useState({}); - const handleForce = (data: any) => { + const authUser = useAuthUser(); + const handleForce = (data: IExternalResult[]) => { setCsvData(data); setValidationErrorCount( data.filter( - (result: IExternalResult) => - result.district !== user.district_object.name + (result) => String(result.district) !== authUser.district_object?.name ).length ); }; const { t } = useTranslation(); const { goBack } = useAppHistory(); - const fetchUser = async () => { - const { data: userData } = await request(routes.currentUser, { - pathParams: {}, - }); - setUser(userData); - }; - - useEffect(() => { - fetchUser(); - }, []); - const papaparseOptions = { header: true, dynamicTyping: true, @@ -67,7 +56,7 @@ export default function ExternalResultUpload() { sample_tests: validationErrorCount ? csvData.filter( (data: IExternalResult) => - data.district === user.district_object.name + String(data.district) !== authUser.district_object?.name ) : csvData, }, @@ -156,7 +145,7 @@ export default function ExternalResultUpload() {

Total: {csvData.length}

)}
- {csvData.map((data: any, index: number) => { + {csvData.map((data, index: number) => { return (
{index + 1}
@@ -175,7 +164,8 @@ export default function ExternalResultUpload() { : null}
- {data.district !== user.district_object.name && ( + {String(data.district) !== + authUser.district_object?.name && (

Different districts