UNPKG

@kiwicom/smart-faq

Version:

45 lines (38 loc) 1.18 kB
// @flow import * as React from 'react'; import { createFragmentContainer, graphql } from 'react-relay'; import TripSector from '@kiwicom/orbit-components/lib/TripSector'; import AccordionBodyLeg from './AccordionBodyLeg'; import AccordionBodyLastLeg from './AccordionBodyLastLeg'; import type { AccordionBody_legs as AccordionBodyType } from './__generated__/AccordionBody_legs.graphql'; type Props = {| legs: AccordionBodyType, |}; const AccordionBody = ({ legs }: Props) => { const renderLegs = () => { return legs.map((l, li) => { if (li === legs.length - 1) { return <AccordionBodyLastLeg key={l.flightNumber} leg={l} />; } return ( <AccordionBodyLeg key={l.flightNumber} leg={l} nextLeg={legs[li + 1]} /> ); }); }; return ( <div style={{ padding: '0 5px 0' }}> <TripSector dataTest="tripSector">{renderLegs()}</TripSector> </div> ); }; export default createFragmentContainer( AccordionBody, graphql` fragment AccordionBody_legs on Leg @relay(plural: true) { flightNumber ...AccordionBodyLeg_leg ...AccordionBodyLeg_nextLeg ...AccordionBodyLastLeg_leg } `, );