Skip to content

Commit

Permalink
Merge pull request #1437 from jadmsaadaot/TRACK-task#1282-C
Browse files Browse the repository at this point in the history
Complete function of toggle component
  • Loading branch information
jadmsaadaot authored Dec 11, 2023
2 parents 0593786 + 1271351 commit 0d8ad6b
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 10 deletions.
1 change: 1 addition & 0 deletions epictrack-api/src/api/models/dashboard_seach_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ class WorkplanDashboardSearchOptions: # pylint: disable=too-many-instance-attri
regions: Optional[List[int]]
project_types: Optional[List[int]]
work_types: Optional[List[int]]
staff_id: Optional[int]
8 changes: 3 additions & 5 deletions epictrack-api/src/api/models/work.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ def filter_by_search_criteria(cls, query, search_filters: WorkplanDashboardSearc
if not search_filters:
return query

query = cls._filter_by_staff_id(query, search_filters.staff_id)

query = cls._filter_by_search_text(query, search_filters.text)

query = cls._filter_by_eao_team(query, search_filters.teams)
Expand All @@ -156,11 +158,7 @@ def filter_by_search_criteria(cls, query, search_filters: WorkplanDashboardSearc
@classmethod
def _filter_by_staff_id(cls, query, staff_id):
if staff_id:
subquery = (
cls.query
.filter(StaffWorkRole.staff_id == staff_id)
.exists()
)
subquery = exists().where(and_(Work.id == StaffWorkRole.work_id, StaffWorkRole.staff_id == staff_id))
query = query.filter(subquery)
return query

Expand Down
1 change: 1 addition & 0 deletions epictrack-api/src/api/resources/work.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def get():
project_types=list(map(int, args.getlist('project_types[]'))),
work_types=list(map(int, args.getlist('work_types[]'))),
text=args.get('text', None, str),
staff_id=args.get('staff_id', None, int),
)
works = WorkService.fetch_all_work_plans(pagination_options, search_options)
return jsonify(works), HTTPStatus.OK
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,44 @@
import React from "react";
import { FormControlLabel, Stack, Switch } from "@mui/material";
import React, { useContext, useEffect, useState } from "react";
import { Stack } from "@mui/material";
import { useAppSelector } from "../../../hooks";
import { ETCaption2 } from "../../shared";
import { Palette } from "../../../styles/theme";
import { CustomSwitch } from "../../shared/CustomSwitch";
import staffService from "../../../services/staffService/staffService";
import { MyWorkplansContext } from "../MyWorkPlanContext";

export const AssigneeToggle = () => {
const user = useAppSelector((state) => state.user.userDetail);
const { setSearchOptions } = useContext(MyWorkplansContext);

const [isUsersWorkPlans, setIsUsersWorkPlans] = useState(false);
const [staffId, setStaffId] = useState<number | null>(null);
const [loading, setLoading] = useState(true);

const getStaffInfo = async () => {
if (!user.email) return;

try {
const response = await staffService.getByEmail(user.email);
setStaffId(response.data.id);
setLoading(false);
} catch (error) {
console.log(error);
}
};

useEffect(() => {
getStaffInfo();
}, [isUsersWorkPlans]);

const handleToggleChange = (checked: boolean) => {
setIsUsersWorkPlans(checked);
setSearchOptions((prev) => ({
...prev,
staff_id: checked ? staffId : null,
}));
};

const [isUsersWorkPlans, setIsUsersWorkPlans] = React.useState(false);
return (
<Stack direction="row" spacing={1} alignItems={"center"}>
<>
Expand All @@ -20,7 +50,8 @@ export const AssigneeToggle = () => {
<CustomSwitch
color="primary"
checked={isUsersWorkPlans}
onChange={() => setIsUsersWorkPlans(!isUsersWorkPlans)}
onChange={() => handleToggleChange(!isUsersWorkPlans)}
disabled={loading}
/>
</Stack>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface WorkPlanSearchOptions {
project_types: string[];
work_types: string[];
text: string;
staff_id: number | null;
}

const PAGE_SIZE = 6;
Expand All @@ -52,6 +53,7 @@ export const MyWorkplansProvider = ({
project_types: [],
work_types: [],
text: "",
staff_id: null,
});

const fetchWorkplans = async (page: number, shouldAppend = false) => {
Expand Down
3 changes: 2 additions & 1 deletion epictrack-web/src/services/staffService/staffService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import http from "../../apiManager/http-request-handler";
import Endpoints from "../../constants/api-endpoint";
import { Staff } from "../../models/staff";
import { MasterBase } from "../../models/type";
import ServiceBase from "../common/serviceBase";

Expand Down Expand Up @@ -42,7 +43,7 @@ class StaffService implements ServiceBase {
}

async getByEmail(email: string) {
return await http.GetRequest(Endpoints.Staffs.STAFFS + `/${email}`);
return await http.GetRequest<Staff>(Endpoints.Staffs.STAFFS + `/${email}`);
}
}

Expand Down

0 comments on commit 0d8ad6b

Please sign in to comment.