Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(form-v2): show emergency contact popup in workspace page #4125

Merged
merged 3 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions frontend/src/constants/localStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ export const ROLLOUT_ANNOUNCEMENT_KEY_PREFIX = 'has-seen-rollout-announcement-'
* Key to store whether the admin has seen the feature tour in localStorage.
*/
export const FEATURE_TOUR_KEY_PREFIX = 'has-seen-feature-tour-'

/**
* Key to store whether a user has seen the emergency contact number modal in localStorage.
*/
export const EMERGENCY_CONTACT_KEY_PREFIX = 'has-emergency-contact'
2 changes: 2 additions & 0 deletions frontend/src/features/workspace/WorkspacePage.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
getMobileViewParameters,
mockDateDecorator,
StoryRouter,
ViewedEmergencyContactDecorator,
ViewedRolloutDecorator,
} from '~utils/storybook'

Expand Down Expand Up @@ -56,6 +57,7 @@ export default {
component: WorkspacePage,
decorators: [
ViewedRolloutDecorator,
ViewedEmergencyContactDecorator,
StoryRouter({
initialEntries: [ROOT_ROUTE],
path: ROOT_ROUTE,
Expand Down
28 changes: 27 additions & 1 deletion frontend/src/features/workspace/WorkspacePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ import { useSearchParams } from 'react-router-dom'
import { Box, Container, Grid, useDisclosure } from '@chakra-ui/react'
import { chunk } from 'lodash'

import { ROLLOUT_ANNOUNCEMENT_KEY_PREFIX } from '~constants/localStorage'
import {
EMERGENCY_CONTACT_KEY_PREFIX,
ROLLOUT_ANNOUNCEMENT_KEY_PREFIX,
} from '~constants/localStorage'
import { useLocalStorage } from '~hooks/useLocalStorage'
import Pagination from '~components/Pagination'

import { RolloutAnnouncementModal } from '~features/rollout-announcement/RolloutAnnouncementModal'
import { EmergencyContactModal } from '~features/user/emergency-contact/EmergencyContactModal'
import { useUser } from '~features/user/queries'

import CreateFormModal from './components/CreateFormModal'
Expand Down Expand Up @@ -122,6 +126,24 @@ export const WorkspacePage = (): JSX.Element => {
[isUserLoading, hasSeenAnnouncement],
)

const EMERGENCY_CONTACT_KEY = useMemo(
wanlingt marked this conversation as resolved.
Show resolved Hide resolved
() => EMERGENCY_CONTACT_KEY_PREFIX + user?._id,
[user],
)

const [hasSeenEmergencyContact, setHasSeenEmergencyContact] =
useLocalStorage<boolean>(EMERGENCY_CONTACT_KEY)

const isEmergencyContactModalOpen = useMemo(
() =>
!isUserLoading &&
// Open emergency contact modal after the rollout announcement modal
Boolean(hasSeenAnnouncement) &&
!hasSeenEmergencyContact &&
!user?.contact,
[isUserLoading, hasSeenAnnouncement, hasSeenEmergencyContact, user],
)

return (
<>
<CreateFormModal
Expand Down Expand Up @@ -160,6 +182,10 @@ export const WorkspacePage = (): JSX.Element => {
onClose={() => setHasSeenAnnouncement(true)}
isOpen={isAnnouncementModalOpen}
/>
<EmergencyContactModal
onClose={() => setHasSeenEmergencyContact(true)}
isOpen={isEmergencyContactModalOpen}
/>
Comment on lines +185 to +188
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably not the correct place to put this, since the modal will probably be instantiated in the admin header (when it is complete) (and it is also now when i realize that is why this feature is not in the app yet)

Add a TODO i guess, to move the auto-instantiation of the modal into the admin header when that is done?

Copy link
Contributor Author

@wanlingt wanlingt Jul 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha. and this is because we want it to appear whenever an admin logs in, not just the workspace page right? will create this as a separate issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue #4153

<WorkspaceFormRows rows={paginatedData} isLoading={isLoading} />
</Box>
<Container
Expand Down
16 changes: 16 additions & 0 deletions frontend/src/utils/storybook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { theme } from '~/theme'

import { AuthContext } from '~contexts/AuthContext'
import {
EMERGENCY_CONTACT_KEY_PREFIX,
FEATURE_TOUR_KEY_PREFIX,
ROLLOUT_ANNOUNCEMENT_KEY_PREFIX,
} from '~constants/localStorage'
Expand Down Expand Up @@ -73,6 +74,21 @@ export const ViewedRolloutDecorator: DecoratorFn = (
return storyFn()
}

export const ViewedEmergencyContactDecorator: DecoratorFn = (
storyFn,
{ parameters },
) => {
const userId = parameters.userId
const emergencyContactKey = EMERGENCY_CONTACT_KEY_PREFIX + userId
window.localStorage.setItem(emergencyContactKey, JSON.stringify(true))

useEffect(() => {
return () => window.localStorage.removeItem(emergencyContactKey)
}, [emergencyContactKey, userId])

return storyFn()
}

export const EditFieldDrawerDecorator: DecoratorFn = (storyFn) => {
const deleteFieldModalDisclosure = useDisclosure()
return (
Expand Down