Skip to content

Commit

Permalink
[PAY-1435] Navigate to chat after unblocking user on mobile (#3578)
Browse files Browse the repository at this point in the history
  • Loading branch information
dharit-tan authored Jun 13, 2023
1 parent ee1b6c3 commit a6c8ece
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { useColor } from 'app/utils/theme'

const { getUser } = cacheUsersSelectors
const { getDoesBlockUser } = chatSelectors
const { blockUser, unblockUser } = chatActions
const { blockUser, unblockUser, createChat } = chatActions

const BLOCK_MESSAGES_MODAL_NAME = 'BlockMessages'

Expand Down Expand Up @@ -106,7 +106,7 @@ export const BlockMessagesDrawer = () => {
const neutralLight2 = useColor('neutralLight2')
const neutral = useColor('neutral')
const dispatch = useDispatch()
const { userId } = useSelector((state: AppState) =>
const { userId, shouldOpenChat } = useSelector((state: AppState) =>
getData<'BlockMessages'>(state)
)
const user = useSelector((state) => getUser(state, { id: userId }))
Expand All @@ -116,6 +116,9 @@ export const BlockMessagesDrawer = () => {
const handleConfirmPress = useCallback(() => {
if (doesBlockUser) {
dispatch(unblockUser({ userId }))
if (shouldOpenChat) {
dispatch(createChat({ userIds: [userId] }))
}
} else {
dispatch(blockUser({ userId }))
}
Expand All @@ -125,7 +128,7 @@ export const BlockMessagesDrawer = () => {
visible: false
})
)
}, [dispatch, doesBlockUser, userId])
}, [dispatch, doesBlockUser, shouldOpenChat, userId])

const handleCancelPress = useCallback(() => {
dispatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { useColor } from 'app/utils/theme'

import { UserBadges } from '../user-badges'

const { unblockUser } = chatActions
const { unblockUser, createChat } = chatActions
const { getCanCreateChat } = chatSelectors
const { getUser } = cacheUsersSelectors
const { beginTip } = tippingActions
Expand Down Expand Up @@ -151,7 +151,9 @@ export const InboxUnavailableDrawer = () => {
const styles = useStyles()
const neutralLight2 = useColor('neutralLight2')

const { userId } = useSelector((state) => getData<'InboxUnavailable'>(state))
const { userId, shouldOpenChat } = useSelector((state) =>
getData<'InboxUnavailable'>(state)
)
const user = useSelector((state) => getUser(state, { id: userId }))
const { callToAction } = useSelector((state) =>
getCanCreateChat(state, { userId })
Expand All @@ -168,8 +170,11 @@ export const InboxUnavailableDrawer = () => {

const handleUnblockPress = useCallback(() => {
dispatch(unblockUser({ userId }))
if (shouldOpenChat) {
dispatch(createChat({ userIds: [userId] }))
}
closeDrawer()
}, [dispatch, userId, closeDrawer])
}, [dispatch, userId, shouldOpenChat, closeDrawer])

const handleLearnMorePress = useCallback(() => {
// TODO: Link to blog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export const ChatUserListItem = ({ userId }: ChatUserListItemProps) => {
setVisibility({
drawer: 'InboxUnavailable',
visible: true,
data: { userId: user.user_id }
data: { userId: user.user_id, shouldOpenChat: true }
})
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const MessageLockedButton = (props: MessageLockedButtonProps) => {
setVisibility({
drawer: 'InboxUnavailable',
visible: true,
data: { userId }
data: { userId, shouldOpenChat: true }
})
)
}, [dispatch, userId])
Expand Down
4 changes: 2 additions & 2 deletions packages/mobile/src/store/drawers/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ export type DrawerData = {
ChatActions: { userId: number; chatId: string }
CreateChatActions: { userId: number }
ProfileActions: undefined
BlockMessages: { userId: number }
BlockMessages: { userId: number; shouldOpenChat: boolean }
DeleteChat: { chatId: string }
SupportersInfo: undefined
InboxUnavailable: { userId: number }
InboxUnavailable: { userId: number; shouldOpenChat: boolean }
}

export type DrawersState = { [drawer in Drawer]: boolean | 'closing' } & {
Expand Down

0 comments on commit a6c8ece

Please sign in to comment.