Skip to content

Commit

Permalink
Issue #PS-0000 fix: Handled comparions
Browse files Browse the repository at this point in the history
  • Loading branch information
itsvick committed Nov 30, 2024
1 parent 06caeea commit 087a49f
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 245 deletions.
6 changes: 3 additions & 3 deletions src/components/AddBlockModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export const AddBlockModal: React.FC<AddBlockModalProps> = ({
const districts = data?.result?.values || [];
setDistrictsOptionRead(districts);

const districtNameArray = districts.map((item: any) => item.label);
const districtNameArray = districts.map((item: any) => item?.label?.toLowerCase());
setDistrictNameArr(districtNameArray);

const districtCodeArray = districts.map((item: any) => item.value);
Expand Down Expand Up @@ -162,7 +162,7 @@ export const AddBlockModal: React.FC<AddBlockModalProps> = ({

const matchingDistrict = districtsOptionRead.find(
(district: { label: string }) =>
district.label === transformedName
district?.label?.toLowerCase() === transformedName?.toLowerCase()
);
return {
label: transformedName,
Expand All @@ -176,7 +176,7 @@ export const AddBlockModal: React.FC<AddBlockModalProps> = ({
}
)
.filter((district: { label: any }) =>
districtNameArr.includes(district.label)
districtNameArr.includes(district?.label?.toLowerCase())
);
setDistricts(filteredDistrictData);
} catch (error) {
Expand Down
207 changes: 99 additions & 108 deletions src/components/HeaderComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
import SearchBar from "@/components/layouts/header/SearchBar";
import { formatedBlocks, formatedDistricts } from "@/services/formatedCohorts";
import { QueryKeys, Role, Status, TelemetryEventType } from "@/utils/app.constant";
import { telemetryFactory } from "@/utils/telemetry";
import useSubmittedButtonStore from "@/utils/useSharedState";
import AddIcon from "@mui/icons-material/Add";
import {
Box,
Button,
FormControl,
MenuItem,
Typography,
useMediaQuery,
Divider,
useMediaQuery
} from "@mui/material";
import Select from "@mui/material/Select";
import { useTheme } from "@mui/material/styles";
import Tab from "@mui/material/Tab";
import Tabs from "@mui/material/Tabs";
import { useQueryClient } from "@tanstack/react-query";
import { useTranslation } from "next-i18next";
import { useRouter } from "next/router";
import { useEffect, useState } from "react";
import { QueryKeys, Role, Status, TelemetryEventType } from "@/utils/app.constant";
import FiberManualRecordIcon from "@mui/icons-material/FiberManualRecord";
import {
getCenterList,
getStateBlockDistrictList,
} from "../services/MasterDataService";
import AreaSelection from "./AreaSelection";
import { transformArray } from "../utils/Helper";
import Tab from "@mui/material/Tab";
import Tabs from "@mui/material/Tabs";
import { useQueryClient } from "@tanstack/react-query";
import { formatedBlocks, formatedDistricts } from "@/services/formatedCohorts";
import { useRouter } from "next/router";
import useSubmittedButtonStore from "@/utils/useSharedState";
import { userAgent } from "next/server";
import { telemetryFactory } from "@/utils/telemetry";
import AreaSelection from "./AreaSelection";

interface State {
value: string;
Expand Down Expand Up @@ -103,7 +100,7 @@ const HeaderComponent = ({
const [initialized, setInitialized] = useState(false);
const isArchived = useSubmittedButtonStore(
(state: any) => state.isArchived
);
);

const [blocks, setBlocks] = useState<Block[]>([]);
const selectedBlockStore = useSubmittedButtonStore(
Expand Down Expand Up @@ -195,23 +192,23 @@ const HeaderComponent = ({
handleDistrictChange(selected, selectedCodes);

const windowUrl = window.location.pathname;
const cleanedUrl = windowUrl.replace(/^\//, '');
const env = cleanedUrl.split("/")[0];
const cleanedUrl = windowUrl.replace(/^\//, '');
const env = cleanedUrl.split("/")[0];


const telemetryInteract = {
context: {
env: env,
cdata: [],
},
edata: {
id: 'filter-by-district:'+selected[0],
type: TelemetryEventType.CLICK,
subtype: '',
pageid: cleanedUrl,
},
};
telemetryFactory.interact(telemetryInteract);
const telemetryInteract = {
context: {
env: env,
cdata: [],
},
edata: {
id: 'filter-by-district:' + selected[0],
type: TelemetryEventType.CLICK,
subtype: '',
pageid: cleanedUrl,
},
};
telemetryFactory.interact(telemetryInteract);

};

Expand Down Expand Up @@ -268,7 +265,7 @@ const HeaderComponent = ({
cdata: [],
},
edata: {
id: 'filter-by-block:'+selected[0],
id: 'filter-by-block:' + selected[0],
type: TelemetryEventType.CLICK,
subtype: '',
pageid: cleanedUrl,
Expand All @@ -292,7 +289,7 @@ const HeaderComponent = ({
cdata: [],
},
edata: {
id: 'filter-by-center:'+selected[0],
id: 'filter-by-center:' + selected[0],
type: TelemetryEventType.CLICK,
subtype: '',
pageid: cleanedUrl,
Expand Down Expand Up @@ -370,24 +367,22 @@ const HeaderComponent = ({
districtResult[0]?.label
);
setSelectedDistrictStore(districtResult[0]?.label);
blockResult = await formatedBlocks(
blockResult = await formatedBlocks(
districtResult[0]?.value
);
console.log(blockResult)
if(blockResult?.message ==="Request failed with status code 404")
{
setBlocks([]);
}
else
{
setBlocks(blockResult);
if (blockResult?.message === "Request failed with status code 404") {
setBlocks([]);
}
else {
setBlocks(blockResult);

}
}
}
if (!hasBlock && !hasDistrict && userType!==Role.CONTENT_CREATOR) {
if (userType === Role.TEAM_LEADERS || userType==="Centers") {
// setSelectedBlock([t("COMMON.ALL_BLOCKS")]);

if (!hasBlock && !hasDistrict && userType !== Role.CONTENT_CREATOR) {
if (userType === Role.TEAM_LEADERS || userType === "Centers") {
// setSelectedBlock([t("COMMON.ALL_BLOCKS")]);
//setSelectedBlockCode("")
router.replace({
pathname: router.pathname,
Expand All @@ -399,18 +394,17 @@ const HeaderComponent = ({
});
} else {
console.log(blockResult)
if(blockResult?.message==="Request failed with status code 404")
{
if (blockResult?.message === "Request failed with status code 404") {
setBlocks([]);
}
else{
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 All @@ -422,14 +416,13 @@ const HeaderComponent = ({
});
}
}
else if(userType===Role.CONTENT_CREATOR)
{
else if (userType === Role.CONTENT_CREATOR) {
router.replace({
pathname: router.pathname,
query: {
...router.query,
state: stateField.code,

},
});
}
Expand Down Expand Up @@ -542,50 +535,48 @@ const HeaderComponent = ({
// }, [blocks, selectedBlock, handleBlockChangeWrapper]);

useEffect(() => {
const handleRouteparam = async() =>
{
const handleRouteparam = async () => {
const { state, district, block, center } = router.query;
if (state) {
setSelectedStateCode(state.toString());
}
console.log(district?.toString())
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(
try {
const blockResult = await formatedBlocks(
district?.toString()
);
console.log(blockResult.message)
if(blockResult.message==="Request failed with status code 404")
{
setBlocks([]);
);
console.log(blockResult.message)
if (blockResult.message === "Request failed with status code 404") {
setBlocks([]);

}
else
}
else
setBlocks(blockResult);
}
catch{
// console.log("hii")
catch {
// console.log("hii")
}

}


if (block ) {

if (block) {
setSelectedBlockCode(block.toString());
console.log(selectedBlockCode);
// setSelectedBlock([selectedBlockStore])
setSelectedBlock([localStorage.getItem("selectedBlock")]);
if (!localStorage.getItem("selectedBlock"))
setSelectedBlock([selectedBlockStore]);
}


if (center) {
console.log(center);
Expand All @@ -596,7 +587,7 @@ const HeaderComponent = ({
if (!localStorage.getItem("selectedCenter"))
setSelectedCenter([selectedCenterStore]);
}

// setInitialized(true)
}
handleRouteparam();
Expand All @@ -619,7 +610,7 @@ const HeaderComponent = ({
</Typography>
)}

{showStateDropdown && (
{showStateDropdown && (
<AreaSelection
states={transformArray(states)}
districts={transformArray(districts)}
Expand Down Expand Up @@ -712,7 +703,7 @@ const HeaderComponent = ({
placeholder={searchPlaceHolder}
/>
</Box>
{showAddNew && !isArchived && (
{showAddNew && !isArchived && (
<Box
display={"flex"}
gap={1}
Expand Down Expand Up @@ -751,40 +742,40 @@ const HeaderComponent = ({
)}
</Box>
{/* {showAddNew && ( */}
<Box
sx={{
display: "flex",

ml: "10px",
mt: isMobile ? "10px" : "16px",
mb: "10px",
gap: "15px", // boxShadow: "0px 0px 10px rgba(0, 0, 0, 0.1)",
}}
>
{showSort && (
<FormControl sx={{ minWidth: "120px" }}>
<Select
value={selectedSort}
onChange={handleSortChange}
displayEmpty
style={{
borderRadius: "8px",
height: "40px",
marginLeft: "5px",
fontSize: "14px",
backgroundColor: theme.palette.secondary["100"],
}}
>
<MenuItem value="Sort">{t("COMMON.SORT")}</MenuItem>
{Sort?.map((state, index) => (
<MenuItem value={state} key={index}>
{state}
</MenuItem>
))}
</Select>
</FormControl>
)}
</Box>
<Box
sx={{
display: "flex",

ml: "10px",
mt: isMobile ? "10px" : "16px",
mb: "10px",
gap: "15px", // boxShadow: "0px 0px 10px rgba(0, 0, 0, 0.1)",
}}
>
{showSort && (
<FormControl sx={{ minWidth: "120px" }}>
<Select
value={selectedSort}
onChange={handleSortChange}
displayEmpty
style={{
borderRadius: "8px",
height: "40px",
marginLeft: "5px",
fontSize: "14px",
backgroundColor: theme.palette.secondary["100"],
}}
>
<MenuItem value="Sort">{t("COMMON.SORT")}</MenuItem>
{Sort?.map((state, index) => (
<MenuItem value={state} key={index}>
{state}
</MenuItem>
))}
</Select>
</FormControl>
)}
</Box>
{/* )} */}
{children}
</Box>
Expand Down
Loading

0 comments on commit 087a49f

Please sign in to comment.