Skip to content

Commit

Permalink
fix logic for rendering toast and modal
Browse files Browse the repository at this point in the history
  • Loading branch information
jerader committed Oct 23, 2024
1 parent b1758f8 commit b6aa06a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import { getFileMetadata } from '../../../file-data/selectors'
import { toggleNewProtocolModal } from '../../../navigation/actions'
import { useKitchen } from '../../../organisms/Kitchen/hooks'
import { useAnnouncements } from '../../../organisms/AnnouncementModal/announcements'
import { getHasOptedIn } from '../../../analytics/selectors'
import { Landing } from '../index'

vi.mock('../../../load-file/actions')
vi.mock('../../../file-data/selectors')
vi.mock('../../../navigation/actions')
vi.mock('../../../organisms/AnnouncementModal/announcements')
vi.mock('../../../organisms/Kitchen/hooks')
vi.mock('../../../analytics/selectors')

const mockMakeSnackbar = vi.fn()
const mockEatToast = vi.fn()
Expand All @@ -33,6 +35,7 @@ const render = () => {

describe('Landing', () => {
beforeEach(() => {
vi.mocked(getHasOptedIn).mockReturnValue(false)
vi.mocked(getFileMetadata).mockReturnValue({})
vi.mocked(loadProtocolFile).mockReturnValue(vi.fn())
vi.mocked(useAnnouncements).mockReturnValue({} as any)
Expand Down
7 changes: 4 additions & 3 deletions protocol-designer/src/pages/Landing/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { actions as loadFileActions } from '../../load-file'
import { getFileMetadata } from '../../file-data/selectors'
import { toggleNewProtocolModal } from '../../navigation/actions'
import { useKitchen } from '../../organisms/Kitchen/hooks'
import { getHasOptedIn } from '../../analytics/selectors'
import { useAnnouncements } from '../../organisms/AnnouncementModal/announcements'
import { getLocalStorageItem, localStorageAnnouncementKey } from '../../persist'
import welcomeImage from '../../assets/images/welcome_page.png'
Expand All @@ -37,17 +38,17 @@ export function Landing(): JSX.Element {
const [showAnnouncementModal, setShowAnnouncementModal] = useState<boolean>(
false
)
const hasOptedIn = useSelector(getHasOptedIn)
const { bakeToast, eatToast } = useKitchen()
const announcements = useAnnouncements()
const lastAnnouncement = announcements[announcements.length - 1]
const announcementKey = lastAnnouncement
? lastAnnouncement.announcementKey
: null
const showGateModal =
process.env.NODE_ENV === 'production' || process.env.OT_PD_SHOW_GATE

const userHasNotSeenAnnouncement =
getLocalStorageItem(localStorageAnnouncementKey) !== announcementKey &&
!showGateModal
hasOptedIn != null

useEffect(() => {
if (userHasNotSeenAnnouncement) {
Expand Down

0 comments on commit b6aa06a

Please sign in to comment.