Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HL-883 | Fix some issues with opening and locking application on handler's side #2181

Merged
merged 4 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading