diff --git a/public/locales/en/common.json b/public/locales/en/common.json index d088ae6c..af778485 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -31,7 +31,7 @@ "CANCEL": "Cancel", "ARE_YOU_SURE_DELETE": "There are {{block}} Active blocks in this district you cannot delete it.", "NO_ACTIVE_BLOCKS_DELETE": "There are no active blocks in this district. Do you want to delete it?", - "ARE_YOU_SURE_DELETE_BLOCK": "There are Active centers in this block you cannot delete it", + "ARE_YOU_SURE_DELETE_BLOCK": "There are {{centers}} Active centers in this block you cannot delete it", "NO_ACTIVE_CENTERS_DELETE": "There are no active centers in this block. Do you want to delete it?", "CONFIRM_DELETE": "Confirm Delete", "ADD_STATE": "Add New State", @@ -212,7 +212,7 @@ }, "MASTER": { - "STATE": "State", + "STATE": "States", "STATE_NAMES": "State Name", "SORT": "Sort", "DISTRICT_NAMES": "District Name", diff --git a/src/components/AddBlockModal.tsx b/src/components/AddBlockModal.tsx index 387cb366..30fbeb71 100644 --- a/src/components/AddBlockModal.tsx +++ b/src/components/AddBlockModal.tsx @@ -53,7 +53,7 @@ export const AddBlockModal: React.FC = ({ const [errors, setErrors] = useState>({}); const [districts, setDistricts] = useState< - { value: string; label: string; cohortId: string | null}[] + { value: string; label: string; cohortId: string | null }[] >([]); const [districtsOptionRead, setDistrictsOptionRead] = useState([]); @@ -185,9 +185,11 @@ export const AddBlockModal: React.FC = ({ value: string, requiredMessage: string ) => { - if (!value) return requiredMessage; - if (field !== "controllingField" && !/^[a-zA-Z\s]+$/.test(value)) + if (!value) return null; + + if (field !== "controllingField" && !/^[a-zA-Z\s]+$/.test(value)) { return t("COMMON.INVALID_TEXT"); + } const isUnique = (fieldName: string, value: string) => { return true; @@ -215,35 +217,7 @@ export const AddBlockModal: React.FC = ({ setFormData((prev) => ({ ...prev, [field]: value })); - let errorMessage: string | null = null; - - if (field === "name") { - errorMessage = validateField( - field, - value, - t("COMMON.BLOCK_NAME_REQUIRED") - ); - } else if (field === "value") { - errorMessage = validateField( - field, - value, - t("COMMON.BLOCK_CODE_REQUIRED") - ); - } else if (field === "controllingField") { - errorMessage = validateField( - field, - value, - t("COMMON.DISTRICT_NAME_REQUIRED") - ); - - const selectedDistrict = districts.find( - (district) => district.value === value - ); - setCohortIdAddNewDropdown(selectedDistrict?.cohortId || null); - - console.log("Selected District:", selectedDistrict); - console.log("Cohort ID Set:", selectedDistrict?.cohortId); - } + let errorMessage: string | null = validateField(field, value, ""); setErrors((prev) => ({ ...prev, @@ -253,21 +227,24 @@ export const AddBlockModal: React.FC = ({ const validateForm = () => { const newErrors = { - name: validateField( - "name", - formData.name, - t("COMMON.BLOCK_NAME_REQUIRED") - ), - value: validateField( - "value", - formData.value, - t("COMMON.BLOCK_CODE_REQUIRED") - ), - controllingField: validateField( - "controllingField", - formData.controllingField, - t("COMMON.DISTRICT_NAME_REQUIRED") - ), + name: + validateField("name", formData.name, t("COMMON.BLOCK_NAME_REQUIRED")) || + (!formData.name ? t("COMMON.BLOCK_NAME_REQUIRED") : null), + value: + validateField( + "value", + formData.value, + t("COMMON.BLOCK_CODE_REQUIRED") + ) || (!formData.value ? t("COMMON.BLOCK_CODE_REQUIRED") : null), + controllingField: + validateField( + "controllingField", + formData.controllingField, + t("COMMON.DISTRICT_NAME_REQUIRED") + ) || + (!formData.controllingField + ? t("COMMON.DISTRICT_NAME_REQUIRED") + : null), }; setErrors(newErrors); @@ -293,7 +270,7 @@ export const AddBlockModal: React.FC = ({ formData.controllingField, currentCohortId, fieldId, - districtId, + districtId ); setFormData({ @@ -323,6 +300,13 @@ export const AddBlockModal: React.FC = ({ e as React.ChangeEvent ) } + MenuProps={{ + PaperProps: { + sx: { + maxHeight: 400, + }, + }, + }} fullWidth displayEmpty variant="outlined" diff --git a/src/components/AddDistrictModal.tsx b/src/components/AddDistrictModal.tsx index c91491a2..87e081ce 100644 --- a/src/components/AddDistrictModal.tsx +++ b/src/components/AddDistrictModal.tsx @@ -93,9 +93,9 @@ const AddDistrictModal: React.FC = ({ value: initialValues.value ?? "", controllingField: initialValues.controllingField ?? stateCode, }); - setErrors({}); + setErrors({}); }, [initialValues, stateCode]); - + const isValidName = (input: string) => /^[a-zA-Z]+(?:\s[a-zA-Z]+)*$/.test(input); @@ -112,31 +112,14 @@ const AddDistrictModal: React.FC = ({ setFormData((prev) => ({ ...prev, [field]: value })); - if (value === "") { - setErrors((prev) => ({ - ...prev, - [field]: t( - field === "name" - ? "COMMON.DISTRICT_NAME_REQUIRED" - : field === "controllingField" - ? "COMMON.STATE_NAME_REQUIRED" - : "COMMON.CODE_REQUIRED" - ), - })); - } else if (field === "name" && !isValidName(value.trim())) { - setErrors((prev) => ({ ...prev, [field]: t("COMMON.INVALID_INPUT") })); - } else if (field === "value" && !isValidCode(value)) { - setErrors((prev) => ({ ...prev, [field]: t("COMMON.INVALID_TEXT") })); - } else { - setErrors((prev) => ({ ...prev, [field]: null })); - } + setErrors((prev) => ({ ...prev, [field]: null })); }; const validateForm = () => { const newErrors: { name?: string; value?: string } = {}; if (!formData.name) { - newErrors.name = t("COMMON.STATE_NAME_REQUIRED"); + newErrors.name = t("COMMON.DISTRICT_NAME_REQUIRED"); } else if (!isValidName(formData.name.trim())) { newErrors.name = t("COMMON.INVALID_TEXT"); } diff --git a/src/components/layouts/sidebar/MenuItems.js b/src/components/layouts/sidebar/MenuItems.js index 6b39451d..70fb88db 100644 --- a/src/components/layouts/sidebar/MenuItems.js +++ b/src/components/layouts/sidebar/MenuItems.js @@ -48,15 +48,15 @@ const Menuitems = [ // href: "/", subOptions: [ { - title: "State", + title: "MASTER.STATE", href: "/state", }, { - title: "District", + title: "MASTER.DISTRICTS", href: "/district", }, { - title: "Block", + title: "MASTER.BLOCKS", href: "/block", }, ], diff --git a/src/pages/block.tsx b/src/pages/block.tsx index 81bbbd08..6bcf7bb3 100644 --- a/src/pages/block.tsx +++ b/src/pages/block.tsx @@ -48,6 +48,7 @@ type DistrictDetail = { }; type BlockDetail = { + code: any; parentId(parentId: any): unknown; status: Status; cohortId(cohortId: any): unknown; @@ -114,6 +115,7 @@ const Block: React.FC = () => { const [cohortIds, setCohortIds] = useState([]); const [selectedCohortId, setSelectedCohortId] = useState(null); const [parentIdBlock, setParentIdBlock] = useState(null); + const [showAllBlocks, setShowAllBlocks] = useState("All"); useEffect(() => { const fetchUserDetail = async () => { @@ -175,6 +177,7 @@ const Block: React.FC = () => { const getFilteredCohortData = async () => { try { + setLoading(true); const reqParams = { limit: 0, offset: 0, @@ -225,8 +228,10 @@ const Block: React.FC = () => { } console.log("cohortIds", selectedCohortId); setDistrictData(filteredDistrictData); + setLoading(false); } catch (error) { console.error("Error fetching and filtering cohort districts", error); + } finally { setLoading(false); } }; @@ -238,7 +243,6 @@ const Block: React.FC = () => { const fetchBlocks = async () => { try { - setLoading(true); const response = await getBlocksForDistricts({ controllingfieldfk: selectedDistrict || "", fieldName: "blocks", @@ -326,6 +330,7 @@ const Block: React.FC = () => { console.log("Filtered Block Data:", filteredBlockData); setBlockData(filteredBlockData); + setShowAllBlocks(filteredBlockData) const totalCount = filteredBlockData.length; setPaginationCount(totalCount); @@ -347,7 +352,7 @@ const Block: React.FC = () => { limit: 0, offset: 0, filters: { - parentId: parentIdBlock, //cohort id of block + blocks: parentIdBlock, //cohort id of block }, }; @@ -407,12 +412,12 @@ const Block: React.FC = () => { dataType: DataType.String, width: "130", }, - { - key: "status", - title: t("Status"), - dataType: DataType.String, - width: "130", - }, + // { + // key: "status", + // title: t("Status"), + // dataType: DataType.String, + // width: "130", + // }, { key: "createdBy", title: t("MASTER.CREATED_BY"), @@ -461,6 +466,9 @@ const Block: React.FC = () => { const handleDistrictChange = async (event: SelectChangeEvent) => { const selectedDistrict = event.target.value; setSelectedDistrict(selectedDistrict); + setShowAllBlocks("") + console.log("selectedDistrict", selectedDistrict); + const selectedDistrictData = districtData.find( (district) => district.value === selectedDistrict @@ -503,7 +511,7 @@ const Block: React.FC = () => { setCohortIdForDelete(rowData.cohortId); setConfirmationDialogOpen(true); - setParentIdBlock(rowData.parentId as any | null); + setParentIdBlock(rowData.code as any | null); const blockValue = rowData.value; setBlockValueForDelete(blockValue); }; @@ -598,7 +606,7 @@ const Block: React.FC = () => { showStateDropdown: false, userType: t("MASTER.BLOCKS"), searchPlaceHolder: t("MASTER.SEARCHBAR_PLACEHOLDER_BLOCK"), - showFilter: false, + showFilter: true, }; const handleAddNewBlock = () => { @@ -767,7 +775,9 @@ const Block: React.FC = () => { modalOpen={confirmationDialogOpen} message={ countOfCenter > 0 - ? t("COMMON.ARE_YOU_SURE_DELETE_BLOCK") + ? t("COMMON.ARE_YOU_SURE_DELETE_BLOCK", { + centers: `${countOfCenter}`, + }) : t("COMMON.NO_ACTIVE_CENTERS_DELETE") } handleAction={handleConfirmDelete} @@ -804,7 +814,7 @@ const Block: React.FC = () => { gap: 3, marginTop: 2, "@media (max-width: 580px)": { - width: "100%", + width: "90%", flexDirection: "column", }, }} @@ -836,6 +846,7 @@ const Block: React.FC = () => { width: "25%", "@media (max-width: 580px)": { width: "100%", + marginLeft: 2, }, }} > @@ -850,11 +861,22 @@ const Block: React.FC = () => { id="district-select" value={selectedDistrict} onChange={handleDistrictChange} + MenuProps={{ + PaperProps: { + sx: { + maxHeight: 400, + }, + }, + }} > + {t("COMMON.ALL")} {districtData.map((districtDetail) => ( {transformLabels(districtDetail.label)} @@ -864,16 +886,7 @@ const Block: React.FC = () => { - {loading ? ( - - - - ) : blockData.length > 0 ? ( + {filteredCohortOptionData().length > 0 ? ( { pagination={pagination} onDelete={handleDelete} extraActions={[]} - noDataMessage={t("COMMON.BLOCKS_NOT_FOUND")} /> ) : ( - - - {t("COMMON.BLOCKS_NOT_FOUND")} - - + !loading && ( + + + {t("COMMON.BLOCKS_NOT_FOUND")} + + + ) )} diff --git a/src/pages/district.tsx b/src/pages/district.tsx index 0389bc26..bbd2914e 100644 --- a/src/pages/district.tsx +++ b/src/pages/district.tsx @@ -28,7 +28,6 @@ import { createCohort, getCohortList, } from "@/services/CohortService/cohortService"; -import useStore from "@/store/store"; import { getUserDetailsInfo } from "@/services/UserList"; import { getCohortList as getMyCohorts } from "@/services/GetCohortList"; @@ -152,6 +151,7 @@ const District: React.FC = () => { const response: any = await getMyCohorts(userId); const cohortData = response?.result?.cohortData; + console.log("cohortData", cohortData); if (Array.isArray(cohortData)) { const stateCohort = cohortData.find( (cohort) => cohort.type === "STATE" @@ -178,6 +178,7 @@ const District: React.FC = () => { const getFilteredCohortData = async () => { try { + setLoading(true); const reqParams = { limit: 0, offset: 0, @@ -232,6 +233,7 @@ const District: React.FC = () => { const totalCount = filteredDistrictData.length; setPaginationCount(totalCount); setPageCount(Math.ceil(totalCount / pageLimit)); + setLoading(false) } catch (error) { console.error("Error fetching and filtering cohort districts", error); setDistrictData([]); diff --git a/src/pages/state.tsx b/src/pages/state.tsx index c69a14d4..32832c47 100644 --- a/src/pages/state.tsx +++ b/src/pages/state.tsx @@ -77,7 +77,6 @@ const State: React.FC = () => { const [stateDataOption, setStateDataOptinon] = useState([]); const [stateCodArrray, setStateCodeArr] = useState([]); const [stateNameArray, setStateNameArr] = useState([]); - const setPid = useStore((state) => state.setPid); const columns = [ { key: "label", title: t("MASTER.STATE"), width: "160" }, { key: "value", title: t("MASTER.CODE"), width: "160" }, diff --git a/src/store/store.js b/src/store/store.js index 67d96d87..5ac7e49e 100644 --- a/src/store/store.js +++ b/src/store/store.js @@ -8,15 +8,15 @@ const useStore = create( // state: "", // district: "", // block: "", - setPid: (newPid) => set((state) => ({ pid: newPid })), + // setPid: (newPid) => set((state) => ({ pid: newPid })), // setPid: (newPid) => set((state) => ({ pid: newPid })), // setPid: (newPid) => set((state) => ({ pid: newPid })), // setPid: (newPid) => set((state) => ({ pid: newPid })), }), - { - name: "adminApp", - getStorage: () => localStorage, - } + // { + // name: "adminApp", + // getStorage: () => localStorage, + // } ) );