Skip to content

Commit 2ba9ea1

Browse files
authored
Enabling editing of 'estimated hourly price' for a consultant (#724)
1 parent 66912df commit 2ba9ea1

File tree

7 files changed

+81
-4
lines changed

7 files changed

+81
-4
lines changed

backend/Api/Common/StorageService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ public async Task<Consultant> CreateConsultant(Organization org, ConsultantWrite
200200
if (department is not null) consultant.Department = department;
201201
consultant.GraduationYear = body.GraduationYear;
202202
consultant.Degree = body.Degree;
203+
consultant.EstimatedHourPrice = body.EstimatedHourPrice;
203204

204205
if (body.Discipline?.Id != consultant.DisciplineId)
205206
{

backend/Api/Consultants/ConsultantModels.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public record SingleConsultantReadModel(
1717
int? GraduationYear,
1818
int YearsOfExperience,
1919
Degree Degree,
20-
DisciplineReadModel? Discipline)
20+
DisciplineReadModel? Discipline,
21+
int EstimatedHourPrice)
2122
{
2223
public SingleConsultantReadModel(Consultant consultant)
2324
: this(
@@ -31,7 +32,8 @@ public SingleConsultantReadModel(Consultant consultant)
3132
consultant.GraduationYear,
3233
consultant.YearsOfExperience,
3334
consultant.Degree ?? Degree.Master,
34-
DisciplineReadModel.CreateIfExists(consultant.Discipline)
35+
DisciplineReadModel.CreateIfExists(consultant.Discipline),
36+
consultant.EstimatedHourPrice
3537
)
3638
{
3739
}
@@ -62,4 +64,5 @@ public record ConsultantWriteModel(
6264
UpdateDepartmentReadModel Department,
6365
int GraduationYear,
6466
Degree Degree,
65-
DisciplineReadModel? Discipline);
67+
DisciplineReadModel? Discipline,
68+
int EstimatedHourPrice);

frontend/mockdata/mockData.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,5 +418,6 @@ export const MockConsultants: ConsultantReadModel[] = [
418418
isOccupied: true,
419419
graduationYear: 2010,
420420
degree: Degree.Bachelor,
421+
estimatedHourPrice: 1200,
421422
},
422423
];

frontend/src/api-types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ export interface ConsultantReadModel {
5858
yearsOfExperience: number;
5959
graduationYear: number;
6060
degree: Degree;
61+
/** @format int32 */
62+
estimatedHourPrice: number;
6163
bookings: BookedHoursPerWeek[];
6264
detailedBooking: DetailedBooking[];
6365
isOccupied: boolean;
@@ -76,6 +78,8 @@ export interface ConsultantWriteModel {
7678
degree: Degree;
7779
/** @format int32 */
7880
graduationYear: number;
81+
/** @format int32 */
82+
estimatedHourPrice: number;
7983
startDate: Date;
8084
endDate?: Date;
8185
}
@@ -222,6 +226,8 @@ export interface SingleConsultantReadModel {
222226
graduationYear: number;
223227
/** @format int32 */
224228
yearsOfExperience: number;
229+
/** @format int32 */
230+
estimatedHourPrice: number;
225231
degree: Degree;
226232
imageUrl?: string;
227233
imageThumbUrl?: string;

frontend/src/components/consultants/AddNewConsultantModal.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default function AddNewConsultantModal({
2121
degree: Degree.None,
2222
graduationYear: new Date().getFullYear(),
2323
startDate: new Date(),
24+
estimatedHourPrice: 0,
2425
});
2526
const { competences, departments } = useContext(FilteredContext);
2627
const { organisation } = useParams();
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"use client";
2+
import React, { useEffect, useState } from "react";
3+
4+
export default function EditableTableNumberCell({
5+
number,
6+
setConsultant,
7+
isEditing,
8+
}: {
9+
number: number;
10+
setConsultant: (number: number) => void;
11+
isEditing: boolean;
12+
}) {
13+
const [newValue, setNewValue] = useState<number>(number);
14+
15+
useEffect(() => {
16+
if (isEditing) {
17+
setConsultant(newValue);
18+
}
19+
}, [newValue]);
20+
21+
return (
22+
<td className="pr-3">
23+
{isEditing ? (
24+
<input
25+
className="w-full py-2 px-3 border border-primary_50 rounded-md focus:outline-none focus:ring-1 focus:ring-primary text-sm"
26+
type="number"
27+
min="0"
28+
value={newValue}
29+
onChange={(e) => setNewValue(Number(e.target.value))}
30+
/>
31+
) : (
32+
<p className="normal text-text_light_black float-right">
33+
{newValue.toLocaleString("no-nb")}
34+
</p>
35+
)}
36+
</td>
37+
);
38+
}

frontend/src/components/consultants/FilteredConsultantsComp.tsx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import {
99
import { useSimpleConsultantsFilter } from "@/hooks/staffing/useConsultantsFilter";
1010
import Image from "next/image";
1111
import React, { useContext, useEffect, useRef, useState } from "react";
12-
import { Edit3, Check } from "react-feather";
12+
import { Edit3, Check, Info } from "react-feather";
1313
import EditableTableTextCell from "./EditableTableTextCell";
14+
import EditableTableNumberCell from "./EditableTableNumberCell";
1415
import EditableTableDateCell from "./EditableTableDateCell";
1516
import { FilteredContext } from "@/hooks/ConsultantFilterProvider";
1617
import EditableTableSelectDepartmentCell from "./EditableTableSelectDepartmentCell";
@@ -155,6 +156,18 @@ export default function FilteredConsultantsComp({
155156
<p className="normal text-left">Eksamensår</p>
156157
</div>
157158
</th>
159+
160+
<th className="py-1 pt-3 w-20">
161+
<div className="flex flex-col gap-1">
162+
<p className="normal text-left" title="Estimert timepris">
163+
Timepris
164+
<span className="pl-1">
165+
<Info className="inline" size="15" />
166+
</span>
167+
</p>
168+
</div>
169+
</th>
170+
158171
<th className="py-1 pt-3 w-14">
159172
<div className="flex flex-col gap-1"></div>
160173
</th>
@@ -327,6 +340,20 @@ export default function FilteredConsultantsComp({
327340
isEditing={selectedEditConsultant?.id === consultant.id}
328341
/>
329342

343+
<EditableTableNumberCell
344+
setConsultant={(hourPrice: number) =>
345+
setSelectedEditConsultant((selectedConsultant) => {
346+
if (!selectedConsultant) return null;
347+
return {
348+
...selectedConsultant,
349+
estimatedHourPrice: hourPrice,
350+
};
351+
})
352+
}
353+
number={consultant.estimatedHourPrice}
354+
isEditing={selectedEditConsultant?.id === consultant.id}
355+
/>
356+
330357
<td className="rounded-r-md">
331358
<button
332359
className="flex self-center hover:bg-background_light_purple p-2 rounded float-right"

0 commit comments

Comments
 (0)