pl-fe: migrate /api/v*/instance to tanstack query
Signed-off-by: mkljczk <git@mkljczk.pl>
This commit is contained in:
@ -1,12 +1,6 @@
|
||||
import { getAuthUserUrl, getMeUrl } from 'pl-fe/utils/auth';
|
||||
|
||||
import { getClient } from '../api';
|
||||
|
||||
import type { Instance } from 'pl-api';
|
||||
import type { AppDispatch, RootState } from 'pl-fe/store';
|
||||
|
||||
const INSTANCE_FETCH_SUCCESS = 'INSTANCE_FETCH_SUCCESS' as const;
|
||||
const INSTANCE_FETCH_FAIL = 'INSTANCE_FETCH_FAIL' as const;
|
||||
import type { RootState } from 'pl-fe/store';
|
||||
|
||||
/** Figure out the appropriate instance to fetch depending on the state */
|
||||
const getHost = (state: RootState) => {
|
||||
@ -19,34 +13,4 @@ const getHost = (state: RootState) => {
|
||||
}
|
||||
};
|
||||
|
||||
interface InstanceFetchSuccessAction {
|
||||
type: typeof INSTANCE_FETCH_SUCCESS;
|
||||
instance: Instance;
|
||||
}
|
||||
|
||||
interface InstanceFetchFailAction {
|
||||
type: typeof INSTANCE_FETCH_FAIL;
|
||||
error: unknown;
|
||||
}
|
||||
|
||||
const fetchInstance = () => async (dispatch: AppDispatch, getState: () => RootState) => {
|
||||
try {
|
||||
const instance = await getClient(getState).instance.getInstance();
|
||||
|
||||
dispatch<InstanceFetchSuccessAction>({ type: INSTANCE_FETCH_SUCCESS, instance });
|
||||
} catch (error) {
|
||||
dispatch({ type: INSTANCE_FETCH_FAIL, error });
|
||||
}
|
||||
};
|
||||
|
||||
type InstanceAction =
|
||||
InstanceFetchSuccessAction
|
||||
| InstanceFetchFailAction
|
||||
|
||||
export {
|
||||
INSTANCE_FETCH_SUCCESS,
|
||||
INSTANCE_FETCH_FAIL,
|
||||
getHost,
|
||||
fetchInstance,
|
||||
type InstanceAction,
|
||||
};
|
||||
export { getHost };
|
||||
|
||||
Reference in New Issue
Block a user