-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Ida Marie Andreassen <[email protected]>
- Loading branch information
Showing
12 changed files
with
592 additions
and
72 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
frontend/src/app/[organisation]/prosjekt/[project]/Sidebar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
"use client"; | ||
import { ConsultantReadModel, ProjectWithCustomerModel } from "@/api-types"; | ||
import InfoBox from "@/components/InfoBox"; | ||
import { weekToString } from "@/data/urlUtils"; | ||
import { setWeeklyTotalBillableForProject } from "@/hooks/staffing/useConsultantsFilter"; | ||
import { useWeekSelectors } from "@/hooks/useWeekSelectors"; | ||
import { Week } from "@/types"; | ||
import { usePathname } from "next/navigation"; | ||
import { useEffect, useState } from "react"; | ||
|
||
// TODO: Call funtion and set a state when adding or removing consultants and hours | ||
function Sidebar({ project }: { project: ProjectWithCustomerModel }) { | ||
const { selectedWeek, selectedWeekSpan } = useWeekSelectors(); | ||
|
||
const [selectedConsultants, setSelectedConsultants] = useState< | ||
ConsultantReadModel[] | ||
>([]); | ||
|
||
const organisationUrl = usePathname().split("/")[1]; | ||
|
||
useEffect(() => { | ||
if (project != undefined) { | ||
fetchConsultantsFromProject( | ||
project, | ||
organisationUrl, | ||
selectedWeek, | ||
selectedWeekSpan, | ||
).then((res) => { | ||
setSelectedConsultants([ | ||
// Use spread to make a new list, forcing a re-render | ||
...res, | ||
]); | ||
}); | ||
} | ||
}, [project, organisationUrl, selectedWeek, selectedWeekSpan]); | ||
|
||
function calculateTotalHours() { | ||
const weeklyTotalBillableAndOffered = setWeeklyTotalBillableForProject( | ||
selectedConsultants, | ||
project, | ||
); | ||
var sum = 0; | ||
weeklyTotalBillableAndOffered.forEach((element) => { | ||
sum += element; | ||
}); | ||
return sum.toString(); | ||
} | ||
|
||
return ( | ||
<div className="sidebar z-10"> | ||
<div className=" bg-primary/5 h-full flex flex-col gap-6 p-4 w-[300px]"> | ||
<div className="flex flex-col gap-6"> | ||
<h2 className="text-h1">Info</h2> | ||
<div className="flex flex-col gap-2"> | ||
<h3>Om</h3> | ||
<InfoBox | ||
infoName="Navn på kunde" | ||
infoValue={project.customerName} | ||
/> | ||
</div> | ||
<div className="flex flex-col gap-2"> | ||
<h3>Bemanning</h3> | ||
<InfoBox | ||
infoName="Antall konsulenter" | ||
infoValue={selectedConsultants.length.toString()} | ||
/> | ||
<InfoBox | ||
infoName="Planlagt timeforbruk" | ||
infoValue={calculateTotalHours()} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
async function fetchConsultantsFromProject( | ||
project: ProjectWithCustomerModel, | ||
organisationUrl: string, | ||
selectedWeek: Week, | ||
selectedWeekSpan: number, | ||
) { | ||
const url = `/${organisationUrl}/bemanning/api/projects/staffings?projectId=${ | ||
project.projectId | ||
}&selectedWeek=${weekToString( | ||
selectedWeek, | ||
)}&selectedWeekSpan=${selectedWeekSpan}`; | ||
|
||
try { | ||
const data = await fetch(url, { | ||
method: "get", | ||
}); | ||
return (await data.json()) as ConsultantReadModel[]; | ||
} catch (e) { | ||
console.error("Error updating staffing", e); | ||
} | ||
|
||
return []; | ||
} | ||
|
||
export default Sidebar; |
7 changes: 7 additions & 0 deletions
7
frontend/src/app/[organisation]/prosjekt/[project]/layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function BemanningLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
return children; | ||
} |
59 changes: 59 additions & 0 deletions
59
frontend/src/app/[organisation]/prosjekt/[project]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { EditEngagementHour } from "@/components/Staffing/EditEngagementHourModal/EditEngagementHour"; | ||
import { | ||
fetchEmployeesWithImageAndToken, | ||
fetchWithToken, | ||
} from "@/data/apiCallsWithToken"; | ||
import { ProjectWithCustomerModel } from "@/api-types"; | ||
import Sidebar from "./Sidebar"; | ||
import { ConsultantFilterProvider } from "@/hooks/ConsultantFilterProvider"; | ||
import { parseYearWeekFromUrlString } from "@/data/urlUtils"; | ||
|
||
export default async function Project({ | ||
params, | ||
searchParams, | ||
}: { | ||
params: { organisation: string; project: string }; | ||
searchParams: { selectedWeek?: string; weekSpan?: string }; | ||
}) { | ||
const project = | ||
(await fetchWithToken<ProjectWithCustomerModel>( | ||
`${params.organisation}/projects/get/${params.project}`, | ||
)) ?? undefined; | ||
|
||
const selectedWeek = parseYearWeekFromUrlString( | ||
searchParams.selectedWeek || undefined, | ||
); | ||
const weekSpan = searchParams.weekSpan || undefined; | ||
|
||
const consultants = | ||
(await fetchEmployeesWithImageAndToken( | ||
`${params.organisation}/staffings${ | ||
selectedWeek | ||
? `?Year=${selectedWeek.year}&Week=${selectedWeek.weekNumber}` | ||
: "" | ||
}${weekSpan ? `${selectedWeek ? "&" : "?"}WeekSpan=${weekSpan}` : ""}`, | ||
)) ?? []; | ||
|
||
if (project) { | ||
return ( | ||
<ConsultantFilterProvider | ||
consultants={consultants} | ||
departments={[]} | ||
competences={[]} | ||
customers={[]} | ||
> | ||
<Sidebar project={project} /> | ||
<div className="main p-4 pt-5 w-full flex flex-col gap-8"> | ||
<div className="flex flex-col gap-2"> | ||
<h1>{project.projectName}</h1> | ||
<h2>{project.customerName}</h2> | ||
</div> | ||
|
||
<EditEngagementHour project={project} /> | ||
</div> | ||
</ConsultantFilterProvider> | ||
); | ||
} else { | ||
return <h1>Fant ikke prosjektet</h1>; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
"use client"; | ||
|
||
import { | ||
EngagementState, | ||
ProjectWithCustomerModel, | ||
UpdateProjectWriteModel, | ||
} from "@/api-types"; | ||
import { useState } from "react"; | ||
import FilterButton from "./Buttons/FilterButton"; | ||
import { usePathname, useRouter } from "next/navigation"; | ||
|
||
export default function ChangeEngagementState({ | ||
project, | ||
}: { | ||
project: ProjectWithCustomerModel; | ||
}) { | ||
const organisationName = usePathname().split("/")[1]; | ||
|
||
const router = useRouter(); | ||
|
||
const [engagementState, setEngagementState] = useState<EngagementState>( | ||
project.bookingType, | ||
); | ||
|
||
async function handleChange(newState: EngagementState) { | ||
setEngagementState(newState); | ||
|
||
const currentDate = new Date(); | ||
const startYear = currentDate.getFullYear(); | ||
const startWeek = Math.ceil( | ||
(currentDate.getTime() - new Date(startYear, 0, 1).getTime()) / | ||
(7 * 24 * 60 * 60 * 1000), | ||
); | ||
|
||
const body: UpdateProjectWriteModel = { | ||
engagementId: project.projectId, | ||
projectState: newState, | ||
startYear: startYear, | ||
startWeek: startWeek, | ||
weekSpan: 26, | ||
}; | ||
|
||
await submitAddEngagementForm(body); | ||
router.refresh(); | ||
} | ||
|
||
async function submitAddEngagementForm(body: UpdateProjectWriteModel) { | ||
const url = `/${organisationName}/bemanning/api/projects/updateState`; | ||
try { | ||
const data = await fetch(url, { | ||
method: "PUT", | ||
body: JSON.stringify({ | ||
...body, | ||
}), | ||
}); | ||
return (await data.json()) as ProjectWithCustomerModel; | ||
} catch (e) { | ||
console.error("Error updating engagement state", e); | ||
} | ||
} | ||
|
||
return ( | ||
<form className="flex flex-row gap-4"> | ||
<FilterButton | ||
label="Tilbud" | ||
rounded={true} | ||
value={EngagementState.Offer} | ||
checked={engagementState === EngagementState.Offer} | ||
onChange={(e) => handleChange(e.target.value as EngagementState)} | ||
/> | ||
<FilterButton | ||
label="Ordre" | ||
rounded={true} | ||
value={EngagementState.Order} | ||
checked={engagementState === EngagementState.Order} | ||
onChange={(e) => handleChange(e.target.value as EngagementState)} | ||
/> | ||
|
||
<FilterButton | ||
label="Avsluttet" | ||
rounded={true} | ||
value={EngagementState.Closed} | ||
checked={engagementState === EngagementState.Closed} | ||
onChange={(e) => handleChange(e.target.value as EngagementState)} | ||
/> | ||
</form> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.