aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/FlexibleForm.js
blob: d8c959dd203e22b46c7c3c31ed3bcf872f4591e5 (plain)
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
69
70
import React from 'react';
import { Link } from "react-router-dom";
import logo from "../assets/img/logo.svg";

const FlexibleForm = ({ data, onFormSubmit }) => {
        const handleSubmit = (event) => {
            event.preventDefault();
            if (typeof onFormSubmit === 'function') {
                onFormSubmit(event);
            }
        };

    return (
        <div className="flex flex-col items-center justify-center min-h-screen">
            <div className="mt-8 sm:w-full sm:max-w-md border rounded-lg p-6 border-gray-300 shadow-lg">
            <Link to="/">
                <span className="flex justify-center space-x-2 text-2xl font-medium text-indigo-500 dark:text-gray-100">
                    <span>
                        <img
                            src={logo}
                            alt="heart shaped handshake logo"
                            width="128"
                            height="128"
                            className="w-20"
                        />
                    </span>
                </span>
            </Link>
                <h3 className="text-3xl mt-3 text-center font-bold leading-snug text-gray-800 lg:text-4xl dark:text-white">
                    {data.title}
                </h3>
                <p className="mt-2 text-lg text-center leading-normal text-gray-500 lg:text-xl xl:text-xl dark:text-gray-300">
                    {data.subtitle}
                </p>
                <form onSubmit={handleSubmit} className="mt-5 space-y-3">
                    {data.formFields.map((field, index) => (
                        <div key={index}>
                            <label htmlFor={field.name} className="block text-sm font-medium leading-6 text-gray-900">{field.label}</label>
                            <input
                                id={field.name}
                                name={field.name}
                                type={field.type}
                                autoComplete={field.autoComplete}
                                required={field.required}
                                value={field.value}
                                onChange={field.onChange}
                                className="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"
                            />
                        </div>
                    ))}
                    <button type="submit" className="w-full rounded-md bg-indigo-600 px-10 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">
                        {data.ctaText || "Submit"}
                    </button>
                </form>
                {data.underneathButton && (
                    <div className="mt-3 text-center">
                        <a href={data.underneathButton.url} className="text-sm text-indigo-600 hover:text-indigo-500">{data.underneathButton.text}</a>
                    </div>
                )}
                {data.ctaLink && (
                    <p className="mt-10 text-center text-sm text-gray-500">
                        {data.ctaLink.text} <a href={data.ctaLink.url} className="font-semibold leading-6 text-indigo-600 hover:text-indigo-500">{data.ctaLink.linkText}</a>
                    </p>
                )}
            </div>
        </div>
    );
};

export default FlexibleForm;