-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathproject.ts
More file actions
22 lines (21 loc) · 859 Bytes
/
project.ts
File metadata and controls
22 lines (21 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { faro } from "@grafana/faro-react";
import { Action, ThunkAction } from "@reduxjs/toolkit";
import { projectPageSlice } from "src/redux/slices/project-page";
import { AppState } from "src/redux/store";
import { fetchV2 } from "src/utils/fetch";
export const fetchProjectAction =
(id?: string): ThunkAction<void, AppState, unknown, Action> =>
async (dispatch) => {
if (!id) {
dispatch(projectPageSlice.actions.set({ project: "404" }));
return;
}
try {
dispatch(projectPageSlice.actions.set({ project: null }));
const { project } = await fetchV2("api:projects/:id", { params: { id } });
dispatch(projectPageSlice.actions.set({ project }));
} catch (error) {
dispatch(projectPageSlice.actions.set({ project: "ERROR" }));
faro.api.pushError(error as Error, { type: "WEB_FETCH" });
}
};