Skip to content

Commit

Permalink
Bug fix personinput
Browse files Browse the repository at this point in the history
  • Loading branch information
vjvirtan committed Oct 26, 2024
1 parent abd056f commit e9e712b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 3 additions & 1 deletion app/components/form/FindPersonFormChild.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions app/components/form/useValidate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const useValidate = () => {
const { useAdvice } = UseAdviceContext();

const runValidation = async (field: string, input: any): Promise<Valid> => {
console.log(field, " ", input);
return new Promise((resolve, reject) => {
const rules = useAdvice.advice.find((e) => {
if (e.key.toLowerCase() == field.toLowerCase()) {
Expand Down Expand Up @@ -79,6 +80,7 @@ const useValidate = () => {
if (rules?.subString) {
rules.subString.map((e) => {});
}
console.log(validationErrors);
resolve(
validationErrors.length > 0 ? onError(validationErrors) : onValid()
);
Expand Down
12 changes: 10 additions & 2 deletions app/requests/FetchPerson.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -38,7 +44,9 @@ const FetchPerson = async (personId: string) => {
fResponse.status = true;
fResponse.data = personData;
})
.catch((error) => {});
.catch((error) => {
return fResponse;
});

return fResponse;
};
Expand Down

0 comments on commit e9e712b

Please sign in to comment.