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