Skip to content

Commit

Permalink
Merge pull request #581 from Arnei/simplify-notifications-syntax
Browse files Browse the repository at this point in the history
Simplify code for Notifications.tsx
  • Loading branch information
ziegenberg authored Jun 4, 2024
2 parents 32f386a + 56ce0d2 commit fdbdc96
Showing 1 changed file with 9 additions and 28 deletions.
37 changes: 9 additions & 28 deletions src/components/shared/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,28 @@ import {
NOTIFICATION_CONTEXT,
NOTIFICATION_CONTEXT_ACCESS,
} from "../../configs/modalConfig";
import { useAppDispatch } from "../../store";
import { setHidden } from "../../slices/notificationSlice";
import { useAppDispatch, useAppSelector } from "../../store";
import { OurNotification, setHidden } from "../../slices/notificationSlice";

/**
* This component renders notifications about occurred errors, warnings and info
*/
const Notifications : React.FC<{
notifications: any,
globalPosition: any,
context?: any,
context?: string,
}> = ({
notifications,
globalPosition,
context,
}) => {
const { t } = useTranslation();
const dispatch = useAppDispatch();

// @ts-expect-error TS(7006): Parameter 'id' implicitly has an 'any' type.
const closeNotification = (id) => {
const notifications = useAppSelector(getNotifications);
const globalPosition = useAppSelector(getGlobalPositions);

const closeNotification = (id: number) => {
dispatch(setHidden({id: id, isHidden: true}));
};

// @ts-expect-error TS(7006): Parameter 'notification' implicitly has an 'any' t... Remove this comment to see the full error message
const renderNotification = (notification, key) => (
const renderNotification = (notification: OurNotification, key: number) => (
<li key={key}>
<div className={cn(notification.type, "alert sticky")}>
<button
Expand All @@ -51,7 +48,6 @@ const Notifications : React.FC<{
context === "not_corner" ? (
<ul>
{notifications.map(
// @ts-expect-error TS(7006): Parameter 'notification' implicitly has an 'any' t... Remove this comment to see the full error message
(notification, key) =>
!notification.hidden &&
(notification.context === NOTIFICATION_CONTEXT ||
Expand All @@ -62,7 +58,6 @@ const Notifications : React.FC<{
) : context === "above_table" ? (
<ul>
{notifications.map(
// @ts-expect-error TS(7006): Parameter 'notification' implicitly has an 'any' t... Remove this comment to see the full error message
(notification, key) =>
!notification.hidden &&
notification.context === "global" &&
Expand All @@ -83,7 +78,6 @@ const Notifications : React.FC<{
})}
>
{notifications.map(
// @ts-expect-error TS(7006): Parameter 'notification' implicitly has an 'any' t... Remove this comment to see the full error message
(notification, key) =>
!notification.hidden &&
notification.context === "global" &&
Expand All @@ -94,17 +88,4 @@ const Notifications : React.FC<{
);
};

// Getting state data out of redux store
// @ts-expect-error TS(7006): Parameter 'state' implicitly has an 'any' type.
const mapStateToProps = (state) => ({
notifications: getNotifications(state),
globalPosition: getGlobalPositions(state),
});

// Mapping actions to dispatch
// @ts-expect-error TS(7006): Parameter 'dispatch' implicitly has an 'any' type.
const mapDispatchToProps = (dispatch) => ({

});

export default connect(mapStateToProps, mapDispatchToProps)(Notifications);
export default Notifications;

0 comments on commit fdbdc96

Please sign in to comment.