Skip to content

Commit

Permalink
Merge pull request #190 from rahulg1254/admin-master
Browse files Browse the repository at this point in the history
Task #226364 feat: Fixed all select dropdown issue on pagination change and hide on edit for all
  • Loading branch information
itsvick authored Sep 4, 2024
2 parents 7b91c92 + 168e475 commit 802c8d0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 47 deletions.
71 changes: 32 additions & 39 deletions src/components/AddBlockModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,6 @@ export const AddBlockModal: React.FC<AddBlockModalProps> = ({
const currentCohortId: any = cohortIdAddNewDropdown;
console.log("Cohort ID on Submit:", currentCohortId);

if (!currentCohortId) {
setErrors((prev) => ({
...prev,
controllingField: t("COMMON.DISTRICT_NOT_VALID"),
}));
return;
}

onSubmit(
formData.name,
formData.value,
Expand Down Expand Up @@ -305,38 +297,39 @@ export const AddBlockModal: React.FC<AddBlockModalProps> = ({
<DialogTitle sx={{ fontSize: "14px" }}>{dialogTitle}</DialogTitle>
<Divider />
<DialogContent>
<Select
value={formData.controllingField}
onChange={(e) =>
handleChange("controllingField")(
e as React.ChangeEvent<HTMLInputElement>
)
}
MenuProps={{
PaperProps: {
sx: {
maxHeight: 400,
{isEditing && !(formData.controllingField === "All") && (
<Select
value={formData.controllingField}
onChange={(e) =>
handleChange("controllingField")(
e as React.ChangeEvent<HTMLInputElement>
)
}
MenuProps={{
PaperProps: {
sx: {
maxHeight: 400,
},
},
},
}}
fullWidth
displayEmpty
variant="outlined"
margin="dense"
error={!!errors.controllingField}
disabled={isEditing}
>
<MenuItem value="">{t("COMMON.SELECT_DISTRICT")}</MenuItem>
{districts.length > 0 ? (
districts.map((district: any) => (
<MenuItem key={district.value} value={district.value}>
{transformLabels(district.label)}
</MenuItem>
))
) : (
<MenuItem disabled>{t("COMMON.NO_DISTRICTS")}</MenuItem>
)}
</Select>
}}
fullWidth
displayEmpty
variant="outlined"
margin="dense"
disabled={isEditing}
>
<MenuItem value="">{t("COMMON.SELECT_DISTRICT")}</MenuItem>
{districts.length > 0 ? (
districts.map((district: any) => (
<MenuItem key={district.value} value={district.value}>
{transformLabels(district.label)}
</MenuItem>
))
) : (
<MenuItem disabled>{t("COMMON.NO_DISTRICTS")}</MenuItem>
)}
</Select>
)}
{errors.controllingField && (
<Typography variant="caption" color="error">
{errors.controllingField}
Expand Down
23 changes: 15 additions & 8 deletions src/pages/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ const Block: React.FC = () => {
const [showAllBlocks, setShowAllBlocks] = useState("All");
const [statusValue, setStatusValue] = useState(Status.ACTIVE);
const [pageSize, setPageSize] = React.useState<string | number>(10);
const [isFirstVisit, setIsFirstVisit] = useState(true);

const [filters, setFilters] = useState({
name: searchKeyword,
Expand Down Expand Up @@ -234,10 +235,15 @@ const Block: React.FC = () => {
.filter((district: { label: any }) =>
districtNameArr.includes(district.label)
);
if (filteredDistrictData.length > 0) {
setSelectedDistrict(filteredDistrictData[0].value);
if (isFirstVisit) {
if (
filteredDistrictData.length > 0 &&
selectedDistrict !== t("COMMON.ALL")
) {
setSelectedDistrict(filteredDistrictData[0].value);
}
setIsFirstVisit(false);
}
console.log("cohortIds", selectedCohortId);
setDistrictData(filteredDistrictData);
setLoading(false);
} catch (error) {
Expand All @@ -250,7 +256,7 @@ const Block: React.FC = () => {
if (stateCode) {
getFilteredCohortData();
}
}, [searchKeyword, pageLimit, pageOffset, stateCode]);
}, [isFirstVisit,searchKeyword, pageLimit, pageOffset, stateCode]);

const fetchBlocks = async () => {
try {
Expand Down Expand Up @@ -409,14 +415,13 @@ const Block: React.FC = () => {
const startIndex = pageOffset * pageLimit;
const endIndex = startIndex + pageLimit;

const transformedData = blockData.map((item) => ({
const transformedData = blockData?.map((item) => ({
...item,
label: transformLabels(item.label),
}));

return transformedData.slice(startIndex, endIndex);
};

const columns = [
{
key: "name",
Expand Down Expand Up @@ -482,10 +487,12 @@ const Block: React.FC = () => {
};

const handleDistrictChange = async (event: SelectChangeEvent<string>) => {
setPageOffset(Numbers.ZERO);
setPageCount(Numbers.ONE);

const selectedDistrict = event.target.value;
setSelectedDistrict(selectedDistrict);
setShowAllBlocks("");
console.log("selectedDistrict", selectedDistrict);

const selectedDistrictData = districtData.find(
(district) => district.value === selectedDistrict
Expand Down Expand Up @@ -513,7 +520,7 @@ const Block: React.FC = () => {
const initialValues: StateDetail = {
name: rowData.name || "",
value: rowData.code || "",
selectedDistrict: selectedDistrict || "",
selectedDistrict: selectedDistrict || "All",
controllingField: "",
block: "",
label: "",
Expand Down

0 comments on commit 802c8d0

Please sign in to comment.