diff --git a/app/components/form/FindPersonFormChild.tsx b/app/components/form/FindPersonFormChild.tsx index ba0ca47..453425f 100644 --- a/app/components/form/FindPersonFormChild.tsx +++ b/app/components/form/FindPersonFormChild.tsx @@ -20,7 +20,9 @@ const FindPersonFormChild = () => { }); const personInput = (event: string, fieldName: string) => { - runValidation(event, fieldName).then((response) => { + + runValidation(fieldName, event).then((response) => { + console.log(response.validated); if (response.validated) { let personCheck: PersonInterface | undefined = checkPerson(event); diff --git a/app/components/form/useValidate.tsx b/app/components/form/useValidate.tsx index 72f86db..ef2d810 100644 --- a/app/components/form/useValidate.tsx +++ b/app/components/form/useValidate.tsx @@ -27,6 +27,7 @@ const useValidate = () => { const { useAdvice } = UseAdviceContext(); const runValidation = async (field: string, input: any): Promise => { + console.log(field, " ", input); return new Promise((resolve, reject) => { const rules = useAdvice.advice.find((e) => { if (e.key.toLowerCase() == field.toLowerCase()) { @@ -79,6 +80,7 @@ const useValidate = () => { if (rules?.subString) { rules.subString.map((e) => {}); } + console.log(validationErrors); resolve( validationErrors.length > 0 ? onError(validationErrors) : onValid() ); diff --git a/app/requests/FetchPerson.tsx b/app/requests/FetchPerson.tsx index 5f9bc02..f3978dc 100644 --- a/app/requests/FetchPerson.tsx +++ b/app/requests/FetchPerson.tsx @@ -2,6 +2,7 @@ import { PersonInterface } from "../contexts/Person"; import { FetchResponse, URL } from "../interface/FetchInterface"; import { useFetch } from "./useFetch"; + const fResponse: FetchResponse = { status: false, data: null, @@ -17,16 +18,21 @@ const FetchPerson = async (personId: string) => { personId: personId.toUpperCase(), }) .then((d) => { + console.log(d); if (!d.ok) { + fResponse.status = false; d.json().then((err) => { fResponse.errorMessage = err; }); - return fResponse; + throw new Error(""); } return d.json(); }) + .then((data) => { + console.log(" TULEEKO TÄNNE"); + console.log(data); personData = { firstName: data.firstname, lastName: data.lastname, @@ -38,7 +44,9 @@ const FetchPerson = async (personId: string) => { fResponse.status = true; fResponse.data = personData; }) - .catch((error) => {}); + .catch((error) => { + return fResponse; + }); return fResponse; };