about summary refs log tree commit diff
path: root/src/components/dms/dialogs/ShareViaChatDialog.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/dms/dialogs/ShareViaChatDialog.tsx')
-rw-r--r--src/components/dms/dialogs/ShareViaChatDialog.tsx52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/components/dms/dialogs/ShareViaChatDialog.tsx b/src/components/dms/dialogs/ShareViaChatDialog.tsx
new file mode 100644
index 000000000..ac475f7c9
--- /dev/null
+++ b/src/components/dms/dialogs/ShareViaChatDialog.tsx
@@ -0,0 +1,52 @@
+import React, {useCallback} from 'react'
+import {msg} from '@lingui/macro'
+import {useLingui} from '@lingui/react'
+
+import {useGetConvoForMembers} from '#/state/queries/messages/get-convo-for-members'
+import {logEvent} from 'lib/statsig/statsig'
+import * as Toast from '#/view/com/util/Toast'
+import * as Dialog from '#/components/Dialog'
+import {SearchablePeopleList} from './SearchablePeopleList'
+
+export function SendViaChatDialog({
+  control,
+  onSelectChat,
+}: {
+  control: Dialog.DialogControlProps
+  onSelectChat: (chatId: string) => void
+}) {
+  const {_} = useLingui()
+
+  const {mutate: createChat} = useGetConvoForMembers({
+    onSuccess: data => {
+      onSelectChat(data.convo.id)
+
+      if (!data.convo.lastMessage) {
+        logEvent('chat:create', {logContext: 'SendViaChatDialog'})
+      }
+      logEvent('chat:open', {logContext: 'SendViaChatDialog'})
+    },
+    onError: error => {
+      Toast.show(error.message)
+    },
+  })
+
+  const onCreateChat = useCallback(
+    (did: string) => {
+      control.close(() => createChat([did]))
+    },
+    [control, createChat],
+  )
+
+  return (
+    <Dialog.Outer
+      control={control}
+      testID="sendViaChatChatDialog"
+      nativeOptions={{sheet: {snapPoints: ['100%']}}}>
+      <SearchablePeopleList
+        title={_(msg`Send post to...`)}
+        onSelectChat={onCreateChat}
+      />
+    </Dialog.Outer>
+  )
+}