Skip to content

Commit

Permalink
fix/2.13.1
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulEntourage committed Jan 29, 2024
1 parent 7006e58 commit 8d2e2d7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "linkedout-front",
"version": "2.13.0",
"version": "2.13.1",
"description": "",
"main": "index.js",
"engines": {
Expand Down
24 changes: 20 additions & 4 deletions src/components/backoffice/profile/useSelectedProfile.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 8d2e2d7

Please sign in to comment.