Skip to content

Commit

Permalink
Update agreement alert (#541)
Browse files Browse the repository at this point in the history
Co-authored-by: md <[email protected]>
  • Loading branch information
Dahly96 and md authored Nov 22, 2024
1 parent bad43c4 commit 320a3e5
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ public async Task<ActionResult<AgreementReadModel>> Post([FromRoute] string orgU
UploadedOn: f.UploadedOn
)).ToList()
);
cache.Remove($"consultantCacheKey/{orgUrlKey}");

return Ok(responseModel);
}
Expand Down Expand Up @@ -294,6 +295,8 @@ public async Task<ActionResult<AgreementReadModel>> Put([FromRoute] string orgUr
)).ToList()
);

cache.Remove($"consultantCacheKey/{orgUrlKey}");

return Ok(responseModel);
}

Expand All @@ -308,6 +311,7 @@ public async Task<ActionResult> Delete([FromRoute] string orgUrlKey, [FromRoute]
if (agreement is null) return NotFound();

await agreementsRepository.DeleteAgreementAsync(agreementId, ct);
cache.Remove($"consultantCacheKey/{orgUrlKey}");

return Ok("Deleted");
}
Expand Down
File renamed without changes.
15 changes: 11 additions & 4 deletions backend/Api/Common/StorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ public Consultant LoadConsultantForSingleWeek(int consultantId, Week week)
.Single(c => c.Id == consultantId);

consultant.Staffings = _dbContext.Staffing.Where(staffing =>
staffing.Week.Equals(week) && staffing.ConsultantId == consultantId).Include(s => s.Engagement)
.ThenInclude(p => p.Customer).ToList();
staffing.Week.Equals(week) && staffing.ConsultantId == consultantId)
.Include(s => s.Engagement)
.ThenInclude(p => p.Customer)
.Include(s => s.Engagement)
.ThenInclude(e => e.Agreements).ToList();

consultant.PlannedAbsences = _dbContext.PlannedAbsence
.Where(absence => absence.Week.Equals(week) && absence.ConsultantId == consultantId).Include(a => a.Absence)
Expand All @@ -70,8 +73,12 @@ public Consultant LoadConsultantForWeekSet(int consultantId, List<Week> weeks)


consultant.Staffings = _dbContext.Staffing.Where(staffing =>
weeks.Contains(staffing.Week) && staffing.ConsultantId == consultantId).Include(s => s.Engagement)
.ThenInclude(p => p.Customer).ToList();
weeks.Contains(staffing.Week) && staffing.ConsultantId == consultantId)
.Include(s => s.Engagement)
.ThenInclude(p => p.Customer)
.Include(s => s.Engagement)
.ThenInclude(e => e.Agreements)
.ToList();

