forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1import {msg} from '@lingui/core/macro'
2import {useLingui} from '@lingui/react'
3import {StackActions, useNavigation} from '@react-navigation/native'
4
5import {type NavigationProp} from '#/lib/routes/types'
6import {useLeaveConvo} from '#/state/queries/messages/leave-conversation'
7import {type DialogOuterProps} from '#/components/Dialog'
8import * as Prompt from '#/components/Prompt'
9import * as Toast from '#/components/Toast'
10import {IS_NATIVE} from '#/env'
11
12export function LeaveConvoPrompt({
13 control,
14 convoId,
15 currentScreen,
16 hasMessages = true,
17}: {
18 control: DialogOuterProps['control']
19 convoId: string
20 currentScreen: 'list' | 'conversation'
21 hasMessages?: boolean
22}) {
23 const {_} = useLingui()
24 const navigation = useNavigation<NavigationProp>()
25
26 const {mutate: leaveConvo} = useLeaveConvo(convoId, {
27 onMutate: () => {
28 if (currentScreen === 'conversation') {
29 navigation.dispatch(
30 StackActions.replace('Messages', IS_NATIVE ? {animation: 'pop'} : {}),
31 )
32 }
33 },
34 onError: () => {
35 Toast.show(_(msg`Could not leave chat`), {
36 type: 'error',
37 })
38 },
39 })
40
41 return (
42 <Prompt.Basic
43 control={control}
44 title={_(msg`Leave conversation`)}
45 description={
46 hasMessages
47 ? _(
48 msg`Are you sure you want to leave this conversation? Your messages will be deleted for you, but not for the other participant.`,
49 )
50 : _(msg`Are you sure you want to leave this conversation?`)
51 }
52 confirmButtonCta={_(msg`Leave`)}
53 confirmButtonColor="negative"
54 onConfirm={() => leaveConvo()}
55 />
56 )
57}