Skip to content

Commit

Permalink
Notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
azymazy committed Oct 23, 2024
1 parent 0da109f commit c513584
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/features/ModalFlightsQuota/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import {
Stack,
} from '@mui/material'
import { Theme } from '@mui/material/styles'
import { Notification } from '@/shared'
import IconClose from '@mui/icons-material/Close'

import { useFlightsQuotaMutation } from '@/shared'
import { NumberControl, SelectMotive } from './ui'
import { Notifications, NumberControl, SelectMotive } from './ui'

const MIN_QUOTA = 0
const MAX_QUOTA = 3
Expand Down Expand Up @@ -69,7 +68,7 @@ export function ModalFlightsQuota({
quota: initialValue,
},
})
const { mutate, isError } = useFlightsQuotaMutation()
const { mutate, isError, isSuccess } = useFlightsQuotaMutation()
const motive = watch('motive')
const quota = watch('quota')
const motiveOptions = getMotiveOptions(initialValue, quota)
Expand All @@ -85,7 +84,7 @@ export function ModalFlightsQuota({

return (
<>
{isError && <Notification message="Flights quota update failed" />}
<Notifications isError={isError} isSuccess={isSuccess} />
<Dialog closeAfterTransition={false} open={isOpen} onClose={handleClose}>
<DialogTitle>Edit flights</DialogTitle>
<DialogContent>
Expand Down
20 changes: 20 additions & 0 deletions src/features/ModalFlightsQuota/ui/Notifications.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Notification } from '@/shared'

type NotificationsProps = {
isError: boolean
isSuccess: boolean
}

export function Notifications({ isError, isSuccess }: NotificationsProps) {
return (
<>
{isError && <Notification message="Flights quota update failed" />}
{isSuccess && (
<Notification
message="Flights quota successfully updated"
severity="success"
/>
)}
</>
)
}
1 change: 1 addition & 0 deletions src/features/ModalFlightsQuota/ui/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './Notifications'
export * from './NumberControl'
export * from './SelectMotive'
3 changes: 2 additions & 1 deletion src/shared/ui/Notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ export function Notification({

return (
<Snackbar
autoHideDuration={5000}
anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
autoHideDuration={5000}
ClickAwayListenerProps={{ onClickAway: () => null }}
onClose={onClose}
open={isOpen}
>
Expand Down

0 comments on commit c513584

Please sign in to comment.