-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from Bayusetiawan45/feature-alert
Feature Notification System
- Loading branch information
Showing
9 changed files
with
91 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use client' | ||
|
||
import { AnimatePresence, motion } from 'framer-motion' | ||
import React, { useEffect } from 'react' | ||
|
||
import { useNotifStore } from '@/stores/notif' | ||
|
||
export default function Notif() { | ||
const { isOpen, text, hideNotif } = useNotifStore() | ||
|
||
useEffect(() => { | ||
const timeout = setTimeout(() => { | ||
hideNotif() | ||
}, 3000) | ||
|
||
return () => clearTimeout(timeout) | ||
}, [hideNotif, isOpen]) | ||
|
||
return ( | ||
<AnimatePresence> | ||
{isOpen && ( | ||
<motion.div | ||
initial={{ opacity: 0, y: -20 }} | ||
animate={{ opacity: 1, y: 0 }} | ||
exit={{ opacity: 0, y: 20 }} | ||
transition={{ duration: 0.3 }} | ||
className="fixed top-6 font-sans right-6 text-sm rounded-md opacity-70 bg-neutral-200 text-neutral-900 py-1 px-2" | ||
> | ||
{text} | ||
</motion.div> | ||
)} | ||
</AnimatePresence> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { useNotifStore } from '@/stores/notif' | ||
|
||
export function useNotif() { | ||
const { showNotif, setNotifText } = useNotifStore() | ||
|
||
function notif(text: string) { | ||
setNotifText(text) | ||
showNotif() | ||
} | ||
|
||
return notif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { create } from 'zustand' | ||
|
||
export interface InitialNotifState { | ||
isOpen: boolean | ||
text: string | ||
} | ||
|
||
export interface InitialNotifAction { | ||
showNotif(): void | ||
hideNotif(): void | ||
setNotifText(text: string): void | ||
} | ||
|
||
export const useNotifStore = create<InitialNotifState & InitialNotifAction>()(set => ({ | ||
isOpen: false, | ||
text: '', | ||
showNotif: () => set({ isOpen: true }), | ||
hideNotif: () => set({ isOpen: false }), | ||
setNotifText: (text: string) => set({ text }) | ||
})) |