import React from 'react'; import { useStore } from 'App/mstore'; import { numberWithCommas, debounce } from 'App/utils'; import { Step } from 'Components/UsabilityTesting/TestEdit'; import OutsideClickDetectingDiv from 'Shared/OutsideClickDetectingDiv'; import { Loader, NoContent, Pagination } from 'UI'; import { Button, Typography, Input } from 'antd'; import { observer } from 'mobx-react-lite'; import { DownOutlined } from '@ant-design/icons'; import { useTranslation } from 'react-i18next'; let debounceUpdate: any = () => {}; const ResponsesOverview = observer(() => { const { t } = useTranslation(); const { uxtestingStore } = useStore(); const [search, setSearch] = React.useState(''); const [page, setPage] = React.useState(1); const [showAll, setShowAll] = React.useState(false); const [taskId, setTaskId] = React.useState(undefined); React.useEffect(() => { setTaskId( uxtestingStore.instance?.tasks.filter((t) => t.allowTyping)[0].taskId, ); }, [uxtestingStore.instance?.tasks]); React.useEffect(() => { if (taskId) { void refreshData(); } }, [page, taskId]); debounceUpdate = debounce((text: string) => { void refreshData(text); }, 200); const refreshDataQuery = (text: string) => { setSearch(text); debounceUpdate(text); }; const refreshData = (searchText?: string) => taskId ? uxtestingStore.fetchResponses( uxtestingStore.instance!.testId!, taskId, page, searchText || search, ) : null; const selectedIndex = uxtestingStore.instance?.tasks.findIndex( (task) => task.taskId === taskId, )!; const task = uxtestingStore.instance?.tasks.find( (task) => task.taskId === taskId, ); return (
{t('Open-ended task responses')}
{t('Select Task / Question')} setShowAll(false)}>
setShowAll(!showAll)}>
} />
{showAll ? (
{uxtestingStore.instance?.tasks .filter((t) => t.taskId !== taskId && t.allowTyping) .map((task) => (
{ setShowAll(false); setTaskId(task.taskId); }} > t.taskId === task.taskId, )! } title={task.title} description={task.description} />
))}
) : null}
#
{t('Participant')}
{t('Response')}
refreshDataQuery(e.target.value)} classNames={{ input: '!border-0 focus:!border-0' }} onSearch={() => refreshData()} />
{t('No data yet')}} >
{uxtestingStore.responses[taskId!]?.list.map((r, i) => (
{i + 10 * (page - 1) + 1}
{r.user_id || 'Anonymous User'}
{r.comment}
))}
{t('Showing')}  {(page - 1) * 10 + 1}{' '} {t('to')}{' '} {(page - 1) * 10 + uxtestingStore.responses[taskId!]?.list.length} {' '} {t('of')}{' '} {numberWithCommas(uxtestingStore.responses[taskId!]?.total)} {' '} {t('replies.')}
setPage(p)} />
); }); export default ResponsesOverview;