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-642: Handler state check icons #2156

Merged
merged 5 commits into from
Aug 14, 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
34 changes: 34 additions & 0 deletions backend/benefit/applications/api/v1/review_state_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from rest_framework import status
from rest_framework.response import Response
from rest_framework.views import APIView

from applications.api.v1.serializers.review_state import ReviewStateSerializer
from applications.models import Application, ReviewState
from common.permissions import BFIsHandler


class ReviewStateView(APIView):
permission_classes = [BFIsHandler]

def get(self, _, application_id):
try:
review_state = ReviewState.objects.get(application=application_id)
except ReviewState.DoesNotExist:
application = Application.objects.get(id=application_id)
if application:
review_state = ReviewState.objects.create(application=application)
else:
return Response(status=status.HTTP_404_NOT_FOUND)
serializer = ReviewStateSerializer(review_state)
return Response(serializer.data)

def put(self, request, application_id):
try:
review_state = ReviewState.objects.get(application=application_id)
except ReviewState.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)
serializer = ReviewStateSerializer(review_state, data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from rest_framework import serializers

from applications.models import ReviewState


class ReviewStateSerializer(serializers.ModelSerializer):
class Meta:
model = ReviewState
fields = "__all__"
28 changes: 28 additions & 0 deletions backend/benefit/applications/migrations/0036_reviewstate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 3.2.18 on 2023-07-19 20:52

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('applications', '0035_alter_applicationbatch_handler'),
]

operations = [
migrations.CreateModel(
name='ReviewState',
fields=[
('application', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='applications.application', verbose_name='application')),
('company', models.BooleanField(default=False, verbose_name='company')),
('company_contact_person', models.BooleanField(default=False, verbose_name='company contact person')),
('de_minimis_aids', models.BooleanField(default=False, verbose_name='de minimis aids')),
('co_operation_negotiations', models.BooleanField(default=False, verbose_name='co-operation negotiations')),
('employee', models.BooleanField(default=False, verbose_name='employee')),
('pay_subsidy', models.BooleanField(default=False, verbose_name='pay subsidy')),
('benefit', models.BooleanField(default=False, verbose_name='benefit')),
('employment', models.BooleanField(default=False, verbose_name='employment')),
],
),
]
23 changes: 23 additions & 0 deletions backend/benefit/applications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,3 +827,26 @@ class Meta:

def __str__(self):
return "{} {}".format(self.attachment_type, self.attachment_file.name)


class ReviewState(models.Model):
application = models.OneToOneField(
Application,
on_delete=models.CASCADE,
primary_key=True,
verbose_name=_("application"),
)
company = models.BooleanField(default=False, verbose_name=_("company"))
company_contact_person = models.BooleanField(
default=False, verbose_name=_("company contact person")
)
de_minimis_aids = models.BooleanField(
default=False, verbose_name=_("de minimis aids")
)
co_operation_negotiations = models.BooleanField(
default=False, verbose_name=_("co-operation negotiations")
)
employee = models.BooleanField(default=False, verbose_name=_("employee"))
pay_subsidy = models.BooleanField(default=False, verbose_name=_("pay subsidy"))
benefit = models.BooleanField(default=False, verbose_name=_("benefit"))
employment = models.BooleanField(default=False, verbose_name=_("employment"))
4 changes: 4 additions & 0 deletions backend/benefit/helsinkibenefit/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from rest_framework_nested import routers

