Skip to content

Commit

Permalink
Merge branch 'main' of github.com:tekdi/shiksha-admin
Browse files Browse the repository at this point in the history
  • Loading branch information
itsvick committed Sep 24, 2024
2 parents 11b1d86 + ebf9efc commit fb5d017
Show file tree
Hide file tree
Showing 6 changed files with 428 additions and 118 deletions.
4 changes: 2 additions & 2 deletions src/components/AreaSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,11 @@ const shouldRenderSelectCheckmarks =
tagName={t("CENTERS.CENTERS")}
selectedCategories={selectedCenter}
onCategoryChange={handleCenterChangeWrapper}
disabled={selectedBlock.length === 0 || selectedCenter[0] === ""}
disabled={selectedBlock.length === 0 || selectedCenter[0] === "" ||selectedBlock[0]===t("COMMON.ALL_BLOCKS")|| (selectedBlock?.length > 0 && allCenters?.length <= 0)}
overall={!inModal}
defaultValue={
// blockDefaultValue? blockDefaultValue:
selectedBlock?.length > 0 && blocks?.length <= 0
selectedBlock?.length > 0 && allCenters?.length <= 0
? t("COMMON.NO_CENTERS")
: t("COMMON.ALL_CENTERS")
}
Expand Down
6 changes: 4 additions & 2 deletions src/components/FormControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ const MultipleSelectCheckmarks: React.FC<MultipleSelectCheckmarksProps> = ({
}
onChange={handleChange}
input={<OutlinedInput label={tagName} />}
renderValue={(selected) => selected?.join(", ")}
MenuProps={MenuProps}
renderValue={(selected) => {
const selectedArray = Array.isArray(selected) ? selected : [selected];
return selectedArray.join(", ");
}} MenuProps={MenuProps}
>
{overall && (
<MenuItem value="all">
Expand Down
162 changes: 151 additions & 11 deletions src/components/HeaderComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ 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";

interface State {
value: string;
Expand Down Expand Up @@ -80,11 +83,13 @@ const HeaderComponent = ({
setSelectedBlock,
setSelectedCenter,
selectedCenterCode,
setSelectedCenterCode
setSelectedCenterCode,
setSelectedStateCode,
}: any) => {

const { t } = useTranslation();
const queryClient = useQueryClient();
const router = useRouter();

const theme = useTheme<any>();
const isMobile = useMediaQuery("(max-width:600px)");
Expand All @@ -95,9 +100,27 @@ const HeaderComponent = ({
const [allCenters, setAllCenters] = useState<CenterProp[]>([]);
const [initialDistrict, setInitialDistrict] = useState<any>("");
const [initialBlock, setInitialBlock] = useState<string>("");
const [initialized, setInitialized] = useState(false);

const [blocks, setBlocks] = useState<Block[]>([]);

const selectedBlockStore = useSubmittedButtonStore(
(state: any) => state.selectedBlockStore
);
const setSelectedBlockStore = useSubmittedButtonStore(
(state: any) => state.setSelectedBlockStore
);
const selectedDistrictStore = useSubmittedButtonStore(
(state: any) => state.selectedDistrictStore
);
const setSelectedDistrictStore = useSubmittedButtonStore(
(state: any) => state.setSelectedDistrictStore
);
const selectedCenterStore = useSubmittedButtonStore(
(state: any) => state.selectedCenterStore
);
const setSelectedCenterStore = useSubmittedButtonStore(
(state: any) => state.setSelectedCenterStore
);
const handleStateChangeWrapper = async (
selectedNames: string[],
selectedCodes: string[]
Expand Down Expand Up @@ -221,6 +244,20 @@ const HeaderComponent = ({

useEffect(() => {
const fetchData = async () => {
const { state, district, center } = router.query;
console.log(router.asPath)
const fullPath = router.asPath;

// Extract query parameters
const queryString = fullPath.split('?')[1]; // Get the part after '?'
console.log(queryString)
const params = new URLSearchParams(queryString);

// Check if 'block' is present
const hasBlock = params.has('block');
const hasDistrict = params.has('district');
const hasCenter = params.has('center');
const hasState = params.has('state');
try {
const object = {
// "limit": 20,
Expand Down Expand Up @@ -266,13 +303,53 @@ const HeaderComponent = ({
const districtResult= await formatedDistricts();

setDistricts(districtResult);
setSelectedDistrict([districtResult[0]?.label])
setSelectedDistrictCode(districtResult[0]?.value)
if(!hasDistrict)
{
setSelectedDistrict([districtResult[0]?.label])
setSelectedDistrictCode(districtResult[0]?.value)
localStorage.setItem('selectedDistrict', districtResult[0]?.label)
setSelectedDistrictStore(districtResult[0]?.label)

}
const blockResult=await formatedBlocks(districtResult[0]?.value)
setBlocks(blockResult);
if(!hasBlock && !hasDistrict)
{

setSelectedBlock([blockResult[0]?.label])
setSelectedBlockCode(blockResult[0]?.value)
if(userType===Role.TEAM_LEADERS)
{
setSelectedBlock([t("COMMON.ALL_BLOCKS")])
//setSelectedBlockCode("")
router.replace({
pathname: router.pathname,
query: {
...router.query,
state: stateField.code,
district: districtResult[0]?.value,
}
});
}
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: {
...router.query,
state: stateField.code,
district: districtResult[0]?.value,
block: blockResult[0]?.value
}
});

}

}

const getCentersObject = {
limit: 0,
offset: 0,
Expand Down Expand Up @@ -309,10 +386,29 @@ const HeaderComponent = ({
cohortId: item?.cohortId,
name: item?.name,
}));
setAllCenters(cohortInfo);

console.log(dataArray);
setAllCenters(cohortInfo);
setSelectedCenter([cohortInfo[0]?.name])
setSelectedCenterCode(cohortInfo[0]?.cohortId)
console.log(userType)
if(!hasCenter && !hasBlock && !hasDistrict && userType!==Role.TEAM_LEADERS)
{
console.log(hasCenter)
setSelectedCenter([t("COMMON.ALL_CENTERS")])
// setSelectedCenterCode([cohortInfo[0]?.cohortId])
// localStorage.setItem('selectedCenter',cohortInfo[0]?.name )
// setSelectedCenterStore(cohortInfo[0]?.name)
router.replace({
pathname: router.pathname,
query: {
...router.query,
state: stateField.code,
district: districtResult[0]?.value,
block: blockResult[0]?.value ,
// center: cohortInfo[0]?.cohortId
}
});
}

console.log(cohortInfo)
}

Expand All @@ -335,7 +431,7 @@ const HeaderComponent = ({
if (shouldFetchDistricts) {
fetchData();
}
}, [shouldFetchDistricts]);
}, [shouldFetchDistricts,userType]);
const handleChange = (event: React.SyntheticEvent, newValue: any) => {
console.log(newValue);
setStatusValue(newValue);
Expand All @@ -357,7 +453,51 @@ const HeaderComponent = ({
// }
// }, [blocks, selectedBlock, handleBlockChangeWrapper]);


useEffect(() => {

const { state, district, block, center } = router.query;
{

if (state) {
setSelectedStateCode(state.toString());
}

if (district) {
setSelectedDistrictCode(district.toString());
// setSelectedDistrict([selectedDistrictStore])
setSelectedDistrict([localStorage.getItem('selectedDistrict')])
if(!localStorage.getItem('selectedDistrict'))
{
setSelectedDistrict([selectedDistrictStore])
}

}

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)

setSelectedCenterCode([center.toString()]);
// setSelectedCenter([selectedCenterStore])
setSelectedCenter([localStorage.getItem('selectedCenter')])
if(!localStorage.getItem('selectedCenter'))
setSelectedCenter([selectedCenterStore])

}
// setInitialized(true)
}

}, [router]);


return (
<Box
Expand Down
Loading

0 comments on commit fb5d017

Please sign in to comment.