Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed Filter Component Structure #165

Open
wants to merge 1 commit into
base: NEW-UI
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 67 additions & 4 deletions src/components/Home/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ const Home = () => {
);
const [pin, setPin] = useState("");
const [formattedDate, setFormattedDate] = useState("");
const [filterValue, setfilterValue] = useState("ALL");
const [filtervalueAge, setfiltervalueAge] = useState("ALL");
const [filtervalueFare, setfiltervalueFare] = useState("ALL");
const [filtervalueVaccine, setfiltervalueVaccine] = useState("ALL");

const [selectedDate, setSelectedDate] = useState(new Date());
const [vaccineData, setVaccineData] = useState([]);
const [pinCodeSearch, setPinCodeSearch] = useState(false);
Expand Down Expand Up @@ -68,8 +73,10 @@ const Home = () => {

const onStateChange = async (e) => {
const stateCode = e.target.value;

setDistricts([]);
setVaccineData([]);

setPinCodeSearch(false);

const url =
Expand Down Expand Up @@ -157,7 +164,18 @@ const Home = () => {
});
}
};

const filterValuechange = (e) => {
setfilterValue(e.target.value);
};
const filterValueVaccineChange = (e) => {
setfiltervalueVaccine(e.target.value);
};
const filterValueAgeChange = (e) => {
setfiltervalueAge(e.target.value);
};
const filterValueFareChange = (e) => {
setfiltervalueFare(e.target.value);
};
return (
<>
<Container maxWidth="md">
Expand Down Expand Up @@ -403,8 +421,47 @@ const Home = () => {
</MuiPickersUtilsProvider>
</div>
) : null}

{loading === true ? (
{vaccineData.length > 0 ? (
<div style={{ display: "flex", justifyContent: "center" }}>
<FormControl style={{ width: "150px" }}>
<InputLabel value="ALL">FILTER</InputLabel>
<Select onChange={filterValuechange}>
<MenuItem value="ALL">ALL</MenuItem>
<MenuItem value="VACCINE_TYPE">VACCINE TYPE</MenuItem>
<MenuItem value="AGE_GROUP">AGE GROUP</MenuItem>
<MenuItem value="FARE_TYPE">FARE TYPE</MenuItem>
</Select>
</FormControl>
{filterValue === "AGE_GROUP" ? (
<FormControl style={{ width: "150px", marginLeft: "20px" }}>
<InputLabel value="ALL">AGE</InputLabel>
<Select onChange={filterValueAgeChange}>
<MenuItem value="18">18-45</MenuItem>
<MenuItem value="45">ABOVE 45</MenuItem>
</Select>
</FormControl>
) : filterValue === "FARE_TYPE" ? (
<FormControl style={{ width: "150px", marginLeft: "20px" }}>
<InputLabel value="ALL">MINIMUM FARE</InputLabel>
<Select onChange={filterValueFareChange}>
<MenuItem value="Free">FREE</MenuItem>
<MenuItem value="Paid">PAID</MenuItem>
</Select>
</FormControl>
) : filterValue === "VACCINE_TYPE" ? (
<FormControl style={{ width: "150px", marginLeft: "20px" }}>
<InputLabel value="ALL">VACCINE</InputLabel>
<Select onChange={filterValueVaccineChange}>
<MenuItem value="COVISHIELD">COVISHEILD</MenuItem>
<MenuItem value="COVAXIN">COVAXIN</MenuItem>
</Select>
</FormControl>
) : (
<></>
)}
</div>
) : null}
{vaccineData.length === 0 && loading === true ? (
<div
style={{
display: "flex",
Expand All @@ -415,7 +472,13 @@ const Home = () => {
<CircularProgress />
</div>
) : (
<VaccineDataMain vaccineData={vaccineData} />
<VaccineDataMain
vaccineData={vaccineData}
filterValue={filterValue}
filtervalueAge={filtervalueAge}
filtervalueFare={filtervalueFare}
filtervalueVaccine={filtervalueVaccine}
/>
)}
<NullState
toSearchValue={toSearchValue}
Expand Down
35 changes: 32 additions & 3 deletions src/components/VaccineData/VaccineDataMain.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@
import VaccineDataSingle from "./SingleVaccineData/VaccineDataSingle";

const VaccineDataMain = ({ vaccineData }) => {
const VaccineDataMain = ({
vaccineData,
filterValue,
filtervalueAge,
filtervalueFare,
filtervalueVaccine,
}) => {
return (
<>
{vaccineData?.map((vaccine) => {
return <VaccineDataSingle key={vaccine.center_id} {...vaccine} />;
return filterValue === "ALL" ? (
<VaccineDataSingle key={vaccine.center_id} {...vaccine} />
) : filterValue === "VACCINE_TYPE" &&
filtervalueVaccine === vaccine.vaccine ? (
(console.info(vaccine.vaccine),
(<VaccineDataSingle key={vaccine.center_id} {...vaccine} />))
) : null;
})}

{vaccineData?.map((vaccine) => {
return filterValue === "ALL" ? (
<VaccineDataSingle key={vaccine.center_id} {...vaccine} />
) : filterValue === "FARE_TYPE" &&
filtervalueFare === vaccine.fee_type ? (
<VaccineDataSingle key={vaccine.center_id} {...vaccine} />
) : null;
})}

{vaccineData?.map((vaccine) => {
return filterValue === "ALL" ? (
<VaccineDataSingle key={vaccine.center_id} {...vaccine} />
) : filterValue === "AGE_GROUP" &&
parseInt(filtervalueAge) === vaccine.min_age_limit ? (
<VaccineDataSingle key={vaccine.center_id} {...vaccine} />
) : null;
})}
</>
);
};

export default VaccineDataMain;