2
0

fix(results): 🐛 Exporting many results

This commit is contained in:
Baptiste Arnaud
2022-04-14 16:33:13 -07:00
parent e50ce645eb
commit 281fddc8ef
2 changed files with 18 additions and 8 deletions

View File

@ -126,9 +126,8 @@ export const SubmissionsContent = ({
const getAllTableData = async () => { const getAllTableData = async () => {
if (!publishedTypebot) return [] if (!publishedTypebot) return []
const { data, error } = await getAllResults(typebotId) const results = await getAllResults(typebotId)
if (error) toast({ description: error.message, title: error.name }) return convertResultsToTableData(results, resultHeader)
return convertResultsToTableData(data?.results, resultHeader)
} }
const tableData: { [key: string]: string }[] = useMemo( const tableData: { [key: string]: string }[] = useMemo(

View File

@ -80,11 +80,22 @@ export const deleteAllResults = async (typebotId: string) =>
method: 'DELETE', method: 'DELETE',
}) })
export const getAllResults = async (typebotId: string) => export const getAllResults = async (typebotId: string) => {
sendRequest<{ results: ResultWithAnswers[] }>({ const results = []
url: `/api/typebots/${typebotId}/results`, let hasMore = true
let lastResultId: string | undefined = undefined
do {
const query = stringify({ limit: 200, lastResultId })
const { data } = await sendRequest<{ results: ResultWithAnswers[] }>({
url: `/api/typebots/${typebotId}/results?${query}`,
method: 'GET', method: 'GET',
}) })
results.push(...(data?.results ?? []))
lastResultId = results[results.length - 1]?.id as string | undefined
if (data?.results.length === 0) hasMore = false
} while (hasMore)
return results
}
export const parseDateToReadable = (dateStr: string): string => { export const parseDateToReadable = (dateStr: string): string => {
const date = new Date(dateStr) const date = new Date(dateStr)