Skip to content

Commit

Permalink
fix: prevent submit of paperApplicationDate to application of applica…
Browse files Browse the repository at this point in the history
…nt origin
  • Loading branch information
sirtawast committed Oct 8, 2024
1 parent cde593c commit 5f7e2d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
ApplicationFields,
} from 'benefit/handler/types/application';
import {
APPLICATION_ORIGINS,
ORGANIZATION_TYPES,
VALIDATION_MESSAGE_KEYS,
} from 'benefit-shared/constants';
Expand Down Expand Up @@ -124,6 +125,14 @@ export const useApplicationForm = (): ExtendedComponentProps => {
error: applicationDataError,
} = useApplicationQueryWithState(id, setApplication);

const getPaperApplicationDate = (): string | null => {
if (application?.applicationOrigin === APPLICATION_ORIGINS.APPLICANT)
return null;
return application?.paperApplicationDate
? formatDate(parseDate(application.paperApplicationDate))
: formatDate(new Date());
};

const formik = useFormik({
initialValues: {
...application,
Expand All @@ -133,10 +142,7 @@ export const useApplicationForm = (): ExtendedComponentProps => {
[APPLICATION_FIELDS.END_DATE]: application.endDate
? formatDate(parseDate(application.endDate))
: undefined,
[APPLICATION_FIELDS.PAPER_APPLICATION_DATE]:
application.paperApplicationDate
? formatDate(parseDate(application.paperApplicationDate))
: formatDate(new Date()),
[APPLICATION_FIELDS.PAPER_APPLICATION_DATE]: getPaperApplicationDate(),
},
validationSchema: getValidationSchema(organizationType, t),
validateOnChange: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ const getApplication = (
...applicationData,
start_date: convertToUIDateFormat(applicationData.start_date),
end_date: convertToUIDateFormat(applicationData.end_date),
paper_application_date: convertToUIDateFormat(
applicationData.paper_application_date
),
paper_application_date:
applicationData.application_origin === APPLICATION_ORIGINS.HANDLER
? convertToUIDateFormat(applicationData.paper_application_date)
: null,
calculation: applicationData.calculation
? {
...applicationData.calculation,
Expand Down

0 comments on commit 5f7e2d2

Please sign in to comment.