Skip to content

Commit 1fc2ecd

Browse files
committed
lint fixes
1 parent 6f9bb56 commit 1fc2ecd

File tree

8 files changed

+78
-51
lines changed

8 files changed

+78
-51
lines changed

src/apps/platform/src/PlatformApp.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { FC } from 'react'
22
import { toast, ToastContainer } from 'react-toastify'
33

4-
import { useViewportUnitsFix, NotificationsContainer } from '~/libs/shared'
4+
import { NotificationsContainer, useViewportUnitsFix } from '~/libs/shared'
55

66
import { AppFooter } from './components/app-footer'
77
import { AppHeader } from './components/app-header'

src/apps/review/src/pages/active-review-assignements/ChallengeDetailsPage/ChallengeDetailsPage.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { TableLoading } from '~/apps/admin/src/lib'
1313
import { handleError } from '~/apps/admin/src/lib/utils'
1414
import { EnvironmentConfig } from '~/config'
1515
import { BaseModal, Button, InputCheckbox, InputText } from '~/libs/ui'
16+
import { NotificationContextType, useNotification } from '~/libs/shared'
1617

1718
import {
1819
useFetchScreeningReview,
@@ -60,7 +61,6 @@ import {
6061
} from '../../../config/routes.config'
6162

6263
import styles from './ChallengeDetailsPage.module.scss'
63-
import { useNotification } from '~/libs/shared'
6464

6565
interface Props {
6666
className?: string
@@ -227,7 +227,7 @@ const computePhaseCompletionFromScreenings = (
227227

228228
// eslint-disable-next-line complexity
229229
export const ChallengeDetailsPage: FC<Props> = (props: Props) => {
230-
const { showBannerNotification, removeNotification } = useNotification();
230+
const { showBannerNotification, removeNotification }: NotificationContextType = useNotification()
231231
const [searchParams, setSearchParams] = useSearchParams()
232232
const location = useLocation()
233233
const navigate = useNavigate()
@@ -1328,10 +1328,12 @@ export const ChallengeDetailsPage: FC<Props> = (props: Props) => {
13281328
useEffect(() => {
13291329
const notification = showBannerNotification({
13301330
id: 'ai-review-scores-warning',
1331-
message: 'AI Review Scores are advisory only to provide immediate, educational, and actionable feedback to members. AI Review Scores are not influence winner selection.',
1331+
message: `AI Review Scores are advisory only to provide immediate,
1332+
educational, and actionable feedback to members.
1333+
AI Review Scores are not influence winner selection.`,
13321334
})
1333-
return () => notification && removeNotification(notification.id);
1334-
}, [showBannerNotification]);
1335+
return () => notification && removeNotification(notification.id)
1336+
}, [showBannerNotification])
13351337

13361338
return (
13371339
<PageWrapper

src/libs/core/lib/profile/profile-context/profile.context.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ export const defaultProfileContextData: ProfileContextData = {
1212

1313
const profileContext: Context<ProfileContextData> = createContext(defaultProfileContextData)
1414

15-
export const useProfileContext = () => useContext(profileContext);
15+
export const useProfileContext = (): ProfileContextData => useContext(profileContext)
1616

1717
export default profileContext

src/libs/shared/lib/components/notifications/Notifications.container.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { FC } from 'react'
22

33
import { Notification } from '~/libs/ui'
44

5-
import { useNotification } from './Notifications.context';
5+
import { NotificationContextType, useNotification } from './Notifications.context'
66

77
const NotificationsContainer: FC = () => {
8-
const { notifications, removeNotification } = useNotification();
8+
const { notifications, removeNotification }: NotificationContextType = useNotification()
99

1010
return (
1111
<div>
Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import React, { createContext, useContext, useState, useCallback, ReactNode } from "react";
2-
import { useProfileContext } from "~/libs/core";
3-
import { dismiss, wasDismissed } from "./localstorage.utils";
1+
import React, { createContext, ReactNode, useCallback, useContext, useMemo, useState } from 'react'
42

5-
export type NotificationType = "success" | "error" | "info" | "warning" | "banner";
3+
import { useProfileContext } from '~/libs/core'
4+
5+
import { dismiss, wasDismissed } from './localstorage.utils'
6+
7+
export type NotificationType = 'success' | 'error' | 'info' | 'warning' | 'banner';
68

79
export interface Notification {
810
id: string;
@@ -13,62 +15,77 @@ export interface Notification {
1315

1416
type NotifyPayload = string | (Partial<Notification> & { message: string })
1517

16-
interface NotificationContextType {
18+
export interface NotificationContextType {
1719
notifications: Notification[];
1820
notify: (message: NotifyPayload, type?: NotificationType, duration?: number) => Notification | void;
1921
showBannerNotification: (message: NotifyPayload) => Notification | void;
2022
removeNotification: (id: string) => void;
2123
}
2224

23-
const NotificationContext = createContext<NotificationContextType | undefined>(undefined);
25+
const NotificationContext = createContext<NotificationContextType | undefined>(undefined)
2426

2527
export const useNotification = (): NotificationContextType => {
26-
const context = useContext(NotificationContext);
27-
if (!context) throw new Error("useNotification must be used within a NotificationProvider");
28-
return context;
29-
};
28+
const context = useContext(NotificationContext)
29+
if (!context) throw new Error('useNotification must be used within a NotificationProvider')
30+
return context
31+
}
3032

3133
export const NotificationProvider: React.FC<{
3234
children: ReactNode,
33-
}> = ({ children }) => {
35+
}> = props => {
3436
const profileCtx = useProfileContext()
35-
const uuid = profileCtx.profile?.userId ?? 'annon';
36-
const [notifications, setNotifications] = useState<Notification[]>([]);
37+
const uuid = profileCtx.profile?.userId ?? 'annon'
38+
const [notifications, setNotifications] = useState<Notification[]>([])
3739

3840
const removeNotification = useCallback((id: string, persist?: boolean) => {
39-
setNotifications(prev => prev.filter(n => n.id !== id));
41+
setNotifications(prev => prev.filter(n => n.id !== id))
4042
if (persist) {
41-
dismiss(id);
43+
dismiss(id)
4244
}
43-
}, []);
45+
}, [])
4446

4547
const notify = useCallback(
46-
(message: NotifyPayload, type: NotificationType = "info", duration = 3000) => {
47-
const id = `${uuid}[${typeof message === 'string' ? message : message.id}]`;
48-
const newNotification: Notification = typeof message === 'string' ? { id, message, type, duration } : { type, duration, ...message, id };
48+
(message: NotifyPayload, type: NotificationType = 'info', duration = 3000) => {
49+
const id = `${uuid}[${typeof message === 'string' ? message : message.id}]`
50+
const newNotification: Notification
51+
= typeof message === 'string'
52+
? { duration, id, message, type }
53+
: { duration, type, ...message, id }
4954

5055
if (wasDismissed(id)) {
51-
return;
56+
return undefined
5257
}
5358

54-
setNotifications(prev => [...prev, newNotification]);
59+
setNotifications(prev => [...prev, newNotification])
5560

5661
if (duration > 0) {
57-
setTimeout(() => removeNotification(id), duration);
62+
setTimeout(() => removeNotification(id), duration)
5863
}
5964

60-
return newNotification;
65+
return newNotification
6166
},
62-
[uuid]
63-
);
67+
[uuid],
68+
)
6469

6570
const showBannerNotification = useCallback((
6671
message: NotifyPayload,
67-
) => notify(message, 'banner', 0), [notify]);
72+
) => notify(message, 'banner', 0), [notify])
73+
74+
const ctxValue = useMemo(() => ({
75+
notifications,
76+
notify,
77+
removeNotification,
78+
showBannerNotification,
79+
}), [
80+
notifications,
81+
notify,
82+
removeNotification,
83+
showBannerNotification,
84+
])
6885

6986
return (
70-
<NotificationContext.Provider value={{ notifications, notify, showBannerNotification, removeNotification }}>
71-
{children}
87+
<NotificationContext.Provider value={ctxValue}>
88+
{props.children}
7289
</NotificationContext.Provider>
73-
);
74-
};
90+
)
91+
}
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FC } from 'react'
1+
import { FC, useCallback } from 'react'
22

33
import { NotificationBanner } from './banner'
44

@@ -8,12 +8,20 @@ interface NotificationProps {
88
}
99

1010
const Notification: FC<NotificationProps> = props => {
11+
const handleClose = useCallback((save?: boolean) => {
12+
props.onClose(props.notification.id, save)
13+
}, [props.onClose])
1114

1215
if (props.notification.type === 'banner') {
13-
return <NotificationBanner content={props.notification.message} onClose={(save?: boolean) => props.onClose(props.notification.id, save)} />
16+
return (
17+
<NotificationBanner
18+
content={props.notification.message}
19+
onClose={handleClose}
20+
/>
21+
)
1422
}
1523

16-
return null;
24+
return <></>
1725
}
1826

1927
export default Notification
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1-
/* eslint-disable no-underscore-dangle */
2-
/* eslint-disable camelcase */
3-
41
import { Meta, StoryObj } from '@storybook/react'
52

63
import NotificationBanner from './NotificationBanner'
74

85
const meta: Meta<typeof NotificationBanner> = {
96
argTypes: {
7+
content: {
8+
description: 'Content displayed inside the tooltip',
9+
},
1010
persistent: {
1111
defaultValue: false,
1212
description: 'Set to true to allow clicks inside the tooltip',
1313
},
14-
content: {
15-
description: 'Content displayed inside the tooltip',
16-
},
1714
},
1815
component: NotificationBanner,
1916
excludeStories: /.*Decorator$/,
@@ -27,7 +24,6 @@ type Story = StoryObj<typeof NotificationBanner>;
2724

2825
export const Primary: Story = {
2926
args: {
30-
// children: <IconOutline.QuestionMarkCircleIcon width='35' />,
3127
content: 'Help tooltip',
3228
},
3329
}

src/libs/ui/lib/components/notification/banner/NotificationBanner.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { FC, ReactNode, useCallback } from 'react'
22

3-
import styles from './NotificationBanner.module.scss'
43
import { InformationCircleIcon, XCircleIcon } from '@heroicons/react/outline'
54

5+
import styles from './NotificationBanner.module.scss'
6+
67
interface NotificationBannerProps {
78
persistent?: boolean
89
content: ReactNode
@@ -11,6 +12,9 @@ interface NotificationBannerProps {
1112
}
1213

1314
const NotificationBanner: FC<NotificationBannerProps> = props => {
15+
const handleClose = useCallback(() => {
16+
props.onClose?.(true)
17+
}, [props.onClose])
1418

1519
return (
1620
<div className={styles.wrap}>
@@ -24,7 +28,7 @@ const NotificationBanner: FC<NotificationBannerProps> = props => {
2428
{props.content}
2529

2630
{!props.persistent && (
27-
<div className={styles.close} onClick={() => props.onClose?.(true)}>
31+
<div className={styles.close} onClick={handleClose}>
2832
<XCircleIcon className='icon-xl' />
2933
</div>
3034
)}

0 commit comments

Comments
 (0)