🐛 (results) Fix result modal answers order
This commit is contained in:
@ -11,8 +11,10 @@ import {
|
|||||||
} from '@chakra-ui/react'
|
} from '@chakra-ui/react'
|
||||||
import { useResults } from '../ResultsProvider'
|
import { useResults } from '../ResultsProvider'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { isDefined } from '@typebot.io/lib'
|
import { byId, isDefined } from '@typebot.io/lib'
|
||||||
import { HeaderIcon } from './HeaderIcon'
|
import { HeaderIcon } from './HeaderIcon'
|
||||||
|
import { useTypebot } from '@/features/editor/providers/TypebotProvider'
|
||||||
|
import { parseColumnOrder } from '../helpers/parseColumnsOrder'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
resultId: string | null
|
resultId: string | null
|
||||||
@ -21,10 +23,16 @@ type Props = {
|
|||||||
|
|
||||||
export const ResultModal = ({ resultId, onClose }: Props) => {
|
export const ResultModal = ({ resultId, onClose }: Props) => {
|
||||||
const { tableData, resultHeader } = useResults()
|
const { tableData, resultHeader } = useResults()
|
||||||
|
const { typebot } = useTypebot()
|
||||||
const result = isDefined(resultId)
|
const result = isDefined(resultId)
|
||||||
? tableData.find((data) => data.id.plainText === resultId)
|
? tableData.find((data) => data.id.plainText === resultId)
|
||||||
: undefined
|
: undefined
|
||||||
|
|
||||||
|
const columnsOrder = parseColumnOrder(
|
||||||
|
typebot?.resultsTablePreferences?.columnsOrder,
|
||||||
|
resultHeader
|
||||||
|
)
|
||||||
|
|
||||||
const getHeaderValue = (
|
const getHeaderValue = (
|
||||||
val: string | { plainText: string; element?: JSX.Element | undefined }
|
val: string | { plainText: string; element?: JSX.Element | undefined }
|
||||||
) => (typeof val === 'string' ? val : val.element ?? val.plainText)
|
) => (typeof val === 'string' ? val : val.element ?? val.plainText)
|
||||||
@ -35,8 +43,11 @@ export const ResultModal = ({ resultId, onClose }: Props) => {
|
|||||||
<ModalContent>
|
<ModalContent>
|
||||||
<ModalCloseButton />
|
<ModalCloseButton />
|
||||||
<ModalBody as={Stack} p="10" spacing="10">
|
<ModalBody as={Stack} p="10" spacing="10">
|
||||||
{resultHeader.map((header) =>
|
{columnsOrder.map((headerId) => {
|
||||||
result && result[header.id] ? (
|
if (!result || !result[headerId]) return null
|
||||||
|
const header = resultHeader.find(byId(headerId))
|
||||||
|
if (!header) return null
|
||||||
|
return (
|
||||||
<Stack key={header.id} spacing="4">
|
<Stack key={header.id} spacing="4">
|
||||||
<HStack>
|
<HStack>
|
||||||
<HeaderIcon header={header} />
|
<HeaderIcon header={header} />
|
||||||
@ -46,8 +57,8 @@ export const ResultModal = ({ resultId, onClose }: Props) => {
|
|||||||
{getHeaderValue(result[header.id])}
|
{getHeaderValue(result[header.id])}
|
||||||
</Text>
|
</Text>
|
||||||
</Stack>
|
</Stack>
|
||||||
) : null
|
)
|
||||||
)}
|
})}
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
</ModalContent>
|
</ModalContent>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
Reference in New Issue
Block a user