From 6613ce158162ec893334bd1562d1b133b54f851e Mon Sep 17 00:00:00 2001 From: Magnus Dahl <55053871+Dahly96@users.noreply.github.com> Date: Wed, 20 Nov 2024 10:51:54 +0100 Subject: [PATCH] added icons for agreementstatus on consultants (#538) Co-authored-by: md --- .../Staffing/DetailedBookingRows.tsx | 55 ++++++++++++++++++- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/Staffing/DetailedBookingRows.tsx b/frontend/src/components/Staffing/DetailedBookingRows.tsx index e9414073..50044701 100644 --- a/frontend/src/components/Staffing/DetailedBookingRows.tsx +++ b/frontend/src/components/Staffing/DetailedBookingRows.tsx @@ -14,11 +14,22 @@ import { } from "@/components/Staffing/helpers/utils"; import { FilteredContext } from "@/hooks/ConsultantFilterProvider"; import { usePathname } from "next/navigation"; -import { Edit3, Minus, Plus, ThumbsDown, ThumbsUp } from "react-feather"; +import { + Edit3, + Minus, + Plus, + ThumbsDown, + ThumbsUp, + AlertCircle, + Loader, + CheckCircle, + Icon, +} from "react-feather"; import { updateBookingHoursBody, updateProjectStateBody } from "@/types"; import { useOutsideClick } from "@/hooks/useOutsideClick"; import { parseYearWeekFromString } from "@/data/urlUtils"; import Link from "next/link"; +import { getAgreementsForProject } from "@/actions/agreementActions"; async function updateProjectState( organisationName: string, @@ -56,6 +67,11 @@ export function DetailedBookingRows(props: { openEngagementAndSetID: (id: number) => void; numWorkHours: number; }) { + const colors: { color: string; text: string; icon: Icon }[] = [ + { color: "green", text: "Avtale aktiv", icon: CheckCircle }, + { color: "red", text: "Ingen avtaler funnet", icon: AlertCircle }, + { color: "orange", text: "Avtale utgått", icon: AlertCircle }, + ]; const { setConsultants } = useContext(FilteredContext); const { consultant, detailedBooking, openEngagementAndSetID, numWorkHours } = @@ -69,6 +85,9 @@ export function DetailedBookingRows(props: { const [currentDragWeek, setCurrentDragWeek] = useState( undefined, ); + const [alert, setAlertColor] = useState< + { color: string; text: string; icon: Icon } | undefined + >(undefined); const [editOfferDropdownIsOpen, setEditOfferDropdownIsOpen] = useState(false); const menuRef = useRef(null); @@ -88,12 +107,44 @@ export function DetailedBookingRows(props: { }); } + useEffect(() => { + getColorIcon(); + }, []); + + async function getColorIcon() { + const agreements = await getAgreementsForProject( + detailedBooking.bookingDetails.projectId, + organisationName, + ); + if (agreements) { + const endDate = Math.max( + ...agreements.map((p) => new Date(p.endDate).getTime()), + ); + const today = new Date().getTime(); + if (today > endDate) { + return setAlertColor(colors.find((c) => c.color == "orange")); + } else { + return setAlertColor(colors.find((c) => c.color == "green")); + } + } else { + return setAlertColor(colors.find((c) => c.color == "red")); + } + } + return ( - + +
+ {alert ? : } +
+ {alert?.text} +
+
+
+