Skip to content

Commit

Permalink
add reddot to mrf workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
KenLSM committed Jul 4, 2024
1 parent d883952 commit 927194b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useCallback } from 'react'
import { useCallback, useMemo } from 'react'
import { BiGitMerge, BiQuestionMark } from 'react-icons/bi'
import { Divider, Stack } from '@chakra-ui/react'

import { FormResponseMode } from '~shared/types'
import { FormResponseMode, SeenFlags } from '~shared/types'

import { MultiParty, PhHandsClapping } from '~assets/icons'
import { BxsDockTop } from '~assets/icons/BxsDockTop'
Expand All @@ -17,6 +17,10 @@ import {
DrawerTabs,
useCreatePageSidebar,
} from '~features/admin-form/create/common/CreatePageSidebarContext/CreatePageSidebarContext'
import { SeenFlagsMapVersion } from '~features/user/constants'
import { useUserMutations } from '~features/user/mutations'
import { useUser } from '~features/user/queries'
import { getShowFeatureFlagLastSeen } from '~features/user/utils'

import {
isDirtySelector,
Expand All @@ -34,6 +38,13 @@ export const CreatePageSidebar = (): JSX.Element | null => {
const isMobile = useIsMobile()

const { data } = useAdminForm()
const { user, isLoading: isUserLoading } = useUser()
const { updateLastSeenFlagMutation } = useUserMutations()

const shouldShowMrfWorkflowReddot = useMemo(() => {
if (isUserLoading || !user) return false
return getShowFeatureFlagLastSeen(user, SeenFlags.CreateBuilderMrfWorkflow)
}, [isUserLoading, user])

const setFieldsToInactive = useFieldBuilderStore(setToInactiveSelector)
const isDirty = useDirtyFieldStore(isDirtySelector)
Expand Down Expand Up @@ -69,10 +80,20 @@ export const CreatePageSidebar = (): JSX.Element | null => {
[handleEndpageClick, isDirty],
)

const handleDrawerWorkflowClick = useCallback(
() => handleWorkflowClick(isDirty),
[handleWorkflowClick, isDirty],
)
const handleDrawerWorkflowClick = useCallback(() => {
handleWorkflowClick(isDirty)
if (shouldShowMrfWorkflowReddot) {
updateLastSeenFlagMutation.mutate({
flag: SeenFlags.CreateBuilderMrfWorkflow,
version: SeenFlagsMapVersion.createBuilderMrfWorkflow,
})
}
}, [
handleWorkflowClick,
updateLastSeenFlagMutation,
shouldShowMrfWorkflowReddot,
isDirty,
])

return (
<Stack
Expand Down Expand Up @@ -123,6 +144,7 @@ export const CreatePageSidebar = (): JSX.Element | null => {
icon={<MultiParty fontSize="1.5rem" />}
onClick={handleDrawerWorkflowClick}
isActive={activeTab === DrawerTabs.Workflow}
showRedDot={shouldShowMrfWorkflowReddot}
/>
</>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { GoPrimitiveDot } from 'react-icons/go'
import { Box, Icon } from '@chakra-ui/react'

import IconButton from '~components/IconButton'
import Tooltip from '~components/Tooltip'

Expand All @@ -7,6 +10,7 @@ interface DrawerTabIconProps {
label: string
isActive: boolean
id?: string
showRedDot?: boolean
}

export const DrawerTabIcon = ({
Expand All @@ -15,17 +19,28 @@ export const DrawerTabIcon = ({
label,
isActive,
id,
showRedDot,
}: DrawerTabIconProps): JSX.Element => {
return (
<Tooltip label={label} placement="right">
<IconButton
variant="reverse"
aria-label={label}
isActive={isActive}
icon={icon}
onClick={onClick}
id={id}
/>
<Box>
<IconButton
variant="reverse"
aria-label={label}
isActive={isActive}
icon={icon}
onClick={onClick}
id={id}
/>
{showRedDot ? (
<Icon
as={GoPrimitiveDot}
color="danger.500"
position="absolute"
ml="-15px"
/>
) : null}
</Box>
</Tooltip>
)
}

0 comments on commit 927194b

Please sign in to comment.