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
|
import FieldProperties from "./fields/field_properties";
import Field from "./fields/field";
import { setFieldErrorMessages } from "../../lib/form_utils";
import { Form } from "react-router-dom";
function getFieldProperties(card?: any) {
const fields: Array<FieldProperties> = [
{
id: "number-field",
type: "number",
name: "number",
label: "Número de tarjeta",
placeholder: card?.number
},
{
id: "expiration-year-field",
type: "number",
name: "expiration_year",
label: "Año de expiración",
placeholder: card?.expiration_year
},
{
id: "expiration-month-field",
type: "number",
name: "expiration_month",
label: "Mes de expiración",
placeholder: card?.expiration_month
},
{
id: "expiration-day-field",
type: "number",
name: "expiration_day",
label: "Día de expiración",
placeholder: card?.expiration_day
},
{
id: "security-code-field",
type: "number",
name: "security_code",
label: "CVV"
}
];
return fields;
}
export default function CardForm({ card = null, errors = null }) {
let field_properties = getFieldProperties(card);
if(errors)
field_properties = setFieldErrorMessages(field_properties, errors);
const fields = field_properties.map(prop =>
<Field properties={prop}/>
);
return (
<Form method="post" id="card-form">
{fields}
<button type="submit" className="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm w-full sm:w-auto px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Enviar</button>
</Form>
);
}
|