Skip to content

Commit

Permalink
Require full name for kvittering
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaileshS1702 committed Sep 26, 2024
1 parent ab6acd6 commit f8f6a34
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion webapp/components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { BiBlock, BiReceipt } from 'react-icons/bi';
import { Form } from 'react-final-form';
import PictureUpload from './PictureUpload';
import SignatureUpload from './SignatureUpload';
import { accountValidator, emailValidator } from 'utils/validators';
import { accountValidator, emailValidator, fullNameValidator } from 'utils/validators';
import { mailToDataList } from 'utils/datalists';
import { FormButton, FormInput } from './elements';
import FormSelect from './elements/FormSelect';
Expand Down Expand Up @@ -217,6 +217,7 @@ const ReceiptForm = (): JSX.Element => {
required
helperText="Ditt fulle navn, slik kvitteringen viser"
autoFocus
validators={[fullNameValidator]}
/>

<FormInput
Expand Down
8 changes: 8 additions & 0 deletions webapp/utils/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ export const validateField =
export const requiredValidator: FieldValidator = (value?: string) =>
value ? undefined : 'Dette feltet er obligatorisk';

export const fullNameValidator: FieldValidator = (value?: string) => {
const namesWithlength = value?.split(" ").filter(name => name.length > 0);
if (!value?.includes(' ') || !namesWithlength || namesWithlength?.length < 2) {
return 'Vennligst skriv inn ditt fulle navn';
}

};

export const emailValidator: FieldValidator = (value?: string) => {
if (!value?.includes('@')) {
return 'E-post må inneholde @';
Expand Down

0 comments on commit f8f6a34

Please sign in to comment.