Skip to content

Commit

Permalink
Feat: Base step on workhours pr day for organisation (#504)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigridge authored Jul 24, 2024
1 parent 29c64bf commit 6d6b7c2
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 16 deletions.
10 changes: 9 additions & 1 deletion frontend/src/app/[organisation]/kunder/[customer]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import CustomerSidebar from "@/components/CostumerTable/CustomerSidebar";
import CustomerTable from "@/components/CostumerTable/CustomerTable";
import { fetchWithToken } from "@/data/apiCallsWithToken";
import { ConsultantFilterProvider } from "@/hooks/ConsultantFilterProvider";
import { fetchWorkHoursPerWeek } from "@/hooks/fetchWorkHoursPerDay";
import { Metadata } from "next";

export const metadata: Metadata = {
Expand All @@ -27,6 +28,9 @@ export default async function Kunde({
`organisations/${params.organisation}/departments`,
)) ?? [];

const numWorkHours =
(await fetchWorkHoursPerWeek(params.organisation)) ?? 37.5;

return (
<ConsultantFilterProvider
consultants={[]}
Expand All @@ -37,7 +41,11 @@ export default async function Kunde({
{customer && (
<>
<CustomerSidebar customer={customer} />
<CustomerTable customer={customer} orgUrl={params.organisation} />
<CustomerTable
customer={customer}
orgUrl={params.organisation}
numWorkHours={numWorkHours}
/>
</>
)}
</ConsultantFilterProvider>
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/app/[organisation]/prosjekt/[project]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ProjectWithCustomerModel } from "@/api-types";
import Sidebar from "./Sidebar";
import { ConsultantFilterProvider } from "@/hooks/ConsultantFilterProvider";
import { parseYearWeekFromUrlString } from "@/data/urlUtils";
import { fetchWorkHoursPerWeek } from "@/hooks/fetchWorkHoursPerDay";

export default async function Project({
params,
Expand All @@ -25,6 +26,9 @@ export default async function Project({
);
const weekSpan = searchParams.weekSpan || undefined;

const numWorkHours =
(await fetchWorkHoursPerWeek(params.organisation)) ?? 37.5;

const consultants =
(await fetchEmployeesWithImageAndToken(
`${params.organisation}/staffings${
Expand All @@ -49,7 +53,7 @@ export default async function Project({
<h2>{project.customerName}</h2>
</div>

<EditEngagementHour project={project} />
<EditEngagementHour project={project} numWorkHours={numWorkHours} />
</div>
</ConsultantFilterProvider>
);
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/components/CostumerTable/CustomerTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import { WeekSpanTableHead } from "../Staffing/WeekTableHead";
export default function CustomerTable({
customer,
orgUrl,
numWorkHours,
}: {
customer: CustomersWithProjectsReadModel;
orgUrl: string;
numWorkHours: number;
}) {
const {
selectedWeek,
Expand Down Expand Up @@ -111,6 +113,7 @@ export default function CustomerTable({
selectedWeek={selectedWeek}
selectedWeekSpan={selectedWeekSpan}
weekList={weekList}
numWorkHours={numWorkHours}
/>
))}
</>
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/components/CostumerTable/EngagementRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ export default function EngagementRows({
selectedWeek,
selectedWeekSpan,
weekList,
numWorkHours,
}: {
engagement: EngagementReadModel;
orgUrl: string;
selectedWeek: Week;
selectedWeekSpan: number;
weekList: DateTime[];
numWorkHours: number;
}) {
const [isListElementVisible, setIsListElementVisible] = useState(false);
const [isRowHovered, setIsRowHovered] = useState(false);
Expand Down Expand Up @@ -148,6 +150,7 @@ export default function EngagementRows({
consultants={selectedConsultants}
setConsultants={setSelectedConsultants}
withBorder={true}
numWorkHours={numWorkHours}
/>
))}
</>
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/Staffing/ConsultantRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ export default function ConsultantRows({
modalRef={changeEngagementModalRef}
project={selectedProject}
onClose={onCloseEngagementModal}
numWorkHours={numWorkHours}
/>
)}
</div>
Expand Down Expand Up @@ -240,6 +241,7 @@ export default function ConsultantRows({
consultant={currentConsultant}
detailedBooking={db}
openEngagementAndSetID={openEngagementAndSetID}
numWorkHours={numWorkHours}
/>
))}
{isListElementVisible && addNewRow && (
Expand Down
15 changes: 11 additions & 4 deletions frontend/src/components/Staffing/DetailedBookingRows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ export function DetailedBookingRows(props: {
consultant: ConsultantReadModel;
detailedBooking: DetailedBooking;
openEngagementAndSetID: (id: number) => void;
numWorkHours: number;
}) {
const { setConsultants } = useContext(FilteredContext);

const { consultant, detailedBooking, openEngagementAndSetID } = props;
const { consultant, detailedBooking, openEngagementAndSetID, numWorkHours } =
props;
const [hourDragValue, setHourDragValue] = useState<number | undefined>(
undefined,
);
Expand Down Expand Up @@ -178,6 +180,7 @@ export function DetailedBookingRows(props: {
startDragWeek={startDragWeek}
setStartDragWeek={setStartDragWeek}
setCurrentDragWeek={setCurrentDragWeek}
numWorkHours={numWorkHours}
/>
))}
</tr>
Expand Down Expand Up @@ -226,6 +229,7 @@ function DetailedBookingCell({
startDragWeek,
setStartDragWeek,
setCurrentDragWeek,
numWorkHours,
}: {
detailedBooking: DetailedBooking;
detailedBookingHours: WeeklyHours;
Expand All @@ -236,6 +240,7 @@ function DetailedBookingCell({
setHourDragValue: React.Dispatch<React.SetStateAction<number | undefined>>;
setStartDragWeek: React.Dispatch<React.SetStateAction<number | undefined>>;
setCurrentDragWeek: React.Dispatch<React.SetStateAction<number | undefined>>;
numWorkHours: number;
}) {
const { setConsultants } = useContext(FilteredContext);
const [hours, setHours] = useState(detailedBookingHours.hours);
Expand All @@ -248,6 +253,8 @@ function DetailedBookingCell({
const organisationName = usePathname().split("/")[1];
const numWeeks = detailedBooking.hours.length;

const workHoursPerDay = numWorkHours / 5;

function updateSingularHours() {
setIsDisabledHotkeys(false);
if (oldHours != hours && hourDragValue == undefined) {
Expand Down Expand Up @@ -343,7 +350,7 @@ function DetailedBookingCell({
numWeeks <= 12 && "lg:flex"
} `}
onClick={() => {
setHours(Math.max(hours - 7.5, 0));
setHours(Math.max(hours - workHoursPerDay, 0));
}}
>
<Minus
Expand All @@ -358,7 +365,7 @@ function DetailedBookingCell({
ref={inputRef}
type="number"
min="0"
step="7.5"
step={workHoursPerDay}
value={hours}
draggable={true}
disabled={detailedBooking.bookingDetails.type == BookingType.Vacation}
Expand Down Expand Up @@ -401,7 +408,7 @@ function DetailedBookingCell({
numWeeks <= 8 && "md:flex"
} ${numWeeks <= 12 && "lg:flex"} `}
onClick={() => {
setHours(hours + 7.5);
setHours(hours + workHoursPerDay);
}}
>
<Plus className="w-4 h-4 text-primary" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ export function AddEngagementHoursRow({
weekList,
project,
consultantWWeekHours,
numWorkHours,
}: {
consultant: ConsultantReadModel;
weekList: DateTime[];
project?: ProjectWithCustomerModel;
consultantWWeekHours?: ConsultantWithWeekHours;
numWorkHours: number;
}) {
const [hourDragValue, setHourDragValue] = useState<number | undefined>(
undefined,
Expand Down Expand Up @@ -97,6 +99,7 @@ export function AddEngagementHoursRow({
)?.hours || 0
}
updateHours={updateHours}
numWorkHours={numWorkHours}
/>
))}
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function DetailedEngagementModalCell({
firstDayInWeek,
initHours,
updateHours,
numWorkHours,
}: {
project?: ProjectWithCustomerModel;
consultant: ConsultantReadModel;
Expand All @@ -38,6 +39,7 @@ export function DetailedEngagementModalCell({
firstDayInWeek: DateTime;
initHours: number;
updateHours: (res: ConsultantReadModel | undefined) => void;
numWorkHours: number;
}) {
const [hours, setHours] = useState(initHours);
const [isChangingHours, setIsChangingHours] = useState(false);
Expand All @@ -47,6 +49,8 @@ export function DetailedEngagementModalCell({
const inputRef = useRef<HTMLInputElement | null>(null);
const organisationName = usePathname().split("/")[1];

const workHoursPerDay = numWorkHours / 5;

function updateSingularHours() {
if (oldHours != hours && hourDragValue == undefined) {
setOldHours(hours);
Expand Down Expand Up @@ -137,7 +141,7 @@ export function DetailedEngagementModalCell({
numWeeks <= 12 && "lg:flex"
} `}
onClick={() => {
setHours(Math.max(hours - 7.5, 0));
setHours(Math.max(hours - workHoursPerDay, 0));
}}
>
<Minus
Expand All @@ -152,7 +156,7 @@ export function DetailedEngagementModalCell({
ref={inputRef}
type="number"
min="0"
step="7.5"
step={workHoursPerDay}
value={hours}
draggable={true}
onChange={(e) =>
Expand Down Expand Up @@ -190,7 +194,7 @@ export function DetailedEngagementModalCell({
numWeeks <= 8 && "md:flex"
} ${numWeeks <= 12 && "lg:flex"} `}
onClick={() => {
setHours(hours + 7.5);
setHours(hours + workHoursPerDay);
}}
>
<Plus className="w-4 h-4 text-primary" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import ChangeEngagementState from "@/components/ChangeEngagementState";

export function EditEngagementHour({
project,
numWorkHours,
}: {
project?: ProjectWithCustomerModel;
numWorkHours: number;
}) {
const {
selectedWeek,
Expand Down Expand Up @@ -164,6 +166,7 @@ export function EditEngagementHour({
}
consultants={selectedConsultants}
setConsultants={setSelectedConsultants}
numWorkHours={numWorkHours}
/>
))}

Expand All @@ -182,6 +185,7 @@ export function EditEngagementHour({
weekList={weekList}
project={chosenProject}
consultantWWeekHours={consultant}
numWorkHours={numWorkHours}
/>
))}
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ export function EditEngagementHourModal({
modalRef,
project,
onClose,
numWorkHours,
}: {
modalRef: RefObject<HTMLDialogElement>;
project?: ProjectWithCustomerModel;
onClose: () => void;
numWorkHours: number;
}) {
const {
selectedWeek,
Expand Down Expand Up @@ -164,6 +166,7 @@ export function EditEngagementHourModal({
}
consultants={selectedConsultants}
setConsultants={setSelectedConsultants}
numWorkHours={numWorkHours}
/>
))}

Expand All @@ -185,6 +188,7 @@ export function EditEngagementHourModal({
weekList={weekList}
project={chosenProject}
consultantWWeekHours={consultant}
numWorkHours={numWorkHours}
/>
))}
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ export function EditEngagementHoursRow({
consultants,
setConsultants,
withBorder = false,
numWorkHours,
}: {
consultant: ConsultantReadModel;
detailedBooking?: DetailedBooking;
consultants: ConsultantReadModel[];
setConsultants: React.Dispatch<React.SetStateAction<ConsultantReadModel[]>>;
withBorder?: boolean;
numWorkHours: number;
}) {
const [hourDragValue, setHourDragValue] = useState<number | undefined>(
undefined,
Expand Down Expand Up @@ -71,6 +73,7 @@ export function EditEngagementHoursRow({
setCurrentDragWeek={setCurrentDragWeek}
setConsultants={setConsultants}
consultants={consultants}
numWorkHours={numWorkHours}
/>
))}
</>
Expand All @@ -91,6 +94,7 @@ function EditBookingCell({
setCurrentDragWeek,
setConsultants,
consultants,
numWorkHours,
}: {
detailedBooking: DetailedBooking;
detailedBookingHours: WeeklyHours;
Expand All @@ -103,6 +107,7 @@ function EditBookingCell({
setCurrentDragWeek: React.Dispatch<React.SetStateAction<number | undefined>>;
setConsultants: React.Dispatch<React.SetStateAction<ConsultantReadModel[]>>;
consultants: ConsultantReadModel[];
numWorkHours: number;
}) {
const [hours, setHours] = useState(detailedBookingHours.hours);
const [isChangingHours, setIsChangingHours] = useState(false);
Expand All @@ -113,6 +118,8 @@ function EditBookingCell({
const organisationName = usePathname().split("/")[1];
const numWeeks = detailedBooking.hours.length;

const workHoursPerDay = numWorkHours / 5;

function updateSingularHours() {
if (oldHours != hours && hourDragValue == undefined) {
setDetailedBookingHours({
Expand Down Expand Up @@ -206,7 +213,7 @@ function EditBookingCell({
numWeeks <= 12 && "lg:flex"
} `}
onClick={() => {
setHours(Math.max(hours - 7.5, 0));
setHours(Math.max(hours - workHoursPerDay, 0));
}}
>
<Minus
Expand All @@ -221,7 +228,7 @@ function EditBookingCell({
ref={inputRef}
type="number"
min="0"
step="7.5"
step={workHoursPerDay}
value={hours}
draggable={true}
disabled={detailedBooking.bookingDetails.type == BookingType.Vacation}
Expand Down Expand Up @@ -262,7 +269,7 @@ function EditBookingCell({
numWeeks <= 8 && "md:flex"
} ${numWeeks <= 12 && "lg:flex"} `}
onClick={() => {
setHours(hours + 7.5);
setHours(hours + workHoursPerDay);
}}
>
<Plus className="w-4 h-4 text-primary" />
Expand Down
Loading

0 comments on commit 6d6b7c2

Please sign in to comment.