-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathcontributor.ts
More file actions
22 lines (21 loc) · 911 Bytes
/
contributor.ts
File metadata and controls
22 lines (21 loc) · 911 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 { contributorPageSlice } from "src/redux/slices/contributor-page";
import { AppState } from "src/redux/store";
import { fetchV2 } from "src/utils/fetch";
export const fetchContributorAction =
(id?: string): ThunkAction<void, AppState, unknown, Action> =>
async (dispatch) => {
if (!id) {
dispatch(contributorPageSlice.actions.set({ contributor: "404" }));
return;
}
try {
dispatch(contributorPageSlice.actions.set({ contributor: null }));
const { contributor } = await fetchV2("api:contributors/:id", { params: { id } });
dispatch(contributorPageSlice.actions.set({ contributor }));
} catch (error) {
dispatch(contributorPageSlice.actions.set({ contributor: "ERROR" }));
faro.api.pushError(error as Error, { type: "WEB_FETCH" });
}
};