Skip to content

Commit

Permalink
feat: prepare handler application index for new ahjo integration (hl-…
Browse files Browse the repository at this point in the history
…1278) (#2958)

* chore: move experimental ahjo button to main header

* chore: expose talpa status to application list, filter out ahjo case id

* chore: update translations

* feat: add index component for new ahjo integration
  • Loading branch information
sirtawast authored Apr 30, 2024
1 parent 1dbf1da commit 1ad52cf
Show file tree
Hide file tree
Showing 18 changed files with 428 additions and 46 deletions.
4 changes: 4 additions & 0 deletions backend/benefit/applications/api/v1/application_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ def _get_simplified_queryset(self, request, context) -> QuerySet:
should_filter_archived = request.query_params.get("filter_archived") == "1"
qs = qs.filter(archived=should_filter_archived)

ahjo_cases = request.query_params.get("ahjo_case") == "1"
if ahjo_cases:
qs = qs.filter(ahjo_case_id__isnull=False, ahjo_case_id__gt="")

return qs

def _get_attachment(self, attachment_pk):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1608,6 +1608,7 @@ class Meta(BaseApplicationSerializer.Meta):
"pay_subsidies",
"training_compensations",
"batch",
"talpa_status",
"create_application_for_company",
"latest_decision_comment",
"handled_at",
Expand Down
4 changes: 3 additions & 1 deletion backend/benefit/applications/api/v1/serializers/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,10 @@ def _update_applications(self, application_batch, applications):
class ApplicationBatchListSerializer(ApplicationBatchSerializer):
def to_representation(self, instance):
representation = super().to_representation(instance)

# Do not include applications that have been sent to Ahjo
applications = BatchApplicationSerializer(
Application.objects.filter(batch=instance),
Application.objects.filter(batch=instance, ahjo_case_id__isnull=True),
many=True,
).data
representation["applications"] = applications
Expand Down
5 changes: 4 additions & 1 deletion frontend/benefit/handler/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
"rejected": "Ei yhtään käsiteltyä kielteistä hakemusta.",
"received": "Ei yhtään saapunutta hakemusta.",
"archived": "Ei yhtään arkistoitua hakemusta.",
"accepted,rejected": "Ei yhtään päätettävänä olevaa hakemusta.",
"additional_information_needed": "Ei yhtään lisätietoja odottavaa hakemusta.",
"all": "Ei yhtään hakemusta.",
"draft": "Ei yhtään luonnosta."
Expand All @@ -201,7 +202,9 @@
"accepted": "Myönteiset",
"rejected": "Kielteiset",
"infoRequired": "Odottaa lisätietoja",
"decisions": "päätökset"
"decisions": "päätökset",
"pending": "Päätettävänä",
"inPayment": "Maksussa"
},
"errors": {
"fetch": {
Expand Down
5 changes: 4 additions & 1 deletion frontend/benefit/handler/public/locales/fi/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
"rejected": "Ei yhtään käsiteltyä kielteistä hakemusta.",
"received": "Ei yhtään saapunutta hakemusta.",
"archived": "Ei yhtään arkistoitua hakemusta.",
"accepted,rejected": "Ei yhtään päätettävänä olevaa hakemusta.",
"additional_information_needed": "Ei yhtään lisätietoja odottavaa hakemusta.",
"all": "Ei yhtään hakemusta.",
"draft": "Ei yhtään luonnosta."
Expand All @@ -201,7 +202,9 @@
"accepted": "Myönteiset",
"rejected": "Kielteiset",
"infoRequired": "Odottaa lisätietoja",
"decisions": "päätökset"
"decisions": "päätökset",
"pending": "Päätettävänä",
"inPayment": "Maksussa"
},
"errors": {
"fetch": {
Expand Down
5 changes: 4 additions & 1 deletion frontend/benefit/handler/public/locales/sv/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
"rejected": "Ei yhtään käsiteltyä kielteistä hakemusta.",
"received": "Ei yhtään saapunutta hakemusta.",
"archived": "Ei yhtään arkistoitua hakemusta.",
"accepted,rejected": "Ei yhtään päätettävänä olevaa hakemusta.",
"additional_information_needed": "Ei yhtään lisätietoja odottavaa hakemusta.",
"all": "Ei yhtään hakemusta.",
"draft": "Ei yhtään luonnosta."
Expand All @@ -201,7 +202,9 @@
"accepted": "Myönteiset",
"rejected": "Kielteiset",
"infoRequired": "Odottaa lisätietoja",
"decisions": "päätökset"
"decisions": "päätökset",
"pending": "Päätettävänä",
"inPayment": "Maksussa"
},
"errors": {
"fetch": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ import * as React from 'react';
import Container from 'shared/components/container/Container';
import { getFullName } from 'shared/utils/application.utils';
import { convertToUIDateFormat, formatDate } from 'shared/utils/date.utils';
import {
getLocalStorageItem,
removeLocalStorageItem,
setLocalStorageItem,
} from 'shared/utils/localstorage.utils';

import { $NoticeBar } from '../applicationReview/ApplicationReview.sc';
import {
Expand All @@ -30,20 +25,6 @@ type ApplicationReviewProps = {
isApplicationReadOnly: boolean;
};

const toggleNewAhjoMode = (): void => {
// eslint-disable-next-line no-alert
const confirm = window.confirm(
'Kokeile Ahjo-integraation käyttöliittymää? Vain testiympäristöihin, älä käytä tuotannossa!'
);
if (!confirm) return;
if (getLocalStorageItem('newAhjoMode') !== '1') {
setLocalStorageItem('newAhjoMode', '1');
} else {
removeLocalStorageItem('newAhjoMode');
}
window.location.reload();
};

const ApplicationHeader: React.FC<ApplicationReviewProps> = ({
data,
isApplicationReadOnly,
Expand Down Expand Up @@ -110,17 +91,6 @@ const ApplicationHeader: React.FC<ApplicationReviewProps> = ({
{data.submittedAt && formatDate(new Date(data.submittedAt))}
</$ItemValue>
</$ItemWrapper>
<$ItemWrapper>
<button
style={{ fontSize: '10px' }}
type="button"
onClick={toggleNewAhjoMode}
>
Ahjo-kokeilu
<br />
{getLocalStorageItem('newAhjoMode') ? 'pois' : 'päälle'}
</button>
</$ItemWrapper>
</$Col>
<$Col>
<StatusLabel status={data.status} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,17 @@ export const $CellContent = styled.div`
align-items: center;
background-color: ${(props) => props.theme.colors.white};
`;

type TagWrapperProps = {
$colors: {
background: string;
text: string;
};
};

export const $TagWrapper = styled.div<TagWrapperProps>`
#hds-tag {
background: ${(props) => props.$colors.background};
color: ${(props) => props.$colors.text};
}
`;
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'react-loading-skeleton/dist/skeleton.css';

import { ALL_APPLICATION_STATUSES, ROUTES } from 'benefit/handler/constants';
import {
ApplicationListTableColumns,
Expand All @@ -18,7 +16,12 @@ import {
} from 'shared/utils/date.utils';
import { useTheme } from 'styled-components';

import { $CellContent, $EmptyHeading, $Heading } from './ApplicationList.sc';
import {
$CellContent,
$EmptyHeading,
$Heading,
$TagWrapper,
} from './ApplicationList.sc';
import { useApplicationList } from './useApplicationList';

export interface ApplicationListProps {
Expand Down Expand Up @@ -64,10 +67,60 @@ const ApplicationList: React.FC<ApplicationListProps> = ({
status.includes(APPLICATION_STATUSES.HANDLING) && !isAllStatuses,
infoRequired:
status.includes(APPLICATION_STATUSES.INFO_REQUIRED) && !isAllStatuses,
accepted:
status.includes(APPLICATION_STATUSES.ACCEPTED) && !isAllStatuses,
rejected:
status.includes(APPLICATION_STATUSES.REJECTED) && !isAllStatuses,
}),
[isAllStatuses, status]
);

const getTagStyleForStatus = React.useMemo(
() =>
(
appStatus: APPLICATION_STATUSES
): { background: string; text: string } => {
let background: string;
let text: string = theme.colors.black;
switch (appStatus) {
case APPLICATION_STATUSES.DRAFT:
background = theme.colors.black50;
text = theme.colors.white;
break;

case APPLICATION_STATUSES.INFO_REQUIRED:
background = theme.colors.alertLight;
break;

case APPLICATION_STATUSES.RECEIVED:
background = theme.colors.black20;
break;

case APPLICATION_STATUSES.ACCEPTED:
background = theme.colors.tramLight;
break;

case APPLICATION_STATUSES.REJECTED:
background = theme.colors.brickMediumLight;
break;

case APPLICATION_STATUSES.CANCELLED:
background = theme.colors.alertDark;
break;

case APPLICATION_STATUSES.HANDLING:
background = theme.colors.infoLight;
break;

default:
background = theme.colors.black40;
break;
}
return { background, text };
},
[theme.colors]
);

const columns = React.useMemo(() => {
const cols: ApplicationListTableColumns[] = [
{
Expand Down Expand Up @@ -134,20 +187,24 @@ const ApplicationList: React.FC<ApplicationListProps> = ({
});
}

if (isAllStatuses) {
if (
isVisibleOnlyForStatus.accepted ||
isVisibleOnlyForStatus.rejected ||
isAllStatuses
) {
cols.push({
transform: ({
status: applicationStatus,
}: ApplicationListTableTransforms) => (
<div>
<$TagWrapper $colors={getTagStyleForStatus(applicationStatus)}>
<Tag>
{t(
`common:applications.list.columns.applicationStatuses.${String(
applicationStatus
)}`
)}
</Tag>
</div>
</$TagWrapper>
),
headerName: getHeader('applicationStatus'),
key: 'status',
Expand Down Expand Up @@ -219,7 +276,15 @@ const ApplicationList: React.FC<ApplicationListProps> = ({
});

return cols.filter(Boolean);
}, [t, getHeader, status, theme, isAllStatuses, isVisibleOnlyForStatus]);
}, [
t,
getHeader,
status,
theme,
isAllStatuses,
isVisibleOnlyForStatus,
getTagStyleForStatus,
]);

if (isLoading) {
return (
Expand All @@ -240,6 +305,7 @@ const ApplicationList: React.FC<ApplicationListProps> = ({
}

const statusAsString = isAllStatuses ? 'all' : status.join(',');

return (
<div data-testid={`application-list-${statusAsString}`}>
{list.length > 0 ? (
Expand Down
Loading

0 comments on commit 1ad52cf

Please sign in to comment.