2
0

⚗️ Add export results

This commit is contained in:
Baptiste Arnaud
2022-01-04 15:50:56 +01:00
parent 72454c0f68
commit 6c1e0fd345
11 changed files with 235 additions and 103 deletions

View File

@ -12,14 +12,13 @@ const getKey = (
}
) => {
if (previousPageData && previousPageData.results.length === 0) return null
if (pageIndex === 0) return `/api/typebots/${typebotId}/results`
console.log(previousPageData.results)
if (pageIndex === 0) return `/api/typebots/${typebotId}/results?limit=50`
return `/api/typebots/${typebotId}/results?lastResultId=${
previousPageData.results[previousPageData.results.length - 1].id
}`
}&limit=50`
}
type ResultWithAnswers = Result & { answers: Answer[] }
export type ResultWithAnswers = Result & { answers: Answer[] }
export const useResults = ({
typebotId,
onError,
@ -72,6 +71,12 @@ export const deleteAllResults = async (typebotId: string) =>
method: 'DELETE',
})
export const getAllResults = async (typebotId: string) =>
sendRequest<{ results: ResultWithAnswers[] }>({
url: `/api/typebots/${typebotId}/results`,
method: 'GET',
})
export const parseDateToReadable = (dateStr: string): string => {
const date = new Date(dateStr)
return (
@ -83,3 +88,12 @@ export const parseDateToReadable = (dateStr: string): string => {
})
)
}
export const convertResultsToTableData = (results?: ResultWithAnswers[]) =>
(results ?? []).map((result) => ({
createdAt: parseDateToReadable(result.createdAt),
...result.answers.reduce(
(o, answer) => ({ ...o, [answer.blockId]: answer.content }),
{}
),
}))