Skip to content

Commit

Permalink
Merge pull request #2181 from City-of-Helsinki/hl-883
Browse files Browse the repository at this point in the history
HL-883 | Fix some issues with opening and locking application on handler's side
  • Loading branch information
sirtawast authored Aug 29, 2023
2 parents b676bd8 + d510e25 commit c86d24c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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")}
Expand Down
43 changes: 42 additions & 1 deletion backend/benefit/applications/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)


Expand Down
15 changes: 15 additions & 0 deletions frontend/benefit/handler/src/hooks/useUpdateApplicationQuery.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -12,7 +14,9 @@ const useUpdateApplicationQuery = (): UseMutationResult<
ApplicationData
> => {
const { axios, handleResponse } = useBackendAPI();
const { t } = useTranslation();
const queryClient = useQueryClient();

return useMutation<ApplicationData, AxiosError<ErrorData>, ApplicationData>(
'updateApplication',
(application: ApplicationData) =>
Expand All @@ -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,
})
);
},
}
);
};
Expand Down

0 comments on commit c86d24c

Please sign in to comment.