diff --git a/backend/benefit/applications/api/v1/serializers/application.py b/backend/benefit/applications/api/v1/serializers/application.py index 346dd89b98..ea922f1ebf 100755 --- a/backend/benefit/applications/api/v1/serializers/application.py +++ b/backend/benefit/applications/api/v1/serializers/application.py @@ -1074,6 +1074,10 @@ def _validate_employee_consent(self, instance): def _update_applicant_terms_approval(self, instance, approve_terms): if ApplicantTermsApproval.terms_approval_needed(instance): + # Ignore applicant's terms if app origin is from handler + if instance.application_origin == ApplicationOrigin.HANDLER: + return + if not approve_terms: raise serializers.ValidationError( {"approve_terms": _("Terms must be approved")} diff --git a/backend/benefit/applications/tests/factories.py b/backend/benefit/applications/tests/factories.py index 09027f5806..80f1015730 100755 --- a/backend/benefit/applications/tests/factories.py +++ b/backend/benefit/applications/tests/factories.py @@ -136,10 +136,51 @@ class Meta: model = Application +attachment_factory_string = "applications.tests.factories.AttachmentFactory" + + class ApplicationWithAttachmentFactory(ApplicationFactory): attachment = factory.RelatedFactory( - "applications.tests.factories.AttachmentFactory", + attachment_factory_string, + factory_related_name="application", + attachment_type="employment_contract", + ) + attachment_2 = factory.RelatedFactory( + attachment_factory_string, + factory_related_name="application", + attachment_type="pay_subsidy_decision", + ) + + attachment_3 = factory.RelatedFactory( + attachment_factory_string, + factory_related_name="application", + attachment_type="commission_contract", + ) + + attachment_4 = factory.RelatedFactory( + attachment_factory_string, + factory_related_name="application", + attachment_type="education_contract", + ) + attachment_5 = factory.RelatedFactory( + attachment_factory_string, + factory_related_name="application", + attachment_type="helsinki_benefit_voucher", + ) + attachment_6 = factory.RelatedFactory( + attachment_factory_string, + factory_related_name="application", + attachment_type="employee_consent", + ) + attachment_7 = factory.RelatedFactory( + attachment_factory_string, + factory_related_name="application", + attachment_type="full_application", + ) + attachment_8 = factory.RelatedFactory( + attachment_factory_string, factory_related_name="application", + attachment_type="other_attachment", ) diff --git a/frontend/benefit/handler/src/hooks/useUpdateApplicationQuery.ts b/frontend/benefit/handler/src/hooks/useUpdateApplicationQuery.ts index bb32b0a8da..dddca586e4 100644 --- a/frontend/benefit/handler/src/hooks/useUpdateApplicationQuery.ts +++ b/frontend/benefit/handler/src/hooks/useUpdateApplicationQuery.ts @@ -1,7 +1,9 @@ import { AxiosError } from 'axios'; import { BackendEndpoint } from 'benefit-shared/backend-api/backend-api'; import { ApplicationData } from 'benefit-shared/types/application'; +import { useTranslation } from 'next-i18next'; import { useMutation, UseMutationResult, useQueryClient } from 'react-query'; +import showErrorToast from 'shared/components/toast/show-error-toast'; import useBackendAPI from 'shared/hooks/useBackendAPI'; import { ErrorData } from '../types/common'; @@ -12,7 +14,9 @@ const useUpdateApplicationQuery = (): UseMutationResult< ApplicationData > => { const { axios, handleResponse } = useBackendAPI(); + const { t } = useTranslation(); const queryClient = useQueryClient(); + return useMutation, ApplicationData>( 'updateApplication', (application: ApplicationData) => @@ -27,6 +31,17 @@ const useUpdateApplicationQuery = (): UseMutationResult< void queryClient.invalidateQueries('applications'); void queryClient.invalidateQueries('application'); }, + onError: (error: AxiosError) => { + const errorStatus = error.response?.data + ? Object.values(error.response.data) + : error.code; + showErrorToast( + t('common:applications.list.errors.fetch.label'), + t('common:applications.list.errors.fetch.text', { + status: errorStatus, + }) + ); + }, } ); };