Skip to content

Commit

Permalink
fix useDepartmentsApi and add mockDepartments
Browse files Browse the repository at this point in the history
  • Loading branch information
sigridge committed Oct 12, 2023
1 parent 1348934 commit 45eda2e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
8 changes: 8 additions & 0 deletions frontend/mockdata/mockDepartments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Department, Variant } from "@/types";

export const MockDepartments: Department[] = [
{
id: "myDepartment",
name: "My Department",
},
];
4 changes: 4 additions & 0 deletions frontend/src/auth/fetchWithToken.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { msalInstance } from "@/auth/msalInstance";
import { loginRequest } from "@/authConfig";
import { MockConsultants } from "../../mockdata/mockConsultants";
import { MockDepartments } from "../../mockdata/mockDepartments";

export async function fetchWithToken(path: string) {
if (process.env.NEXT_PUBLIC_NO_AUTH) {
Expand Down Expand Up @@ -49,4 +50,7 @@ function mockedCall(path: string) {
if (path.includes("/variants")) {
return MockConsultants;
}
if (path.includes("/departments")) {
return MockDepartments;
}
}
6 changes: 4 additions & 2 deletions frontend/src/hooks/useDepartmentsApi.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"use client";
import { fetchWithToken } from "@/utils/ApiUtils";

import { useIsAuthenticated } from "@azure/msal-react";
import { useQuery } from "react-query";
import { Department } from "@/types";
import { fetchWithToken } from "@/auth/fetchWithToken";

function useDepartmentsApi() {
const isAuthenticated = useIsAuthenticated();
const isAuthenticated =
useIsAuthenticated() || process.env.NEXT_PUBLIC_NO_AUTH;

return useQuery({
queryKey: "departments",
Expand Down

0 comments on commit 45eda2e

Please sign in to comment.