diff --git a/package.json b/package.json index 34fad00cb..4b878193d 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "linkedout-front", - "version": "2.13.0", + "version": "2.13.1", "description": "", "main": "index.js", "engines": { diff --git a/src/components/backoffice/profile/useSelectedProfile.ts b/src/components/backoffice/profile/useSelectedProfile.ts index aefee29d6..c837e0f97 100644 --- a/src/components/backoffice/profile/useSelectedProfile.ts +++ b/src/components/backoffice/profile/useSelectedProfile.ts @@ -1,6 +1,9 @@ import { useEffect } from 'react'; import { useDispatch, useSelector } from 'react-redux'; +import UIkit from 'uikit'; +import { ReduxRequestEvents } from 'src/constants'; import { useUserId } from 'src/hooks/queryParams/useUserId'; +import { usePrevious } from 'src/hooks/utils'; import { profilesActions } from 'src/use-cases/profiles'; import { fetchSelectedProfileSelectors, @@ -9,23 +12,36 @@ import { export function useSelectedProfile() { const userId = useUserId(); + const prevUserId = usePrevious(userId); const dispatch = useDispatch(); - const isFetchedSelectedProfileIdle = useSelector( - fetchSelectedProfileSelectors.selectIsFetchSelectedProfileIdle + const fetchSelectedProfileStatus = useSelector( + fetchSelectedProfileSelectors.selectFetchSelectedProfileStatus + ); + const prevFetchSelectedProfileStatus = usePrevious( + fetchSelectedProfileStatus ); const selectedProfile = useSelector(selectSelectedProfile); useEffect(() => { - if (isFetchedSelectedProfileIdle && userId) { + if (userId && userId !== prevUserId) { dispatch( profilesActions.fetchSelectedProfileRequested({ userId: userId as string, }) ); } - }, [dispatch, isFetchedSelectedProfileIdle, userId]); + }, [dispatch, userId, prevUserId]); + + useEffect(() => { + if (prevFetchSelectedProfileStatus === ReduxRequestEvents.REQUESTED) { + if (fetchSelectedProfileStatus === ReduxRequestEvents.FAILED) { + UIkit.notification('Une erreur est survenue', 'danger'); + } + dispatch(profilesActions.fetchSelectedProfileReset()); + } + }, [dispatch, fetchSelectedProfileStatus, prevFetchSelectedProfileStatus]); return { selectedProfile,