mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-26 19:12:50 +00:00
fix: move the me endpoint to generic useApiQuery
This commit is contained in:
@@ -43,7 +43,7 @@ import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { z } from 'zod';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { notify, PageHeader } from '@ema-platform/ui';
|
||||
import { useApiMutation, useGetMeQuery, baseApi } from '@ema-platform/api';
|
||||
import { useApiMutation, useApiQuery } from '@ema-platform/api';
|
||||
import type { AuthUser } from '@ema-platform/auth';
|
||||
import { SUPPORTED_LANGUAGES, type AppLanguage } from '../../../i18n/config';
|
||||
import { useAppDispatch, useAppSelector } from '../../../store/hooks';
|
||||
@@ -76,9 +76,9 @@ export function ProfilePage() {
|
||||
const { colorScheme, setColorScheme } = useMantineColorScheme();
|
||||
const layoutMode = useAppSelector((state) => state.preferences.layoutMode);
|
||||
|
||||
const { data: me } = useGetMeQuery();
|
||||
const { data: me, refetch: refetchMe } = useApiQuery<AuthUser>({ url: '/auth/me', method: 'GET' });
|
||||
const storeUser = useAppSelector((state) => state.auth.user);
|
||||
const user = (me as AuthUser | undefined) ?? storeUser;
|
||||
const user = me ?? storeUser;
|
||||
const [updateTrigger] = useApiMutation<AuthUser>();
|
||||
const [passwordTrigger] = useApiMutation<unknown>();
|
||||
|
||||
@@ -133,7 +133,7 @@ export function ProfilePage() {
|
||||
},
|
||||
}).unwrap();
|
||||
|
||||
dispatch(baseApi.util.invalidateTags(['Me']));
|
||||
refetchMe();
|
||||
notify.success(t('profile.profileUpdated'));
|
||||
} catch {
|
||||
notify.error(t('profile.updateFailed'));
|
||||
|
||||
@@ -44,7 +44,7 @@ import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { z } from 'zod';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { notify, PageHeader } from '@ema-platform/ui';
|
||||
import { useApiMutation, useGetMeQuery, baseApi } from '@ema-platform/api';
|
||||
import { useApiMutation, useApiQuery } from '@ema-platform/api';
|
||||
import { authStorage, setCurrentProfile } from '@ema-platform/auth';
|
||||
import type { CurrentProfile } from '@ema-platform/auth';
|
||||
import { SUPPORTED_LANGUAGES, type AppLanguage } from '../../../i18n/config';
|
||||
@@ -86,9 +86,9 @@ export function ProfilePage() {
|
||||
const currentProfile = useAppSelector((state) => state.auth.currentProfile);
|
||||
const { colorScheme, setColorScheme } = useMantineColorScheme();
|
||||
|
||||
const { data: me } = useGetMeQuery();
|
||||
const { data: me, refetch: refetchMe } = useApiQuery<AuthUser>({ url: '/auth/me', method: 'GET' });
|
||||
const storeUser = useAppSelector((state) => state.auth.user);
|
||||
const user = (me as AuthUser | undefined) ?? storeUser;
|
||||
const user = me ?? storeUser;
|
||||
const [updateTrigger] = useApiMutation<AuthUser>();
|
||||
const [passwordTrigger] = useApiMutation<unknown>();
|
||||
const [fetchProfessions] = useApiMutation<{ count: number; items: Array<{ id: string; name: { en: string } }> }>();
|
||||
@@ -239,7 +239,7 @@ export function ProfilePage() {
|
||||
},
|
||||
}).unwrap();
|
||||
|
||||
dispatch(baseApi.util.invalidateTags(['Me']));
|
||||
refetchMe();
|
||||
notify.success(t('profile.profileUpdated'));
|
||||
} catch {
|
||||
notify.error(t('profile.updateFailed'));
|
||||
|
||||
@@ -4,6 +4,6 @@ import { baseQueryWithReauth } from './base-query-with-reauth';
|
||||
export const baseApi = createApi({
|
||||
reducerPath: 'baseApi',
|
||||
baseQuery: baseQueryWithReauth,
|
||||
tagTypes: ['Api', 'Me'],
|
||||
tagTypes: ['Api'],
|
||||
endpoints: () => ({}),
|
||||
});
|
||||
|
||||
@@ -22,15 +22,11 @@ const queryApi = baseApi.injectEndpoints({
|
||||
headers,
|
||||
}),
|
||||
}),
|
||||
getMe: builder.query<unknown, void>({
|
||||
query: () => '/auth/me',
|
||||
providesTags: ['Me'],
|
||||
}),
|
||||
}),
|
||||
overrideExisting: false,
|
||||
});
|
||||
|
||||
export const { useApiQueryQuery, useApiMutationMutation, useGetMeQuery } = queryApi;
|
||||
export const { useApiQueryQuery, useApiMutationMutation } = queryApi;
|
||||
|
||||
export function useApiQuery<TData = unknown>(
|
||||
args: ApiQueryArgs,
|
||||
|
||||
Reference in New Issue
Block a user