Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create table and show hours booked #242

Merged
merged 4 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backend/Api/Consultants/ConsultantExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@ private static List<BookedHoursPerWeek> GetBookedHoursForWeeks(this Consultant c
{
var year = DateTime.Today.AddDays(7 * offset).Year;
var week = DateService.GetWeekAhead(offset);
var datestring = DateService.GetDatesInWorkWeek(year, week)[0].ToString("dd.MM") + "-" + DateService
.GetDatesInWorkWeek(year, week)[^1].ToString("dd.MM");

return new BookedHoursPerWeek(
year,
week,
datestring,
GetBookingModelForWeek(consultant, year, week)
);
})
Expand Down
2 changes: 1 addition & 1 deletion backend/Api/Consultants/ConsultantReadModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public record ConsultantReadModel(int Id, string Name, string Email, List<string
List<BookedHoursPerWeek> Bookings, bool IsOccupied);


public record BookedHoursPerWeek(int Year, int WeekNumber, WeeklyBookingReadModel BookingModel);
public record BookedHoursPerWeek(int Year, int WeekNumber, string DateString, WeeklyBookingReadModel BookingModel);

public record WeeklyBookingReadModel(double TotalBillable, double TotalOffered, double TotalPlannedAbstences, double TotalSellableTime, double TotalHolidayHours, List<BookingReadModel> Bookings);

Expand Down
11 changes: 6 additions & 5 deletions backend/Core/Services/DateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ namespace Core.Services;

