Skip to content

Commit d08199f

Browse files
committed
Refactor input fields to separate file
1 parent c65f85e commit d08199f

File tree

2 files changed

+44
-41
lines changed

2 files changed

+44
-41
lines changed

components/Checkout/Billing.component.jsx

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,8 @@
11
import { useForm } from 'react-hook-form';
2+
23
import { InputField } from '../Input/InputField.component';
3-
import { getCustomNumberValidation } from '../../utils/functions/functions';
44

5-
const inputField = [
6-
{ label: 'Fornavn', name: 'firstName' },
7-
{ label: 'Etternavn', name: 'lastName' },
8-
{ label: 'Adresse', name: 'address1' },
9-
{
10-
label: 'Postnummer',
11-
name: 'postcode',
12-
customValidation: getCustomNumberValidation(
13-
{
14-
minLength: 'Postnummer må være minimum 4 tall',
15-
maxLength: 'Postnummer må være maksimalt 4 tall',
16-
pattern: 'Postnummer må bare være tall',
17-
},
18-
4
19-
),
20-
},
21-
{ label: 'Sted', name: 'city' },
22-
{
23-
label: 'Epost',
24-
name: 'email',
25-
customValidation: getCustomNumberValidation(
26-
{ pattern: 'Du må oppgi en gyldig epost' },
27-
undefined,
28-
/^[a-z0-9_!#$%&'*+\/=?`{|}~^.-]+@[a-z0-9.-]+$/gim
29-
),
30-
},
31-
{
32-
label: 'Telefon',
33-
name: 'phone',
34-
customValidation: getCustomNumberValidation(
35-
{
36-
minLength: 'Minimum 8 tall i telefonnummeret',
37-
maxLength: 'Maksimalt 8 tall i telefonnummeret',
38-
pattern: 'Ikke gyldig telefonnummer',
39-
},
40-
8
41-
),
42-
},
43-
];
5+
import { INPUT_FIELDS } from '../../utils/constants/INPUT_FIELDS';
446

457
const Billing = ({ onSubmit }) => {
468
const {
@@ -53,7 +15,7 @@ const Billing = ({ onSubmit }) => {
5315
<section className="text-gray-700 container p-4 py-2 mx-auto">
5416
<form onSubmit={handleSubmit(onSubmit)}>
5517
<div className="mx-auto lg:w-1/2 flex flex-wrap">
56-
{inputField.map(({ label, name, customValidation }, key) => (
18+
{INPUT_FIELDS.map(({ label, name, customValidation }, key) => (
5719
<InputField
5820
key={key}
5921
label={label}

utils/constants/INPUT_FIELDS.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { getCustomNumberValidation } from '../functions/functions';
2+
3+
export const INPUT_FIELDS = [
4+
{ label: 'Fornavn', name: 'firstName' },
5+
{ label: 'Etternavn', name: 'lastName' },
6+
{ label: 'Adresse', name: 'address1' },
7+
{
8+
label: 'Postnummer',
9+
name: 'postcode',
10+
customValidation: getCustomNumberValidation(
11+
{
12+
minLength: 'Postnummer må være minimum 4 tall',
13+
maxLength: 'Postnummer må være maksimalt 4 tall',
14+
pattern: 'Postnummer må bare være tall',
15+
},
16+
4
17+
),
18+
},
19+
{ label: 'Sted', name: 'city' },
20+
{
21+
label: 'Epost',
22+
name: 'email',
23+
customValidation: getCustomNumberValidation(
24+
{ pattern: 'Du må oppgi en gyldig epost' },
25+
undefined,
26+
/^[a-z0-9_!#$%&'*+\/=?`{|}~^.-]+@[a-z0-9.-]+$/gim
27+
),
28+
},
29+
{
30+
label: 'Telefon',
31+
name: 'phone',
32+
customValidation: getCustomNumberValidation(
33+
{
34+
minLength: 'Minimum 8 tall i telefonnummeret',
35+
maxLength: 'Maksimalt 8 tall i telefonnummeret',
36+
pattern: 'Ikke gyldig telefonnummer',
37+
},
38+
8
39+
),
40+
},
41+
];

0 commit comments

Comments
 (0)