All files customize-service.tsx

50% Statements 4/8
0% Branches 0/24
0% Functions 0/3
50% Lines 4/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 693x 3x   3x                                                                                                                               3x  
import * as React from 'react'
import { observer } from 'mobx-react'
import { Store } from './store'
import { Button } from 'reactstrap'
import { ConsentResponse, ServiceInformations } from './service'
 
interface BtnProps {
    color?: (service: ServiceInformations) => string
    size?: (service: ServiceInformations) => string
    outline?: (service: ServiceInformations) => boolean
    className?: (service: ServiceInformations) => string
    content?: (service: ServiceInformations) => React.ReactNode
}
 
export interface Props {
    store: Store
    service: ServiceInformations
    className?: (service: ServiceInformations) => string
    name?: (service: ServiceInformations) => React.ReactNode
    accept?: BtnProps
    decline?: BtnProps
    noNeedConsent?: (service: ServiceInformations) => React.ReactNode
}
 
export interface State {
 
}
 
class CustomizeService extends React.Component<Props, State> {
    render (): React.ReactNode {
 
        const { store, service, className, name, accept, decline, noNeedConsent } = this.props
 
        return <>
            <div className={className !== undefined ? className(service) : 'd-flex justify-content-between' }>
                { name !== undefined ? name(service) : <span>{ service.id } ({service.cookies?.join(', ')})</span> }
                <div>
                    { service.needConsent ? (
                        <>
                            <Button
                                color={accept?.color !== undefined ? accept.color(service) : 'primary'}
                                size={accept?.size?.(service)}
                                outline={accept?.outline !== undefined ? accept.outline(service) : service.consent != 'yes'}
                                className={accept?.className !== undefined ? accept.className(service) : '' }
                                onClick={() => store.accept(service.id)}
                                >
                                {accept?.content !== undefined ? accept.content(service) : 'Accept'}
                            </Button>
                            <Button
                                color={decline?.color !== undefined ? decline.color(service) : 'primary'}
                                size={decline?.size?.(service)}
                                outline={decline?.outline !== undefined ? decline.outline(service) : service.consent != 'no'}
                                className={decline?.className !== undefined ? decline.className(service) : 'ms-2' }
                                onClick={() => store.decline(service.id)}
                                >
                                {decline?.content !== undefined ? decline.content(service) : 'Decline'}
                            </Button>
                        </>
                    ) : (
                        noNeedConsent !== undefined ? noNeedConsent(service) : 'Required'
                    )}
                </div>
            </div>
        </>
    }
}
 
export default observer(CustomizeService)