public class DateService
{
public static DateOnly GetFirstDayOfWeekContainingDate(DateTime time){
return DateOnly.FromDateTime(FirstWorkDayOfWeek(time.Year, GetWeekNumber(time)));
}

// This presumes that weeks start with Monday.
public static DateOnly GetFirstDayOfWeekContainingDate(DateTime time)
{
return DateOnly.FromDateTime(FirstWorkDayOfWeek(time.Year, GetWeekNumber(time)));
}

// This presumes that weeks start with Monday.
// Week 1 is the 1st week of the year with a Thursday in it.
public static int GetWeekNumber(DateTime time)
{
Expand Down
25 changes: 23 additions & 2 deletions frontend/mockdata/mockData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
import { Consultant, Department, Organisation } from "@/types";
import {
Consultant,
Department,
Organisation,
WeeklyBookingReadModel,
} from "@/types";

const MockWeeklyBookingReadModel: WeeklyBookingReadModel = {
totalBillable: 0,
totalOffered: 0,
totalPlannedAbstences: 0,
totalSellableTime: 0,
totalHolidayHours: 0,
bookings: [],
};

export const MockConsultants: Consultant[] = [
{
Expand All @@ -7,7 +21,14 @@ export const MockConsultants: Consultant[] = [
email: "[email protected]",
competences: ["Frontend"],
department: "My Department",
bookings: [{ year: 2023, weekNumber: 10, bookedHours: 10 }],
bookings: [
{
year: 2023,
weekNumber: 10,
dateString: "",
bookingModel: MockWeeklyBookingReadModel,
},
],
yearsOfExperience: 23,
},
];
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@
background-color: transparent;
}

th {
font-weight: normal;
}

.interaction-chip {
font-size: 0.75rem;
font-family: "Graphik-SemiBold";
Expand Down
60 changes: 0 additions & 60 deletions frontend/src/components/ConsultantListElement.tsx

This file was deleted.

80 changes: 80 additions & 0 deletions frontend/src/components/ConsultantRows.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"use client";
import { Consultant } from "@/types";
import { useState } from "react";
import { ChevronDown } from "react-feather";

interface ConsultantListElementProps {
consultant: Consultant;
}

export default function ConsultantRows({
consultant,
}: ConsultantListElementProps) {
const [isListElementVisible, setIsListElementVisible] = useState(false);
const [isButtonHovered, setIsButtonHovered] = useState(false);

function toggleListElementVisibility() {
setIsListElementVisible(!isListElementVisible);
}

return (
<>
<tr>
<td>
<div className="flex flex-row gap-2 ">
<div
className={`py-0 w-0.5 rounded-lg ${
isButtonHovered ? "bg-primary_default" : "bg-primary_l4"
} ${isListElementVisible && "bg-secondary_default"}`}
></div>
<div
className="flex flex-row gap-2 items-center h-[52px]"
onMouseEnter={() => setIsButtonHovered(true)}
onMouseLeave={() => setIsButtonHovered(false)}
>
<button
className={`p-2 rounded-lg hover:bg-primary_default hover:bg-opacity-10 ${
isListElementVisible && "rotate-180"
}`}
onClick={toggleListElementVisibility}
>
<ChevronDown className={`text-primary_default w-6 h-6`} />
</button>
<div className="flex flex-col gap-1">
<p
className={`text-black text-start ${
isListElementVisible ? "body-bold" : "body"
}`}
>
{consultant.name}
</p>
<p className="detail text-neutral_l1 text-start">
{`${consultant.yearsOfExperience} års erfaring`}
</p>
</div>
</div>
</div>
</td>
{consultant.bookings?.map((b) => (
<td
key={b.weekNumber}
className={`px-2 py-1 rounded ${
b.bookingModel.totalSellableTime > 0
? `bg-semantic_4_l1`
: `bg-primary_l5`
}`}
>
<p
className={`text-right ${
isListElementVisible ? "body-bold" : "body"
}`}
>
{b.bookingModel.totalBillable}
</p>
</td>
))}
</tr>
<tr className={`${!isListElementVisible && "hidden"} h-[198px] `}></tr>
</>
);
}
47 changes: 32 additions & 15 deletions frontend/src/components/FilteredConsultantsList.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,46 @@
"use client";
import ConsultantListElement from "./ConsultantListElement";
import ConsultantRows from "./ConsultantRows";
import ActiveFilters from "./ActiveFilters";
import { useFilteredConsultants } from "@/hooks/useFilteredConsultants";

export default function FilteredConsultantList() {
const { filteredConsultants: consultants } = useFilteredConsultants();

return (
<div>
<div className="">
<div>
<ActiveFilters />
</div>
<div className="flex flex-row gap-3 pb-4 items-center">
<p className="body-large-bold ">Konsulenter</p>
<table className="w-full table-auto border-separate border-spacing-1">
<thead>
<tr>
<th className="flex flex-row gap-3 pb-4 items-center ">
<p className="body-large-bold ">Konsulenter</p>

<div className="rounded-full bg-primary_l3 px-2 py-1">
<p className="text-primary_default body-small-bold">
{consultants?.length}
</p>
</div>
</div>
<div className="flex flex-col gap-1">
{consultants?.map((consultant) => (
<ConsultantListElement key={consultant.id} consultant={consultant} />
))}
</div>
<div className="rounded-full bg-primary_l3 px-2 py-1">
<p className="text-primary_default body-small-bold">
{consultants?.length}
</p>
</div>
</th>
{consultants.at(0)?.bookings?.map((b) => (
<th key={b.weekNumber} className="px-2 py-1">
<div className="flex flex-col gap-1 justify-items-end">
<p className=" body text-right">{b.weekNumber}</p>
</div>
<p className="detail text-neutral_l1 text-right">
{b.dateString}
</p>
</th>
))}
</tr>
</thead>
<tbody>
{consultants?.map((consultant) => (
<ConsultantRows key={consultant.id} consultant={consultant} />
))}
</tbody>
</table>
</div>
);
}
37 changes: 30 additions & 7 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
export interface BookedHoursPerWeek {
year: number;
weekNumber: number;
bookingModel: WeeklyBookingReadModel;
dateString: string;
}

export interface WeeklyBookingReadModel {
totalBillable: number;
totalOffered: number;
totalPlannedAbstences: number;
totalSellableTime: number;
totalHolidayHours: number;
bookings: BookingReadModel[] | null;
}

export interface BookingReadModel {
name: string | null;
hours: number;
type: BookingType;
}

export enum BookingType {
Offer = "Offer",
Booking = "Booking",
PlannedAbsence = "PlannedAbsence",
Vacation = "Vacation",
}

export type Consultant = {
id: string;
name: string;
email: string;
competences: string[];
department: string;
bookings: [
{
year: number;
weekNumber: number;
bookedHours: number;
},
];
yearsOfExperience: number;
bookings?: BookedHoursPerWeek[] | null;
};

export type Department = {
Expand Down
2 changes: 2 additions & 0 deletions frontend/tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export default {
primary_l2: "#C6C5DC",
primary_l3: "#ECECF3",
primary_l4: "#F6F5F9",
primary_l5: "#F9F9FB",
secondary_default: "#F076A6",
semantic_4_l1: "#FFE5B5",
neutral_l1: "#858585",
transparent: "transparent",
},
Expand Down
Loading