from applications.api.v1 import application_batch_views, views as application_views
from applications.api.v1.review_state_views import ReviewStateView
from calculator.api.v1 import views as calculator_views
from common.debug_util import debug_env
from companies.api.v1.views import (
Expand Down Expand Up @@ -69,6 +70,9 @@
path("v1/company/search/<str:name>/", SearchOrganisationsView.as_view()),
path("v1/company/get/<str:business_id>/", GetOrganisationByIdView.as_view()),
path("v1/users/me/", CurrentUserView.as_view()),
path(
"v1/handlerapplications/<str:application_id>/review/", ReviewStateView.as_view()
),
path("oidc/", include("shared.oidc.urls")),
path("oauth2/", include("shared.azure_adfs.urls")),
path("api-auth/", include("rest_framework.urls", namespace="rest_framework")),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ApplicationHeader from 'benefit/handler/components/applicationHeader/ApplicationHeader';
import { HANDLED_STATUSES } from 'benefit/handler/constants';
import ReviewStateContext from 'benefit/handler/context/ReviewStateContext';
import {
APPLICATION_ORIGINS,
APPLICATION_STATUSES,
Expand Down Expand Up @@ -33,6 +34,7 @@ import PaySubsidyView from './paySubsidyView/PaySubsidyView';
import SalaryBenefitCalculatorView from './salaryBenefitCalculatorView/SalaryBenefitCalculatorView';
import { useApplicationReview } from './useApplicationReview';


const ApplicationReview: React.FC = () => {
const {
application,
Expand All @@ -41,6 +43,8 @@ const ApplicationReview: React.FC = () => {
t,
isUploading,
handleUpload,
reviewState,
handleUpdateReviewState,
} = useApplicationReview();
const theme = useTheme();

Expand Down Expand Up @@ -92,45 +96,52 @@ const ApplicationReview: React.FC = () => {
})}
</StatusLabel>
)}
<CompanyInfoView data={application} />
<ContactPersonView data={application} />
<DeminimisView data={application} />
<CoOperationNegotiationsView data={application} />
<EmployeeView
data={application}
handleUpload={handleUpload}
isUploading={isUploading}
/>
<PaySubsidyView
data={application}
handleUpload={handleUpload}
isUploading={isUploading}
/>
<BenefitView data={application} />
<EmploymentView
data={application}
handleUpload={handleUpload}
isUploading={isUploading}
/>
{application.applicationOrigin === APPLICATION_ORIGINS.HANDLER ? (
<AttachmentsView data={application} />
) : (
<ConsentView
<ReviewStateContext.Provider
value={{
reviewState,
handleUpdateReviewState,
}}
>
<CompanyInfoView data={application} />
<ContactPersonView data={application} />
<DeminimisView data={application} />
<CoOperationNegotiationsView data={application} />
<EmployeeView
data={application}
handleUpload={handleUpload}
isUploading={isUploading}
/>
)}
{application.status === APPLICATION_STATUSES.HANDLING && (
<>
<CalculatorView />
<ApplicationProcessingView />
</>
)}
{application.status &&
HANDLED_STATUSES.includes(application.status) && (
<HandledView data={application} />
<PaySubsidyView
data={application}
handleUpload={handleUpload}
isUploading={isUploading}
/>
<BenefitView data={application} />
<EmploymentView
data={application}
handleUpload={handleUpload}
isUploading={isUploading}
/>
{application.applicationOrigin === APPLICATION_ORIGINS.HANDLER ? (
<AttachmentsView data={application} />
) : (
<ConsentView
data={application}
handleUpload={handleUpload}
isUploading={isUploading}
/>
)}
{application.status === APPLICATION_STATUSES.HANDLING && (
<>
<CalculatorView />
<ApplicationProcessingView />
</>
)}
{application.status &&
HANDLED_STATUSES.includes(application.status) && (
<HandledView data={application} />
)}
</ReviewStateContext.Provider>
</Container>
<StickyActionBar>
{application.status === APPLICATION_STATUSES.RECEIVED && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const BenefitView: React.FC<ApplicationReviewViewProps> = ({ data }) => {
withoutDivider
header={t(`${translationsBase}.headings.heading7`)}
action={data.status !== APPLICATION_STATUSES.RECEIVED ? <span /> : null}
section='benefit'
>
<$GridCell $colSpan={6}>
<$ViewField>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const CoOperationNegotiationsView: React.FC<ApplicationReviewViewProps> = ({
<ReviewSection
header={t(`${translationsBase}.headings.heading4`)}
action={data.status !== APPLICATION_STATUSES.RECEIVED ? <span /> : null}
section='coOperationNegotiations'
>
<$GridCell $colSpan={12}>
<$ViewField>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const CompanyInfoView: React.FC<ApplicationReviewViewProps> = ({ data }) => {
<ReviewSection
header={t(`${translationsBase}.headings.heading1`)}
action={data.status !== APPLICATION_STATUSES.RECEIVED ? <span /> : null}
section='company'
>
<$GridCell $colSpan={3}>
<$ViewField>{data.company?.name}</$ViewField>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const ContactPersonView: React.FC<ApplicationReviewViewProps> = ({ data }) => {
<ReviewSection
header={t(`${translationsBase}.headings.heading2`)}
action={data.status !== APPLICATION_STATUSES.RECEIVED ? <span /> : null}
section='companyContactPerson'
>
<$GridCell $colSpan={6}>
<$ViewField>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const DeminimisView: React.FC<ApplicationReviewViewProps> = ({ data }) => {
<ReviewSection
header={t(`${translationsBase}.headings.heading3`)}
action={data.status !== APPLICATION_STATUSES.RECEIVED ? <span /> : null}
section='deMinimisAids'
>
{data.deMinimisAidSet && data.deMinimisAidSet?.length > 0 ? (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const EmployeeView: React.FC<ApplicationReviewViewProps> = ({
return (
<ReviewSection
header={t(`${translationsBase}.headings.heading5`)}
section='employee'
action={
data.status !== APPLICATION_STATUSES.RECEIVED ? (
<EmployeeActions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const EmploymentView: React.FC<ApplicationReviewViewProps> = ({
return (
<ReviewSection
header={t(`${translationsBase}.headings.heading8`)}
section='employment'
action={
data.status !== APPLICATION_STATUSES.RECEIVED ? (
<EmploymentActions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const PaySubsidyView: React.FC<ApplicationReviewViewProps> = ({
return (
<ReviewSection
header={t(`${translationsBase}.headings.heading6`)}
section='paySubsidy'
action={
data.status !== APPLICATION_STATUSES.RECEIVED ? (
<PaySubsidyActions
Expand Down
Loading
Loading