import {useState} from 'react'
import {View} from 'react-native'
import {useLingui} from '@lingui/react/macro'
import {useMutation} from '@tanstack/react-query'
import {logger} from '#/logger'
import {sendErrorReport} from '#/logger/reporting/sendErrorReport'
import {useSession} from '#/state/session'
import {atoms as a, web} from '#/alf'
import {Button, ButtonText} from '#/components/Button'
import * as Dialog from '#/components/Dialog'
import * as TextField from '#/components/forms/TextField'
import * as Toast from '#/components/Toast'
import {Text} from '#/components/Typography'
export function SendErrorReportDialog({
control,
}: {
control: Dialog.DialogControlProps
}) {
return (
)
}
function SendErrorReportDialogInner() {
const {t: l} = useLingui()
const control = Dialog.useDialogContext()
const {currentAccount} = useSession()
const [title, setTitle] = useState('')
const [description, setDescription] = useState('')
const {mutate: onSubmit, isPending} = useMutation({
mutationFn: async () => {
sendErrorReport({
title,
description,
handle: currentAccount?.handle ?? '',
})
},
onSuccess: () => {
control.close(() => {
Toast.show(l`Report sent`)
})
},
onError: error => {
logger.error('Error sending user report', {safeMessage: error})
Toast.show(l`Failed to send report`, {type: 'error'})
},
})
const canSubmit = title.trim().length > 0 && !isPending
return (
{l`Send error report`}
{l`Title`}
setTitle(value.slice(0, 100))}
/>
{l`Description`}
setDescription(value.slice(0, 1000))}
/>
)
}