consultant.PlannedAbsences = _dbContext.PlannedAbsence
.Where(absence => weeks.Contains(absence.Week) && absence.ConsultantId == consultantId)
Expand Down
6 changes: 4 additions & 2 deletions backend/Api/StaffingController/ReadModelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ private static List<DetailedBooking> DetailedBookings(Consultant consultant,
.Select(grouping => new DetailedBooking(
new BookingDetails(grouping.First().Engagement.Name, BookingType.Booking,
grouping.First().Engagement.Customer.Name,
grouping.Key, false, grouping.First().Engagement.IsBillable),
grouping.Key, false, grouping.First().Engagement.IsBillable,
grouping.First().Engagement.Agreements.Select(a => (DateTime?)a.EndDate).DefaultIfEmpty(null).Max()),
weekSet.Select(week =>
new WeeklyHours(
week.ToSortableInt(), grouping
Expand All @@ -117,7 +118,8 @@ private static List<DetailedBooking> DetailedBookings(Consultant consultant,
.Select(grouping => new DetailedBooking(
new BookingDetails(grouping.First().Engagement.Name, BookingType.Offer,
grouping.First().Engagement.Customer.Name,
grouping.Key, false, grouping.First().Engagement.IsBillable),
grouping.Key, false, grouping.First().Engagement.IsBillable,
grouping.First().Engagement.Agreements.Select(a => (DateTime?)a.EndDate).DefaultIfEmpty(null).Max()),
weekSet.Select(week =>
new WeeklyHours(
week.ToSortableInt(),
Expand Down
3 changes: 2 additions & 1 deletion backend/Api/StaffingController/StaffingReadModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ public record BookingDetails(
[property: Required] string CustomerName,
[property: Required] int ProjectId,
[property: Required] bool ExcludeFromBilling = false,
[property: Required] bool IsBillable = false);
[property: Required] bool IsBillable = false,
DateTime? EndDateAgreement = null);

public record WeeklyHours([property: Required] int Week, [property: Required] double Hours);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static void AddRepositories(this WebApplicationBuilder builder)
builder.Services.Decorate<IPlannedAbsenceRepository, PlannedAbsenceCacheRepository>();

builder.Services.AddScoped<IStaffingRepository, StaffingDbRepository>();
builder.Services.Decorate<IStaffingRepository, StaffingCacheRepository>();
//builder.Services.Decorate<IStaffingRepository, StaffingCacheRepository>();

builder.Services.AddScoped<IConsultantRepository, ConsultantDbRepository>();
builder.Services.AddScoped<IAgreementsRepository, AgreementDbRepository>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public async Task<Dictionary<int, List<Staffing>>> GetStaffingForConsultants(Lis
.Include(s => s.Consultant)
.Include(staffing => staffing.Engagement)
.ThenInclude(project => project.Customer)
.Include(staffing => staffing.Engagement)
.ThenInclude(project => project.Agreements)
.GroupBy(staffing => staffing.Consultant.Id)

Check warning on line 21 in backend/Infrastructure/Repositories/Staffings/StaffingDbRepository.cs

View workflow job for this annotation

GitHub Actions / Build and deploy Backend

Dereference of a possibly null reference.

Check warning on line 21 in backend/Infrastructure/Repositories/Staffings/StaffingDbRepository.cs

View workflow job for this annotation

GitHub Actions / dotnet_core_project_tests (8.x.x)

Dereference of a possibly null reference.

Check warning on line 21 in backend/Infrastructure/Repositories/Staffings/StaffingDbRepository.cs

View workflow job for this annotation

GitHub Actions / Build and deploy Backend

Dereference of a possibly null reference.
.ToDictionaryAsync(group => group.Key, grouping => grouping.ToList(), ct);
}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/api-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface BookingDetails {
/** @format int32 */
projectId: number;
isBillable: boolean;
endDateAgreement?: string | null;
}

export enum BookingType {
Expand Down
27 changes: 25 additions & 2 deletions frontend/src/components/Staffing/ConsultantRow.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";
import { ConsultantReadModel, ProjectWithCustomerModel } from "@/api-types";
import React, { useContext, useEffect, useState } from "react";
import { ChevronDown, Plus } from "react-feather";
import { AlertCircle, ChevronDown, Plus } from "react-feather";
import { DetailedBookingRows } from "@/components/Staffing/DetailedBookingRows";
import { WeekCell } from "@/components/Staffing/WeekCell";
import { useModal } from "@/hooks/useModal";
Expand Down Expand Up @@ -155,6 +155,28 @@ export default function ConsultantRows({
}
}

function getAlert() {
const dates = consultant.detailedBooking
.filter((e) => e.bookingDetails.projectId > 0)
.map((e) => e.bookingDetails.endDateAgreement);

if (dates.some((e) => e === null)) {
return <AlertCircle color="red" size={20} />;
} else if (dates.length > 0) {
const newestDate = dates.reduce((a, b) => {
return new Date(a as string) < new Date(b as string) ? a : b;
});

const now = DateTime.now();
const endDate = DateTime.fromISO(newestDate as string);
if (endDate < now) {
return <AlertCircle color="orange" size={20} />;
} else {
return null;
}
}
}

return (
<>
<tr
Expand All @@ -181,7 +203,8 @@ export default function ConsultantRows({
</button>
</td>
<td>
<div className="flex gap-2">
<div className="flex gap-1 items-center">
{getAlert()}
<div className="flex flex-row align-center self-center gap-2">
{consultant.imageThumbUrl ? (
<Image
Expand Down
18 changes: 8 additions & 10 deletions frontend/src/components/Staffing/DetailedBookingRows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,20 @@ export function DetailedBookingRows(props: {
}, []);

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 endDateString = detailedBooking.bookingDetails.endDateAgreement;
if (endDateString && endDateString !== null) {
const endDate = new Date(endDateString).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"));
if (endDateString === null) {
return setAlertColor(colors.find((c) => c.color == "red"));
}
}
}

Expand All @@ -138,7 +136,7 @@ export function DetailedBookingRows(props: {
>
<td className=" border-l-secondary border-l-2 w-full">
<div className="relative flex justify-center group items-center">
{alert ? <alert.icon color={alert.color} /> : <Loader />}
{alert && <alert.icon color={alert.color} />}
<div className="absolute left-full ml-2 hidden group-hover:block bg-black text-white text-xs rounded py-1 px-2 w-max z-30">
{alert?.text}
<div className="absolute top-1/2 transform -translate-y-1/2 left-0 ml-[-8px] w-0 h-0 border-r-8 border-r-black border-y-8 border-y-transparent border-l-0"></div>
Expand Down

0 comments on commit 320a3e5

Please sign in to comment.