-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update entry point for whats new modal
- Loading branch information
Showing
5 changed files
with
78 additions
and
66 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
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
49 changes: 49 additions & 0 deletions
49
packages/frontend/components/WhatsNewModal/WhatsNewModalContextProvider.tsx
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,49 @@ | ||
import { | ||
createContext, | ||
useContext, | ||
useState, | ||
ReactNode, | ||
useEffect, | ||
} from "react"; | ||
import { WhatsNewModal } from "./WhatsNewModal"; | ||
import { Fall2024ReleaseModalContent } from "./Fall2024ReleaseModalContent"; | ||
import Cookies from "universal-cookie"; | ||
|
||
const WhatsNewModalContext = createContext<{ openModal: () => void }>({ | ||
openModal: () => {}, | ||
}); | ||
|
||
export const WhatsNewModalContextProvider = ({ | ||
children, | ||
}: { | ||
children: ReactNode; | ||
}) => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
const openModal = () => setIsOpen(true); | ||
const cookies = new Cookies(); | ||
Check warning on line 23 in packages/frontend/components/WhatsNewModal/WhatsNewModalContextProvider.tsx GitHub Actions / Run linting for all packages
|
||
|
||
useEffect(() => { | ||
const existingToken = cookies.get("WhatsNewModal JWT"); | ||
|
||
if (!existingToken) { | ||
setIsOpen(true); // Open modal only if token doesn't exist | ||
} | ||
}, [cookies]); | ||
|
||
const handleClose = () => { | ||
setIsOpen(false); // Close the modal when user dismisses it | ||
const newToken = "alreadyShowedModal"; | ||
cookies.set("WhatsNewModal JWT", newToken, { path: "/" }); // Set the token when user closes the modal | ||
}; | ||
|
||
return ( | ||
<WhatsNewModalContext.Provider value={{ openModal }}> | ||
{children} | ||
<WhatsNewModal isOpen={isOpen} onClose={handleClose}> | ||
<Fall2024ReleaseModalContent onClose={handleClose} /> | ||
</WhatsNewModal> | ||
</WhatsNewModalContext.Provider> | ||
); | ||
}; | ||
|
||
export const useWhatsNewModal = () => useContext(WhatsNewModalContext); |
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