Skip to content

Commit

Permalink
Merge pull request #920 from w3bdesign/develop
Browse files Browse the repository at this point in the history
Refactor input fields to separate file
  • Loading branch information
w3bdesign authored Oct 18, 2022
2 parents 1c47377 + 3b97abc commit 87a1f4a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 41 deletions.
44 changes: 3 additions & 41 deletions components/Checkout/Billing.component.jsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,8 @@
import { useForm } from 'react-hook-form';

import { InputField } from '../Input/InputField.component';
import { getCustomNumberValidation } from '../../utils/functions/functions';

const inputField = [
{ label: 'Fornavn', name: 'firstName' },
{ label: 'Etternavn', name: 'lastName' },
{ label: 'Adresse', name: 'address1' },
{
label: 'Postnummer',
name: 'postcode',
customValidation: getCustomNumberValidation(
{
minLength: 'Postnummer må være minimum 4 tall',
maxLength: 'Postnummer må være maksimalt 4 tall',
pattern: 'Postnummer må bare være tall',
},
4
),
},
{ label: 'Sted', name: 'city' },
{
label: 'Epost',
name: 'email',
customValidation: getCustomNumberValidation(
{ pattern: 'Du må oppgi en gyldig epost' },
undefined,
/^[a-z0-9_!#$%&'*+\/=?`{|}~^.-]+@[a-z0-9.-]+$/gim
),
},
{
label: 'Telefon',
name: 'phone',
customValidation: getCustomNumberValidation(
{
minLength: 'Minimum 8 tall i telefonnummeret',
maxLength: 'Maksimalt 8 tall i telefonnummeret',
pattern: 'Ikke gyldig telefonnummer',
},
8
),
},
];
import { INPUT_FIELDS } from '../../utils/constants/INPUT_FIELDS';

const Billing = ({ onSubmit }) => {
const {
Expand All @@ -53,7 +15,7 @@ const Billing = ({ onSubmit }) => {
<section className="text-gray-700 container p-4 py-2 mx-auto">
<form onSubmit={handleSubmit(onSubmit)}>
<div className="mx-auto lg:w-1/2 flex flex-wrap">
{inputField.map(({ label, name, customValidation }, key) => (
{INPUT_FIELDS.map(({ label, name, customValidation }, key) => (
<InputField
key={key}
label={label}
Expand Down
41 changes: 41 additions & 0 deletions utils/constants/INPUT_FIELDS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { getCustomNumberValidation } from '../functions/functions';

export const INPUT_FIELDS = [
{ label: 'Fornavn', name: 'firstName' },
{ label: 'Etternavn', name: 'lastName' },
{ label: 'Adresse', name: 'address1' },
{
label: 'Postnummer',
name: 'postcode',
customValidation: getCustomNumberValidation(
{
minLength: 'Postnummer må være minimum 4 tall',
maxLength: 'Postnummer må være maksimalt 4 tall',
pattern: 'Postnummer må bare være tall',
},
4
),
},
{ label: 'Sted', name: 'city' },
{
label: 'Epost',
name: 'email',
customValidation: getCustomNumberValidation(
{ pattern: 'Du må oppgi en gyldig epost' },
undefined,
/^[a-z0-9_!#$%&'*+\/=?`{|}~^.-]+@[a-z0-9.-]+$/gim
),
},
{
label: 'Telefon',
name: 'phone',
customValidation: getCustomNumberValidation(
{
minLength: 'Minimum 8 tall i telefonnummeret',
maxLength: 'Maksimalt 8 tall i telefonnummeret',
pattern: 'Ikke gyldig telefonnummer',
},
8
),
},
];

1 comment on commit 87a1f4a

@vercel
Copy link

@vercel vercel bot commented on 87a1f4a Oct 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.