Refactor notificationHeaderButton

This commit is contained in:
Rafael 2021-12-20 09:32:32 -03:00 committed by Thomas Zarebczan
parent 254fff208d
commit 80a375fecb
3 changed files with 14 additions and 30 deletions

View file

@ -5,7 +5,7 @@ import * as ICONS from 'constants/icons';
import * as PAGES from 'constants/pages'; import * as PAGES from 'constants/pages';
import HeaderMenuLink from 'component/common/header-menu-link'; import HeaderMenuLink from 'component/common/header-menu-link';
import Icon from 'component/common/icon'; import Icon from 'component/common/icon';
import NotificationHeaderButton from 'component/notificationHeaderButton'; import NotificationHeaderButton from 'component/headerNotificationButton';
import React from 'react'; import React from 'react';
type HeaderMenuButtonProps = { type HeaderMenuButtonProps = {

View file

@ -1,16 +1,10 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { import { selectUnseenNotificationCount } from 'redux/selectors/notifications';
selectNotifications,
selectIsFetchingNotifications,
selectUnseenNotificationCount,
} from 'redux/selectors/notifications';
import { doSeeAllNotifications } from 'redux/actions/notifications'; import { doSeeAllNotifications } from 'redux/actions/notifications';
import { selectUser } from 'redux/selectors/user'; import { selectUser } from 'redux/selectors/user';
import NotificationHeaderButton from './view'; import NotificationHeaderButton from './view';
const select = state => ({ const select = (state) => ({
notifications: selectNotifications(state),
fetching: selectIsFetchingNotifications(state),
unseenCount: selectUnseenNotificationCount(state), unseenCount: selectUnseenNotificationCount(state),
user: selectUser(state), user: selectUser(state),
}); });

View file

@ -1,41 +1,31 @@
// @flow // @flow
import * as PAGES from 'constants/pages'; import { ENABLE_UI_NOTIFICATIONS } from 'config';
import { useHistory } from 'react-router';
import * as ICONS from 'constants/icons'; import * as ICONS from 'constants/icons';
import React from 'react'; import * as PAGES from 'constants/pages';
import Button from 'component/button';
import Icon from 'component/common/icon'; import Icon from 'component/common/icon';
import NotificationBubble from 'component/notificationBubble'; import NotificationBubble from 'component/notificationBubble';
import Button from 'component/button'; import React from 'react';
import { useHistory } from 'react-router';
import { ENABLE_UI_NOTIFICATIONS } from 'config';
type Props = { type Props = {
unseenCount: number, unseenCount: number,
doSeeAllNotifications: () => void,
user: ?User, user: ?User,
doSeeAllNotifications: () => void,
}; };
export default function NotificationHeaderButton(props: Props) { export default function NotificationHeaderButton(props: Props) {
const { const { unseenCount, user, doSeeAllNotifications } = props;
unseenCount,
// notifications,
// fetching,
doSeeAllNotifications,
user,
} = props;
const notificationsEnabled = ENABLE_UI_NOTIFICATIONS || (user && user.experimental_ui);
const { push } = useHistory(); const { push } = useHistory();
const notificationsEnabled = ENABLE_UI_NOTIFICATIONS || (user && user.experimental_ui);
function handleMenuClick() { function handleMenuClick() {
if (unseenCount > 0) { if (unseenCount > 0) doSeeAllNotifications();
doSeeAllNotifications();
}
push(`/$/${PAGES.NOTIFICATIONS}`); push(`/$/${PAGES.NOTIFICATIONS}`);
} }
if (!notificationsEnabled) { if (!notificationsEnabled) return null;
return null;
}
return ( return (
<Button <Button