From f2a53b1aa673a86e45f45feb6228bb8fa8483de5 Mon Sep 17 00:00:00 2001 From: Akshata Katwal Date: Mon, 7 Oct 2024 19:33:29 +0530 Subject: [PATCH] Issue feat: fixes production issues --- src/components/AreaSelection.tsx | 14 +++-- src/components/HeaderComponent.tsx | 66 +++++++++++++++----- src/pages/centers.tsx | 99 ++++++++++++++++++++---------- 3 files changed, 128 insertions(+), 51 deletions(-) diff --git a/src/components/AreaSelection.tsx b/src/components/AreaSelection.tsx index beeba37e..dc432b93 100644 --- a/src/components/AreaSelection.tsx +++ b/src/components/AreaSelection.tsx @@ -191,12 +191,18 @@ const AreaSelection: React.FC = ({ md={inModal ? 12 : 4} lg={inModal ? 12 : isCenterSelection ? 3 : 4} > - {shouldRenderSelectCheckmarks && blocks.length > 0 &&( + {shouldRenderSelectCheckmarks &&( block.label) + blocks?.length > 0 ? blocks.map((block) => block.label) : [] + // blocks.map((block) => block.label) + )} - codes={blocks?.map((block) => block.value)} + codes={ + + blocks?.length > 0 ? blocks?.map((block) => block.value) : [] + // blocks?.map((block) => block.value) + } tagName={t("FACILITATORS.BLOCK")} selectedCategories={capitalizeFirstLetterOfEachWordInArray( selectedBlock @@ -209,7 +215,7 @@ const AreaSelection: React.FC = ({ } overall={!inModal} defaultValue={ - selectedDistrict?.length > 0 && blocks?.length === 0 + selectedDistrict?.length > 0 && (blocks?.length === 0) ? t("COMMON.NO_BLOCKS") : t("COMMON.ALL_BLOCKS") } diff --git a/src/components/HeaderComponent.tsx b/src/components/HeaderComponent.tsx index 8c3bc7f6..f0983877 100644 --- a/src/components/HeaderComponent.tsx +++ b/src/components/HeaderComponent.tsx @@ -300,7 +300,7 @@ const HeaderComponent = ({ // const response = await getStateBlockDistrictList(object); const result = response?.result?.values; const districtResult = await formatedDistricts(); - + let blockResult; setDistricts(districtResult); if (!hasDistrict) { setSelectedDistrict([districtResult[0]?.label]); @@ -310,14 +310,24 @@ const HeaderComponent = ({ districtResult[0]?.label ); setSelectedDistrictStore(districtResult[0]?.label); + blockResult = await formatedBlocks( + districtResult[0]?.value + ); + console.log(blockResult) + if(blockResult?.message ==="Request failed with status code 404") + { + setBlocks([]); + } + else + { + setBlocks(blockResult); + + } } - const blockResult = await formatedBlocks( - districtResult[0]?.value - ); - setBlocks(blockResult); + if (!hasBlock && !hasDistrict) { if (userType === Role.TEAM_LEADERS || userType==="Centers") { - setSelectedBlock([t("COMMON.ALL_BLOCKS")]); + // setSelectedBlock([t("COMMON.ALL_BLOCKS")]); //setSelectedBlockCode("") router.replace({ pathname: router.pathname, @@ -328,11 +338,19 @@ const HeaderComponent = ({ }, }); } else { - setSelectedBlock([blockResult[0]?.label]); - setSelectedBlockCode(blockResult[0]?.value); - localStorage.setItem("selectedBlock", blockResult[0]?.label); - setSelectedBlockStore(blockResult[0]?.label); - + console.log(blockResult) + if(blockResult?.message==="Request failed with status code 404") + { + setBlocks([]); + } + else{ + setSelectedBlock([blockResult[0]?.label]); + setSelectedBlockCode(blockResult[0]?.value); + localStorage.setItem("selectedBlock", blockResult[0]?.label); + setSelectedBlockStore(blockResult[0]?.label); + + } + router.replace({ pathname: router.pathname, query: { @@ -453,19 +471,38 @@ const HeaderComponent = ({ // }, [blocks, selectedBlock, handleBlockChangeWrapper]); useEffect(() => { - const { state, district, block, center } = router.query; + const handleRouteparam = async() => { + const { state, district, block, center } = router.query; if (state) { setSelectedStateCode(state.toString()); } - console.log(selectedDistrict) + console.log(district?.toString()) if (district) { setSelectedDistrictCode(district.toString()); // setSelectedDistrict([selectedDistrictStore]) setSelectedDistrict([localStorage.getItem("selectedDistrict")]); if (!localStorage.getItem("selectedDistrict")) { setSelectedDistrict([selectedDistrictStore]); + + } + try{ + const blockResult = await formatedBlocks( + district?.toString() + ); + console.log(blockResult.message) + if(blockResult.message==="Request failed with status code 404") + { + setBlocks([]); + + } + else + setBlocks(blockResult); + } + catch{ + // console.log("hii") } + } @@ -491,7 +528,8 @@ const HeaderComponent = ({ // setInitialized(true) } - }, [router]); + handleRouteparam(); + }, [router, userType]); return ( { const fetchUserList = async () => { setLoading(true); try { + setCohortData([]); + const limit = pageLimit; const offset = pageOffset * limit; const sort = sortBy; @@ -208,18 +210,18 @@ const Center: React.FC = () => { sort: sort, filters: filters, }; - // const resp = await getCohortList(data); - const resp = await queryClient.fetchQuery({ - queryKey: [ - QueryKeys.GET_COHORT_LIST, - data.limit, - data.offset, - JSON.stringify(data.filters), - JSON.stringify(data.sort), - ], - queryFn: () => getCohortList(data), - }); - + const resp = await getCohortList(data); + // const resp = await queryClient.fetchQuery({ + // queryKey: [ + // QueryKeys.GET_COHORT_LIST, + // data.limit, + // data.offset, + // JSON.stringify(data.filters), + // JSON.stringify(data.sort), + // ], + // queryFn: () => getCohortList(data), + // }); +console.log(resp) if (resp) { const result = resp?.results?.cohortDetails; const resultData: centerData[] = []; @@ -282,7 +284,12 @@ finalResult?.forEach((item: any, index: number) => { setPageCount(pageCount); setLoading(false); } + else{ + setCohortData([]); + + } } catch (error) { + console.log("not data found") setCohortData([]); setLoading(false); console.error("Error fetching user list:", error); @@ -312,16 +319,16 @@ finalResult?.forEach((item: any, index: number) => { cohortId: cohortId, }, }; - - const response = await queryClient.fetchQuery({ - queryKey: [ - QueryKeys.GET_COHORT_MEMBER_LIST, - data.limit, - data.offset, - JSON.stringify(data.filters), - ], - queryFn: () => fetchCohortMemberList(data), - }); +const response= await fetchCohortMemberList(data); + // const response = await queryClient.fetchQuery({ + // queryKey: [ + // QueryKeys.GET_COHORT_MEMBER_LIST, + // data.limit, + // data.offset, + // JSON.stringify(data.filters), + // ], + // queryFn: () => fetchCohortMemberList(data), + // }); if (response?.result) { const userDetails = response.result.userDetails; @@ -472,13 +479,19 @@ finalResult?.forEach((item: any, index: number) => { setSelectedDistrictStore(selected[0]) if (selected[0] === "" || selected[0] === t("COMMON.ALL_DISTRICTS")) { if (filters.status) { + console.log("true...") setFilters({ states: selectedStateCode, status: filters.status, + type:"COHORT", + }); } else { setFilters({ + states: selectedStateCode, + type:"COHORT", + }); } if (newQuery.district) { @@ -504,19 +517,25 @@ finalResult?.forEach((item: any, index: number) => { setSelectedDistrictCode(districts); if (filters.status) { setFilters({ + states: selectedStateCode, districts: districts, status: filters.status, + //type:"COHORT", + }); } else { setFilters({ + states: selectedStateCode, districts: districts, + // type:"COHORT", + }); } } setPageOffset(Numbers.ZERO); - fetchUserList(); + // fetchUserList(); }; const handleBlockChange = (selected: string[], code: string[]) => { setSelectedBlock(selected); @@ -547,14 +566,20 @@ finalResult?.forEach((item: any, index: number) => { }); if (filters.status) { setFilters({ + states: selectedStateCode, districts: selectedDistrictCode, status: filters.status, + type:"COHORT", + }); } else { setFilters({ + states: selectedStateCode, districts: selectedDistrictCode, + type:"COHORT", + }); } } else { @@ -571,16 +596,22 @@ finalResult?.forEach((item: any, index: number) => { setSelectedBlockCode(blocks); if (filters.status) { setFilters({ + states: selectedStateCode, districts: selectedDistrictCode, blocks: blocks, status: filters.status, + type:"COHORT", + }); } else { setFilters({ + states: selectedStateCode, districts: selectedDistrictCode, blocks: blocks, + type:"COHORT", + }); } } @@ -865,6 +896,7 @@ finalResult?.forEach((item: any, index: number) => { { setFilters({ + states: stateField.code, districts: selectedDistrictCode, status: filters.status, @@ -916,16 +948,16 @@ finalResult?.forEach((item: any, index: number) => { }, }; - // const result = await getCohortList(data); - const result = await queryClient.fetchQuery({ - queryKey: [ - QueryKeys.GET_COHORT_LIST, - data.limit, - data.offset, - data.filters, - ], - queryFn: () => getCohortList(data), - }); + const result = await getCohortList(data); + // const result = await queryClient.fetchQuery({ + // queryKey: [ + // QueryKeys.GET_COHORT_LIST, + // data.limit, + // data.offset, + // data.filters, + // ], + // queryFn: () => getCohortList(data), + // }); if (!result || !result.results || !result.results.cohortDetails) { console.log("Invalid response structure or no cohort details found."); @@ -968,6 +1000,7 @@ finalResult?.forEach((item: any, index: number) => { console.log("Error handling member click:", error); } }; + console.log(cohortData); // props to send in header const userProps = {