-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SDP-1451 Export Receivers and Payments
- Loading branch information
1 parent
d54e6e8
commit 1ab1eb1
Showing
7 changed files
with
89 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { createAsyncThunk } from "@reduxjs/toolkit"; | ||
import { ApiError, Export, RejectMessage } from "types"; | ||
import { getExport } from "api/getExport"; | ||
import { normalizeApiError } from "helpers/normalizeApiError"; | ||
import { endSessionIfTokenInvalid } from "helpers/endSessionIfTokenInvalid"; | ||
import { refreshSessionToken } from "helpers/refreshSessionToken"; | ||
import { RootState } from "store"; | ||
|
||
type ExportParams<T> = { | ||
exportType: Export; | ||
searchParams?: T; | ||
}; | ||
|
||
export const exportDataAction = createAsyncThunk< | ||
undefined, | ||
ExportParams<any>, | ||
{ rejectValue: RejectMessage; state: RootState } | ||
>( | ||
"common/exportDataAction", | ||
async ( | ||
{ exportType, searchParams }, | ||
{ rejectWithValue, getState, dispatch }, | ||
) => { | ||
const { token } = getState().userAccount; | ||
|
||
try { | ||
await getExport(token, exportType, searchParams); | ||
refreshSessionToken(dispatch); | ||
return; | ||
} catch (error: unknown) { | ||
const apiError = normalizeApiError(error as ApiError); | ||
const errorString = apiError.message; | ||
endSessionIfTokenInvalid(errorString, dispatch); | ||
|
||
return rejectWithValue({ | ||
errorString: `Error exporting ${exportType}: ${errorString}`, | ||
}); | ||
} | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters