Skip to content

Commit

Permalink
Issue feat: fixes production issues
Browse files Browse the repository at this point in the history
  • Loading branch information
AkshataKatwal16 committed Oct 7, 2024
1 parent 71d9daa commit f2a53b1
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 51 deletions.
14 changes: 10 additions & 4 deletions src/components/AreaSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,18 @@ const AreaSelection: React.FC<DropdownBoxProps> = ({
md={inModal ? 12 : 4}
lg={inModal ? 12 : isCenterSelection ? 3 : 4}
>
{shouldRenderSelectCheckmarks && blocks.length > 0 &&(
{shouldRenderSelectCheckmarks &&(
<MultipleSelectCheckmarks
names={capitalizeFirstLetterOfEachWordInArray(
blocks?.map((block) => 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
Expand All @@ -209,7 +215,7 @@ const AreaSelection: React.FC<DropdownBoxProps> = ({
}
overall={!inModal}
defaultValue={
selectedDistrict?.length > 0 && blocks?.length === 0
selectedDistrict?.length > 0 && (blocks?.length === 0)
? t("COMMON.NO_BLOCKS")
: t("COMMON.ALL_BLOCKS")
}
Expand Down
66 changes: 52 additions & 14 deletions src/components/HeaderComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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,
Expand All @@ -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: {
Expand Down Expand Up @@ -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")
}

}


Expand All @@ -491,7 +528,8 @@ const HeaderComponent = ({

// setInitialized(true)
}
}, [router]);
handleRouteparam();
}, [router, userType]);

return (
<Box
Expand Down
99 changes: 66 additions & 33 deletions src/pages/centers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ const Center: React.FC = () => {
const fetchUserList = async () => {
setLoading(true);
try {
setCohortData([]);

const limit = pageLimit;
const offset = pageOffset * limit;
const sort = sortBy;
Expand All @@ -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[] = [];
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand All @@ -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",

});
}
}
Expand Down Expand Up @@ -865,6 +896,7 @@ finalResult?.forEach((item: any, index: number) => {
{

setFilters({

states: stateField.code,
districts: selectedDistrictCode,
status: filters.status,
Expand Down Expand Up @@ -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.");
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit f2a53b1

Please sign in to comment.