diff --git a/frontend/src/metabase/auth/actions.ts b/frontend/src/metabase/auth/actions.ts index c30ce381bd56fd48b8a657c18649476eab9444f2..bb69162bb4a864633285806e8157317d2787ea61 100644 --- a/frontend/src/metabase/auth/actions.ts +++ b/frontend/src/metabase/auth/actions.ts @@ -1,8 +1,8 @@ -import { createAsyncThunk } from "@reduxjs/toolkit"; import { push } from "react-router-redux"; import { getIn } from "icepick"; import { SessionApi, UtilApi } from "metabase/services"; import { getSetting } from "metabase/selectors/settings"; +import { createAsyncThunk } from "metabase/lib/redux"; import MetabaseSettings from "metabase/lib/settings"; import { loadLocalization } from "metabase/lib/i18n"; import { deleteSession } from "metabase/lib/auth"; @@ -10,7 +10,6 @@ import * as Urls from "metabase/lib/urls"; import { clearCurrentUser, refreshCurrentUser } from "metabase/redux/user"; import { refreshSiteSettings } from "metabase/redux/settings"; import { getUser } from "metabase/selectors/user"; -import { State } from "metabase-types/store"; import { trackLogin, trackLoginGoogle, @@ -19,12 +18,8 @@ import { } from "./analytics"; import { LoginData } from "./types"; -interface ThunkConfig { - state: State; -} - export const REFRESH_LOCALE = "metabase/user/REFRESH_LOCALE"; -export const refreshLocale = createAsyncThunk<void, void, ThunkConfig>( +export const refreshLocale = createAsyncThunk( REFRESH_LOCALE, async (_, { getState }) => { const userLocale = getUser(getState())?.locale; @@ -34,7 +29,7 @@ export const refreshLocale = createAsyncThunk<void, void, ThunkConfig>( ); export const REFRESH_SESSION = "metabase/auth/REFRESH_SESSION"; -export const refreshSession = createAsyncThunk<void, void, ThunkConfig>( +export const refreshSession = createAsyncThunk( REFRESH_SESSION, async (_, { dispatch }) => { await Promise.all([ @@ -51,9 +46,12 @@ interface LoginPayload { } export const LOGIN = "metabase/auth/LOGIN"; -export const login = createAsyncThunk<void, LoginPayload, ThunkConfig>( +export const login = createAsyncThunk( LOGIN, - async ({ data, redirectUrl = "/" }, { dispatch, rejectWithValue }) => { + async ( + { data, redirectUrl = "/" }: LoginPayload, + { dispatch, rejectWithValue }, + ) => { try { await SessionApi.create(data); await dispatch(refreshSession()).unwrap(); @@ -71,13 +69,12 @@ interface LoginGooglePayload { } export const LOGIN_GOOGLE = "metabase/auth/LOGIN_GOOGLE"; -export const loginGoogle = createAsyncThunk< - void, - LoginGooglePayload, - ThunkConfig ->( +export const loginGoogle = createAsyncThunk( LOGIN_GOOGLE, - async ({ credential, redirectUrl = "/" }, { dispatch, rejectWithValue }) => { + async ( + { credential, redirectUrl = "/" }: LoginGooglePayload, + { dispatch, rejectWithValue }, + ) => { try { await SessionApi.createWithGoogleAuth({ token: credential }); await dispatch(refreshSession()).unwrap(); @@ -90,9 +87,9 @@ export const loginGoogle = createAsyncThunk< ); export const LOGOUT = "metabase/auth/LOGOUT"; -export const logout = createAsyncThunk<void, string | undefined, ThunkConfig>( +export const logout = createAsyncThunk( LOGOUT, - async (redirectUrl, { dispatch, rejectWithValue }) => { + async (redirectUrl: string | undefined, { dispatch, rejectWithValue }) => { try { await deleteSession(); await dispatch(clearCurrentUser()); @@ -124,13 +121,12 @@ interface ResetPasswordPayload { } export const RESET_PASSWORD = "metabase/auth/RESET_PASSWORD"; -export const resetPassword = createAsyncThunk< - void, - ResetPasswordPayload, - ThunkConfig ->( +export const resetPassword = createAsyncThunk( RESET_PASSWORD, - async ({ token, password }, { dispatch, rejectWithValue }) => { + async ( + { token, password }: ResetPasswordPayload, + { dispatch, rejectWithValue }, + ) => { try { await SessionApi.reset_password({ token, password }); await dispatch(refreshSession()).unwrap(); diff --git a/frontend/src/metabase/lib/redux/index.ts b/frontend/src/metabase/lib/redux/index.ts index a7f32e6bab08c78ab339644c1bbffae43f808d20..325110e8681af52c4b8d721608761032afba4fb9 100644 --- a/frontend/src/metabase/lib/redux/index.ts +++ b/frontend/src/metabase/lib/redux/index.ts @@ -1,2 +1,3 @@ export * from "./utils"; +export * from "./typed-utils"; export * from "./hooks"; diff --git a/frontend/src/metabase/lib/redux/typed-utils.ts b/frontend/src/metabase/lib/redux/typed-utils.ts new file mode 100644 index 0000000000000000000000000000000000000000..ad49c10acd08ce31ba28247fa62457248886ce89 --- /dev/null +++ b/frontend/src/metabase/lib/redux/typed-utils.ts @@ -0,0 +1,9 @@ +import { createAsyncThunk as createAsyncThunkOriginal } from "@reduxjs/toolkit"; +import type { State } from "metabase-types/store"; + +interface ThunkConfig { + state: State; +} + +export const createAsyncThunk = + createAsyncThunkOriginal.withTypes<ThunkConfig>();