From 0a485681fa8d11d180e3616783a2fab80c1f6dc5 Mon Sep 17 00:00:00 2001 From: burnettk Date: Mon, 16 Jan 2023 18:08:05 -0500 Subject: [PATCH] fix lint issues --- .../src/routes/TaskShow.tsx | 61 +++++++++---------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/spiffworkflow-frontend/src/routes/TaskShow.tsx b/spiffworkflow-frontend/src/routes/TaskShow.tsx index 238583b14..79bc52635 100644 --- a/spiffworkflow-frontend/src/routes/TaskShow.tsx +++ b/spiffworkflow-frontend/src/routes/TaskShow.tsx @@ -138,6 +138,34 @@ export default function TaskShow() { return null; }; + const getFieldsWithDateValidations = ( + jsonSchema: any, + formData: any, + errors: any + ) => { + if ('properties' in jsonSchema) { + Object.keys(jsonSchema.properties).forEach((propertyKey: string) => { + const propertyMetadata = jsonSchema.properties[propertyKey]; + if ( + 'minimumDate' in propertyMetadata && + propertyMetadata.minimumDate === 'today' + ) { + const dateToday = new Date(); + const dateValue = formData[propertyKey]; + if (dateValue) { + const dateValueObject = new Date(dateValue); + const dateValueString = dateValueObject.toISOString().split('T')[0]; + const dateTodayString = dateToday.toISOString().split('T')[0]; + if (dateTodayString > dateValueString) { + errors[propertyKey].addError('must be today or after'); + } + } + } + }); + } + return errors; + }; + const formElement = (taskToUse: any) => { let formUiSchema; let taskData = taskToUse.data; @@ -184,39 +212,8 @@ export default function TaskShow() { ); } - const getFieldsWithDateValidations = (formData: any, errors: any) => { - if ('properties' in jsonSchema) { - Object.keys(jsonSchema.properties).forEach((propertyKey: string) => { - const propertyMetadata = jsonSchema.properties[propertyKey]; - if ('minimum' in propertyMetadata) { - if (propertyMetadata.minimum === 'today') { - const dateToday = new Date(); - const dateValue = formData[propertyKey]; - if (dateValue) { - const dateValueObject = new Date(dateValue); - const dateValueString = dateValueObject - .toISOString() - .split('T')[0]; - const dateTodayString = dateToday.toISOString().split('T')[0]; - if (dateTodayString > dateValueString) { - errors[propertyKey].addError('must be today or after'); - } - } - } - } - }); - } - return errors; - }; - const customValidate = (formData: any, errors: any) => { - console.log('formData', formData); - console.log('errors', errors); - return getFieldsWithDateValidations(formData, errors); - // if (formData.pass1 !== formData.pass2) { - // errors.pass2.addError("Passwords don't match"); - // } - // return errors; + return getFieldsWithDateValidations(jsonSchema, formData, errors); }; return (