Commit b0e3ead6 authored by Imane Misrar's avatar Imane Misrar
Browse files

feat(PreviousExchangesTab): Add switch to only show exchanges with feedback on univ page

Relates to #176
parent 43b83673
......@@ -101,6 +101,7 @@ class ExchangeFeedbackViewSet(EssentialModuleViewSet):
"university",
"exchange__student_major",
"exchange__student_minor",
"untouched"
)
required_filterset_fields = ("university",)
pagination_class = CustomPagination
......@@ -17,6 +17,9 @@ import withNetworkWrapper, {
NetWrapParam
} from "../../../hoc/withNetworkWrapper";
import Switch from "@material-ui/core/Switch";
import FormControlLabel from "@material-ui/core/FormControlLabel";
const undefinedVal = uuid();
const useStyles = makeStyles(theme => ({
......@@ -40,7 +43,9 @@ function PreviousExchangesTab({
setMajor,
setMinor,
goToPage,
univMajorMinors
univMajorMinors,
showUntouched,
setShowUntouched
}) {
const classes = useStyles();
......@@ -102,6 +107,24 @@ function PreviousExchangesTab({
</FormControl>
</>
)}
<FormControlLabel
control={
<Switch
checked={showUntouched}
onChange={() => {
setShowUntouched(!showUntouched);
goToPage(1);
}}
color="primary"
/>
}
label={
showUntouched === true
? "Afficher tous les échanges."
: "Afficher que les départs avec retours."
}
/>
</form>
<PaginatedData
......@@ -138,16 +161,17 @@ const buildExchangesParams = (
univId,
page = 1,
major = undefinedVal,
minor = undefinedVal
minor = undefinedVal,
showUntouched = true
) => {
const params = RequestParams.Builder.withQueryParam("university", univId)
.withQueryParam("page_size", 8)
.withQueryParam("page", page);
if (typeof major !== "undefined" && major !== undefinedVal)
params.withQueryParam("exchange__student_major", major);
if (typeof minor !== "undefined" && minor !== undefinedVal)
params.withQueryParam("exchange__student_minor", minor);
if (showUntouched === false) params.withQueryParam("untouched", false);
return params.build();
};
......@@ -164,13 +188,15 @@ const ConnectedComp = compose(
props.univId,
props.page,
props.major,
props.minor
props.minor,
props.showUntouched
),
propTypes: {
univId: PropTypes.number.isRequired,
page: PropTypes.number.isRequired,
major: PropTypes.string.isRequired,
minor: PropTypes.string.isRequired
minor: PropTypes.string.isRequired,
showUntouched: PropTypes.bool.isRequired
}
}),
new NetWrapParam("univMajorMinors", "all", {
......@@ -189,6 +215,7 @@ export default () => {
const [major, setMajor] = useState(undefinedVal);
const [minor, setMinor] = useState(undefinedVal);
const [showUntouched, setShowUntouched] = useState(false);
// Reset minors on majors change
useEffect(() => {
......@@ -203,6 +230,8 @@ export default () => {
setMajor={setMajor}
minor={minor}
setMinor={setMinor}
showUntouched={showUntouched}
setShowUntouched={setShowUntouched}
/>
);
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment