🚀 Acabamos de lanzar la documentación de ComparaBricks v2

Demo

Para probar este Brick deberá utilizar unas credenciales válidas modificando el código.

React

import { TravelQuoteForm } from '@comparaonline/travel-quote/react';
import { useEffect, useState } from 'react';
import '@comparaonline/travel-quote/css';

const ENVIRONMENT = 'production';

export default function App() {
  const environment = ENVIRONMENT === 'staging' ? 'staging' : 'production';
  const authUrl =
  environment === 'staging'
    ? 'https://ms-staging.comparaonline.com/travel-funnel-bff/public/cl/auth/login'
    : 'https://ms.comparaonline.com/travel-funnel-bff/public/cl/auth/login';

  const [travelProps, setTravelProps] = useState({
    country: 'CL',
    environment,
    styles: {
      theme: 'undefined',
      primaryColor: '#E28743'
    },
  });

  useEffect(() => {
    (async () => {
      const res = await fetch(authUrl, {
        method: 'POST',
        headers: {
          Accept: 'application/json',
          'Content-Type': 'application/json',
          'Requesting-App': 'brick',
        },
        body: JSON.stringify({
          username: 'not-a-valid-user',
          password: 'not-a-valid-password',
        }),
      });

      const data = await res.json();

      setTravelProps((prevConfig) => ({
        ...prevConfig,
        ...data,
      }));
    })();
  }, [authUrl]);

  return <TravelQuoteForm {...travelProps} />;
}

Otros casos de uso

<!DOCTYPE html>
<html>
  <head>
    <title>My application title</title>
    <meta charset="UTF-8" />
    <link rel="stylesheet" href="https://bricks.comparaonline.com/travel-quote/style.css" />
    <script type="module" src="https://bricks.comparaonline.com/travel-quote/index.mjs"></script>
    <style>
      body {
        margin: 0;
      }
    </style>
  </head>

  <body>
    <main id="root"></main>
    <script src="./index.js"></script>
  </body>
</html>