From de37c6940e28aca6ebdc8e86b9bb2a65d8ff7bee Mon Sep 17 00:00:00 2001 From: mengstabketemaw Date: Wed, 8 Jul 2026 14:15:13 +0300 Subject: [PATCH] fix: move the me endpoint to generic useApiQuery --- .../src/app/features/profile/pages/ProfilePage.tsx | 8 ++++---- .../portal/src/app/features/profile/pages/ProfilePage.tsx | 8 ++++---- libs/api/src/lib/base-api/index.ts | 2 +- libs/api/src/lib/query-and-mutation/index.ts | 6 +----- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/apps/backoffice/src/app/features/profile/pages/ProfilePage.tsx b/apps/backoffice/src/app/features/profile/pages/ProfilePage.tsx index 98fc4289c..453d06b6f 100644 --- a/apps/backoffice/src/app/features/profile/pages/ProfilePage.tsx +++ b/apps/backoffice/src/app/features/profile/pages/ProfilePage.tsx @@ -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({ 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(); const [passwordTrigger] = useApiMutation(); @@ -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')); diff --git a/apps/portal/src/app/features/profile/pages/ProfilePage.tsx b/apps/portal/src/app/features/profile/pages/ProfilePage.tsx index e5c21809e..db308081c 100644 --- a/apps/portal/src/app/features/profile/pages/ProfilePage.tsx +++ b/apps/portal/src/app/features/profile/pages/ProfilePage.tsx @@ -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({ 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(); const [passwordTrigger] = useApiMutation(); 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')); diff --git a/libs/api/src/lib/base-api/index.ts b/libs/api/src/lib/base-api/index.ts index 624526140..0570a2d88 100644 --- a/libs/api/src/lib/base-api/index.ts +++ b/libs/api/src/lib/base-api/index.ts @@ -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: () => ({}), }); diff --git a/libs/api/src/lib/query-and-mutation/index.ts b/libs/api/src/lib/query-and-mutation/index.ts index d1e3c2baa..10b736e11 100644 --- a/libs/api/src/lib/query-and-mutation/index.ts +++ b/libs/api/src/lib/query-and-mutation/index.ts @@ -22,15 +22,11 @@ const queryApi = baseApi.injectEndpoints({ headers, }), }), - getMe: builder.query({ - query: () => '/auth/me', - providesTags: ['Me'], - }), }), overrideExisting: false, }); -export const { useApiQueryQuery, useApiMutationMutation, useGetMeQuery } = queryApi; +export const { useApiQueryQuery, useApiMutationMutation } = queryApi; export function useApiQuery( args: ApiQueryArgs,