Updated the MasterCorporate and Corporate pages to allow to have Assignments
This commit is contained in:
@@ -2,7 +2,7 @@ import {Assignment} from "@/interfaces/results";
|
||||
import axios from "axios";
|
||||
import {useEffect, useState} from "react";
|
||||
|
||||
export default function useAssignments({assigner, assignees}: {assigner?: string; assignees?: string}) {
|
||||
export default function useAssignments({assigner, assignees, corporate}: {assigner?: string; assignees?: string; corporate?: string}) {
|
||||
const [assignments, setAssignments] = useState<Assignment[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [isError, setIsError] = useState(false);
|
||||
@@ -10,12 +10,13 @@ export default function useAssignments({assigner, assignees}: {assigner?: string
|
||||
const getData = () => {
|
||||
setIsLoading(true);
|
||||
axios
|
||||
.get<Assignment[]>("/api/assignments")
|
||||
.then((response) => {
|
||||
.get<Assignment[]>(!corporate ? "/api/assignments" : `/api/assignments/corporate?id=${corporate}`)
|
||||
.then(async (response) => {
|
||||
if (assigner) {
|
||||
setAssignments(response.data.filter((a) => a.assigner === assigner));
|
||||
return;
|
||||
}
|
||||
|
||||
if (assignees) {
|
||||
setAssignments(response.data.filter((a) => a.assignees.filter((x) => assignees.includes(x)).length > 0));
|
||||
return;
|
||||
@@ -26,7 +27,7 @@ export default function useAssignments({assigner, assignees}: {assigner?: string
|
||||
.finally(() => setIsLoading(false));
|
||||
};
|
||||
|
||||
useEffect(getData, [assignees, assigner]);
|
||||
useEffect(getData, [assignees, assigner, corporate]);
|
||||
|
||||
return {assignments, isLoading, isError, reload: getData};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user