|
|
@@ -15,13 +15,14 @@ import differenceBy from "lodash/differenceBy"; |
|
|
|
import intersectionWith from "lodash/intersectionWith"; |
|
|
|
import { TFunction } from "i18next"; |
|
|
|
import { LeaveType } from "@/app/api/timesheets"; |
|
|
|
import dayjs, { Dayjs } from "dayjs"; |
|
|
|
|
|
|
|
interface CommonProps { |
|
|
|
allProjects: ProjectWithTasks[]; |
|
|
|
assignedProjects: AssignedProject[]; |
|
|
|
error?: boolean; |
|
|
|
multiple?: boolean; |
|
|
|
showOnlyOngoing?: boolean; |
|
|
|
referenceDay: Dayjs; |
|
|
|
includeLeaves?: boolean; |
|
|
|
leaveTypes?: LeaveType[]; |
|
|
|
} |
|
|
@@ -64,7 +65,7 @@ const getGroupName = (t: TFunction, groupName: string): string => { |
|
|
|
|
|
|
|
const AutocompleteProjectSelect: React.FC<Props> = ({ |
|
|
|
allProjects, |
|
|
|
showOnlyOngoing = true, |
|
|
|
referenceDay, |
|
|
|
assignedProjects, |
|
|
|
value, |
|
|
|
onProjectSelect, |
|
|
@@ -75,10 +76,10 @@ const AutocompleteProjectSelect: React.FC<Props> = ({ |
|
|
|
}) => { |
|
|
|
const { t } = useTranslation("home"); |
|
|
|
const allFilteredProjects = useMemo(() => { |
|
|
|
return showOnlyOngoing |
|
|
|
? allProjects.filter((p) => p.status === "On-going") |
|
|
|
: allProjects; |
|
|
|
}, [showOnlyOngoing, allProjects]); |
|
|
|
return allProjects.filter((p) => |
|
|
|
p.actualEnd ? !referenceDay.isAfter(p.actualEnd) : true, |
|
|
|
); |
|
|
|
}, [allProjects, referenceDay]); |
|
|
|
|
|
|
|
const nonAssignedProjects = useMemo(() => { |
|
|
|
return differenceBy(allFilteredProjects, assignedProjects, "id"); |
|
|
|