Skip to content

Commit

Permalink
Merge pull request #83 from AkshataKatwal16/admin
Browse files Browse the repository at this point in the history
Issue feat:Add state district block field Ids
  • Loading branch information
itsvick authored Aug 2, 2024
2 parents 0a89309 + 8b24785 commit 61b27c6
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 60 deletions.
12 changes: 7 additions & 5 deletions src/components/AddFacilitator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
handleDistrictChangeWrapper,
handleBlockChangeWrapper,
handleCenterChangeWrapper,
BlockFieldId, DistrctFieldId, StateFieldId

} = useLocationState(open, onClose);

useEffect(() => {
Expand Down Expand Up @@ -190,16 +192,16 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({

if (!isEditModal) {
apiBody.customFields.push({
fieldId: "549d3575-bf01-48a9-9fff-59220fede174",
fieldId: BlockFieldId,
value: [selectedBlockCode],
});
apiBody.customFields.push({
fieldId: "b61edfc6-3787-4079-86d3-37262bf23a9e",
value: [selectedStateCode],
fieldId: StateFieldId,
value: [selectedStateCode]
});
apiBody.customFields.push({
fieldId: "f2d731dd-2298-40d3-80bb-9ae6c5b38fb8",
value: [selectedDistrictCode],
fieldId: DistrctFieldId,
value: [selectedDistrictCode]
});
}
try {
Expand Down
9 changes: 5 additions & 4 deletions src/components/AddLeanerModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ const AddLearnerModal: React.FC<AddLearnerModalProps> = ({
handleDistrictChangeWrapper,
handleBlockChangeWrapper,
handleCenterChangeWrapper,
selectedCenterCode,
selectedCenterCode, BlockFieldId, DistrctFieldId, StateFieldId

} = useLocationState(open, onClose);

useEffect(() => {
Expand Down Expand Up @@ -178,15 +179,15 @@ const AddLearnerModal: React.FC<AddLearnerModalProps> = ({
});
if (!isEditModal) {
apiBody.customFields.push({
fieldId: "a717bb68-5c8a-45cb-b6dd-376caa605736",
fieldId: BlockFieldId,
value: [selectedBlockCode],
});
apiBody.customFields.push({
fieldId: "61b5909a-0b45-4282-8721-e614fd36d7bd",
fieldId: StateFieldId,
value: [selectedStateCode],
});
apiBody.customFields.push({
fieldId: "aecb84c9-fe4c-4960-817f-3d228c0c7300",
fieldId: DistrctFieldId,
value: [selectedDistrictCode],
});
}
Expand Down
13 changes: 7 additions & 6 deletions src/components/AddTeamLeaderModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ const AddTeamLeaderModal: React.FC<AddLearnerModalProps> = ({
handleCenterChangeWrapper,
selectedCenterCode,
selectedBlockFieldId,
dynamicFormForBlock
dynamicFormForBlock,
BlockFieldId, DistrctFieldId, StateFieldId

} = useLocationState(open, onClose);

Expand Down Expand Up @@ -185,15 +186,15 @@ const AddTeamLeaderModal: React.FC<AddLearnerModalProps> = ({
});
if (!isEditModal) {
apiBody.customFields.push({
fieldId: "394ee6c9-3c4b-4065-ab82-19dc6ab52e67",
fieldId: BlockFieldId,
value: [selectedBlockCode],
});
apiBody.customFields.push({
fieldId: "8d56e5e6-d504-4c51-a848-eb1b0a8d2ed6",
fieldId: StateFieldId,
value: [selectedStateCode],
});
apiBody.customFields.push({
fieldId: "ea1461c1-2dd3-469d-b58d-52c6acdce30b",
fieldId: DistrctFieldId,
value: [selectedDistrictCode],
});
}
Expand Down Expand Up @@ -320,11 +321,11 @@ const AddTeamLeaderModal: React.FC<AddLearnerModalProps> = ({
marginTop: "10px",
}}
>
{!dynamicForm && (
{/* {!dynamicForm && (
<Typography>
{t("LEARNERS.FIRST_SELECT_REQUIRED_FIELDS")}{" "}
</Typography>
)}
)} */}
<AreaSelection
states={transformArray(states)}
districts={transformArray(districts)}
Expand Down
34 changes: 31 additions & 3 deletions src/components/DynamicForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const DynamicForm: React.FC<DynamicFormProps> = ({
};



function transformErrors(errors: any) {
console.log("errors", errors);
console.log("schema", schema);
Expand All @@ -78,6 +78,25 @@ const DynamicForm: React.FC<DynamicFormProps> = ({
error.message = t("FORM_ERROR_MESSAGES.THIS_IS_REQUIRED_FIELD");
break;
}
case "maximum":
{
const property = error.property.substring(1);

if (schema.properties?.[property]?.validation?.includes("numeric")) {
error.message = t("FORM_ERROR_MESSAGES.MAX_LENGTH_DIGITS_ERROR", {
maxLength: schema.properties?.[property]?.maxLength,
});
}
}
case "minimum":
{
const property = error.property.substring(1);
if (schema.properties?.[property]?.validation?.includes("numeric")) {
error.message = t("FORM_ERROR_MESSAGES.MIN_LENGTH_DIGITS_ERROR", {
minLength: schema.properties?.[property]?.minLength,
});
}
}
case "pattern": {
// if (schema.properties?.[property]?.validation?.includes("numeric")) {
// error.message = t("FORM_ERROR_MESSAGES.ENTER_ONLY_DIGITS");
Expand All @@ -96,6 +115,7 @@ const DynamicForm: React.FC<DynamicFormProps> = ({
// }

const pattern = error?.params?.pattern;
console.log(pattern)
const property = error.property.substring(1);

switch (pattern) {
Expand All @@ -109,8 +129,15 @@ const DynamicForm: React.FC<DynamicFormProps> = ({
if (schema.properties?.[property]?.validation?.includes("mobile")) {
error.message = t(
"FORM_ERROR_MESSAGES.ENTER_VALID_MOBILE_NUMBER"
);
} else {
);

}
else if (schema.properties?.[property]?.validation?.includes(".age")) {
error.message = t(
"age must be valid"
);
}
else {
error.message = t(
"FORM_ERROR_MESSAGES.CHARACTERS_AND_SPECIAL_CHARACTERS_NOT_ALLOWED"
);
Expand Down Expand Up @@ -153,6 +180,7 @@ const DynamicForm: React.FC<DynamicFormProps> = ({
}
}
}

}

return error;
Expand Down
67 changes: 35 additions & 32 deletions src/components/HeaderComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const HeaderComponent = ({
};
console.log(object);
const response = await getStateBlockDistrictList(object);
const result = response?.result;
const result = response?.result?.values;
setDistricts(result);
} catch (error) {
console.log(error);
Expand All @@ -113,7 +113,7 @@ const HeaderComponent = ({
fieldName: "blocks",
};
const response = await getStateBlockDistrictList(object);
const result = response?.result;
const result = response?.result?.values;
setBlocks(result);
} catch (error) {
console.log(error);
Expand All @@ -137,7 +137,7 @@ const HeaderComponent = ({
fieldName: "states",
};
const response = await getStateBlockDistrictList(object);
const result = response?.result;
const result = response?.result?.values;
setStates(result);
console.log(typeof states);
} catch (error) {
Expand Down Expand Up @@ -188,35 +188,30 @@ const HeaderComponent = ({
<SearchBar onSearch={handleSearch} placeholder={searchPlaceHolder} />
</Box>
<Box display={"flex"} gap={1} alignItems={"center"}>
{showFilter && (
<>
<Typography variant="h2" fontWeight={"bold"}>
{t("COMMON.FILTER_BY_STATUS")}
</Typography>
<FormControl sx={{ minWidth: "120px" }}>
<Select
value={selectedFilter}
onChange={handleFilterChange}
displayEmpty
style={{
borderRadius: "8px",
height: "40px",
fontSize: "14px",
}}
>
<MenuItem value="All">
<em>{t("COMMON.ALL")}</em>
</MenuItem>
{Filter?.map((filter, index) => (
<MenuItem value={filter} key={index}>
{filter}
</MenuItem>
))}
</Select>
</FormControl>
</>
)}

<Typography variant="h3">
{t("COMMON.FILTER_BY_STATUS")}
</Typography>
<FormControl sx={{ minWidth: "120px" }}>
<Select
value={selectedFilter}
onChange={handleFilterChange}
displayEmpty
style={{
borderRadius: "8px",
height: "40px",
fontSize: "14px",
}}
>
<MenuItem value="All">
<em>{t("COMMON.ALL")}</em>
</MenuItem>
{Filter?.map((filter, index) => (
<MenuItem value={filter} key={index}>
{filter}
</MenuItem>
))}
</Select>
</FormControl>
{showSort && (
<FormControl sx={{ minWidth: "120px" }}>
<Select
Expand All @@ -239,6 +234,14 @@ const HeaderComponent = ({
</FormControl>
)}
</Box>








</Box>
{showAddNew && (
<Box
Expand Down
29 changes: 19 additions & 10 deletions src/utils/useLocationState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export const useLocationState = (open: boolean, onClose: () => void) => {
const [selectedBlockCode, setSelectedBlockCode] = useState("");
const [selectedCenterCode, setSelectedCenterCode] = useState("");
const [selectedBlockFieldId, setSelectedBlockFieldId] = useState("");

const [BlockFieldId, setBlockFieldId] = useState("");
const [StateFieldId, setStateFieldId] = useState("");
const [DistrctFieldId, setDistrictFieldId] = useState("");

const handleStateChangeWrapper = useCallback(async (
selectedNames: string[],
Expand All @@ -46,7 +48,8 @@ export const useLocationState = (open: boolean, onClose: () => void) => {
fieldName: "districts",
};
const response = await getStateBlockDistrictList(object);
const result = response?.result;
setDistrictFieldId(response?.result?.fieldId)
const result = response?.result?.values;
setDistricts(result);
} catch (error) {
console.log(error);
Expand All @@ -68,7 +71,9 @@ export const useLocationState = (open: boolean, onClose: () => void) => {
fieldName: "blocks",
};
const response = await getStateBlockDistrictList(object);
const result = response?.result;
setBlockFieldId(response?.result?.fieldId)

const result = response?.result?.values;
setBlocks(result);
} catch (error) {
console.log(error);
Expand All @@ -86,15 +91,18 @@ export const useLocationState = (open: boolean, onClose: () => void) => {
"limit":200,
"offset": 0,
"filters": {
"type": "COHORT",
"type": "BLOCK",
"status": [
"active"
],
"states": selectedStateCode,
"districts": selectedDistrictCode,
"blocks": selectedCodes[0]
// "states": selectedStateCode,
// "districts": selectedDistrictCode,
// "blocks": selectedCodes[0]
name:selected[0]
}
};
const response2 = await getCenterList(object);

console.log(selected)
const getBlockIdObject={
"limit": 200,
Expand All @@ -110,7 +118,7 @@ export const useLocationState = (open: boolean, onClose: () => void) => {
setSelectedBlockFieldId(response?.result?.results?.cohortDetails[0].cohortId)
console.log(response?.result?.results?.cohortDetails[0].cohortId)
// const result = response?.result?.cohortDetails;
const dataArray=response?.result?.results?.cohortDetails;
const dataArray=response2?.result?.results?.cohortDetails;

const cohortInfo = dataArray?.map((item: any) => ({
cohortId: item?.cohortId,
Expand Down Expand Up @@ -186,7 +194,8 @@ export const useLocationState = (open: boolean, onClose: () => void) => {
fieldName: "states",
};
const response = await getStateBlockDistrictList(object);
const result = response?.result;
setStateFieldId(response?.result?.fieldId)
const result = response?.result?.values;
setStates(result);
console.log(typeof states);
} catch (error) {
Expand All @@ -200,7 +209,7 @@ export const useLocationState = (open: boolean, onClose: () => void) => {
return {
states, districts, blocks, allCenters, isMobile, isMediumScreen,
selectedState, selectedStateCode, selectedDistrict, selectedDistrictCode,
selectedCenter, dynamicForm, selectedBlock, selectedBlockCode,dynamicFormForBlock,
selectedCenter, dynamicForm, selectedBlock, selectedBlockCode,dynamicFormForBlock,BlockFieldId, DistrctFieldId, StateFieldId,
handleStateChangeWrapper, handleDistrictChangeWrapper, handleBlockChangeWrapper, handleCenterChangeWrapper,selectedCenterCode, selectedBlockFieldId
};
};

0 comments on commit 61b27c6

Please sign in to comment.