diff --git a/src/components/customerCases/customerCase/CustomerCase.tsx b/src/components/customerCases/customerCase/CustomerCase.tsx
index 86244953a..68a347c70 100644
--- a/src/components/customerCases/customerCase/CustomerCase.tsx
+++ b/src/components/customerCases/customerCase/CustomerCase.tsx
@@ -2,7 +2,7 @@ import Image from "next/image";
import { SanitySharedImage } from "src/components/image/SanityImage";
import Text from "src/components/text/Text";
-import { fetchEmployeeByAlias } from "src/utils/employees";
+import { fetchEmployeesByEmails } from "src/utils/employees";
import {
CustomerCase as CustomerCaseDocument,
CustomerCaseSection as CustomerCaseSectionObject,
@@ -42,14 +42,10 @@ export interface CustomerCaseProps {
export default async function CustomerCase({
customerCase,
}: CustomerCaseProps) {
- const consultantsResult = await Promise.all(
- customerCase.projectInfo.consultants.map((alias) =>
- fetchEmployeeByAlias(alias),
- ),
+ const consultantsResult = await fetchEmployeesByEmails(
+ customerCase.projectInfo.consultants,
);
- const consultants = consultantsResult.filter((c) => c.ok).map((c) => c.value);
-
return (
@@ -124,14 +120,14 @@ export default async function CustomerCase({
)}
)}
- {customerCase.projectInfo.consultants && (
+ {consultantsResult.ok && (
Konsulenter
- {consultants.map((c) => c.name).join(", ")}
+ {consultantsResult.value.map((c) => c.name).join(", ")}
)}
@@ -142,46 +138,50 @@ export default async function CustomerCase({
))}
-
-
Varianter på prosjektet
-
- {consultants.map(
- (consultant) =>
- consultant.imageThumbUrl &&
- consultant.name &&
- consultant.email && (
-
-
-
-
-
-
{consultant.name}
- {consultant.officeName && (
-
- {consultant.officeName}
-
- )}
- {consultant.email && (
-
- {consultant.email}
-
- )}
- {consultant.telephone && (
-
- {consultant.telephone}
+ {consultantsResult.ok && (
+
+
Varianter på prosjektet
+
+ {consultantsResult.value.map(
+ (consultant) =>
+ consultant.imageThumbUrl &&
+ consultant.name &&
+ consultant.email && (
+
+
+
+
+
+
+ {consultant.name}
- )}
+ {consultant.officeName && (
+
+ {consultant.officeName}
+
+ )}
+ {consultant.email && (
+
+ {consultant.email}
+
+ )}
+ {consultant.telephone && (
+
+ {consultant.telephone}
+
+ )}
+
-
- ),
- )}
+ ),
+ )}
+
-
+ )}
);
diff --git a/src/types/employees.ts b/src/types/employees.ts
index fff93d9ec..0fb875b8e 100644
--- a/src/types/employees.ts
+++ b/src/types/employees.ts
@@ -16,12 +16,6 @@ export function isChewbaccaEmployeesResponse(
);
}
-export function isChewbaccaEmployeeResponse(
- value: unknown,
-): value is ChewbaccaEmployeeResponse {
- return isChewbaccaEmployee(value);
-}
-
export interface ChewbaccaEmployee {
email?: string | null;
name?: string | null;
diff --git a/src/utils/employees.ts b/src/utils/employees.ts
index 84002d203..1e0720140 100644
--- a/src/utils/employees.ts
+++ b/src/utils/employees.ts
@@ -1,6 +1,5 @@
import {
ChewbaccaEmployee,
- isChewbaccaEmployeeResponse,
isChewbaccaEmployeesResponse,
} from "src/types/employees";
import { Result, ResultError, ResultOk } from "studio/utils/result";
@@ -58,23 +57,19 @@ export function domainFromEmail(email: string) {
return email.split("@")[1];
}
-export async function fetchEmployeeByAlias(
- alias: string,
-): Promise> {
- const country = "no"; // TODO: https://github.com/varianter/chewbacca/issues/132
- const employeeRes = await fetch(
- new URL(`employees/${alias}?country=${country}`, CHEWBACCA_URL),
- );
- if (!employeeRes.ok) {
- return ResultError(
- `Fetch returned status ${employeeRes.status} ${employeeRes.statusText}`,
- );
- }
- const employeeData = await employeeRes.json();
- if (!isChewbaccaEmployeeResponse(employeeData)) {
- return ResultError(
- `Expected ChewbaccaEmployeeResponse, was ${employeeData}`,
- );
+export async function fetchEmployeesByEmails(
+ emails: string[],
+): Promise> {
+ const allEmployeesRes = await fetchAllChewbaccaEmployees();
+ if (!allEmployeesRes.ok) {
+ return allEmployeesRes;
}
- return ResultOk(employeeData);
+ return ResultOk(
+ // mapping from input array (instead of filtering all employees) to preserve order
+ emails
+ .map((email) =>
+ allEmployeesRes.value.find((employee) => employee.email === email),
+ )
+ .filter((employee) => employee !== undefined),
+ );
}
diff --git a/studioShared/schemas/fields/customerCaseProjectInfo.ts b/studioShared/schemas/fields/customerCaseProjectInfo.ts
index 966d5ca8b..89744d184 100644
--- a/studioShared/schemas/fields/customerCaseProjectInfo.ts
+++ b/studioShared/schemas/fields/customerCaseProjectInfo.ts
@@ -69,7 +69,7 @@ export const customerCaseProjectInfo = defineField({
// TODO: We should be able to select the consultants from a list
name: "consultants",
description:
- "The consultants for the project. Use the identifier before '@' in the employee email (e.g. 'oms' for 'oms@variant.no').",
+ "The consultants for the project. Use employee emails (e.g. 'oms@variant.no').",
type: "array",
of: [{ type: "string" }],
}),