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

feat: perform "back" actions througout the app using centralized hook (hl-1276) #3394

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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 @@ -382,7 +382,7 @@ test('Handler handles the alteration from the last test properly', async (t: Tes
)
.ok();
await t
.expect(item.find('dl dd').withText(getCurrencyString(180)).exists)
.expect(item.find('dl dd').withText(getCurrencyString(180, 0)).exists)
.ok();
});

Expand Down
2 changes: 1 addition & 1 deletion frontend/benefit/handler/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@
"calculationOutOfDate": "Laskelma ei ole ajan tasalla"
},
"actions": {
"close": "Peruuta",
"close": "Sulje",
"handle": "Merkitse käsitellyksi",
"returnToApplication": "Palaa hakemukseen",
"returnToAlterationList": "Palaa muutosilmoituksiin"
Expand Down
2 changes: 1 addition & 1 deletion frontend/benefit/handler/public/locales/sv/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@
"calculationOutOfDate": "Laskelma ei ole ajan tasalla"
},
"actions": {
"close": "Peruuta",
"close": "Sulje",
"handle": "Merkitse käsitellyksi",
"returnToApplication": "Palaa hakemukseen",
"returnToAlterationList": "Palaa muutosilmoituksiin"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,6 @@ const AlterationHandling = (): JSX.Element => {
alteration={alteration}
onError={onError}
onSuccess={onSuccess}
onClose={() =>
router.push(`${ROUTES.APPLICATION}?id=${application.id}`)
}
/>
) : (
<Container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import useAlterationHandlingForm from 'benefit/handler/components/alterationHand
import { $CustomNotesActions } from 'benefit/handler/components/applicationReview/actions/handlingApplicationActions/HandlingApplicationActions.sc';
import Sidebar from 'benefit/handler/components/sidebar/Sidebar';
import { DEFAULT_MINIMUM_RECOVERY_AMOUNT } from 'benefit/handler/constants';
import { useRouterNavigation } from 'benefit/handler/hooks/applicationHandling/useRouterNavigation';
import {
Application,
ApplicationAlteration,
Expand Down Expand Up @@ -46,15 +47,13 @@ type Props = {
alteration: ApplicationAlteration;
onError: (error: AxiosError<unknown>) => void;
onSuccess: (isRecoverable: boolean) => void;
onClose: () => void;
};

const AlterationHandlingForm = ({
application,
alteration,
onError,
onSuccess,
onClose,
}: Props): JSX.Element => {
const {
t,
Expand All @@ -79,6 +78,9 @@ const AlterationHandlingForm = ({
const [isMessagesDrawerVisible, toggleMessagesDrawerVisibility] =
useState<boolean>(false);


const { navigateBack } = useRouterNavigation(null, null, null, true);

const [isCSVDownloadDone, setIsCSVDownloadDone] = useState<boolean>(false);

const handleAlterationCsvDownload = (): void => {
Expand Down Expand Up @@ -256,8 +258,12 @@ const AlterationHandlingForm = ({
<StickyActionBar>
<$StickyBarWrapper>
<$StickyBarColumn>
<Button onClick={onClose} theme="black" variant="secondary">
{t(`${translationBase}.actions.close`)}
<Button
onClick={() => navigateBack()}
theme="black"
variant="secondary"
>
{t(`${translationBase}.actions.returnToAlterationList`)}
</Button>
<Button
onClick={() =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ROUTES } from 'benefit/handler/constants';
import { useRouterNavigation } from 'benefit/handler/hooks/applicationHandling/useRouterNavigation';
import { useApplicationFormContext } from 'benefit/handler/hooks/useApplicationFormContext';
import { APPLICATION_STATUSES } from 'benefit-shared/constants';
import {
Expand Down Expand Up @@ -65,6 +66,8 @@ const ApplicationForm: React.FC = () => {

const { isFormActionEdit, isFormActionNew } = useApplicationFormContext();

const { navigateBack } = useRouterNavigation(application.status);

const stepperCss = {
'pointer-events': 'none',
p: {
Expand Down Expand Up @@ -245,7 +248,7 @@ const ApplicationForm: React.FC = () => {
<Button
theme="coat"
variant="primary"
onClick={() => router.push(ROUTES.HOME)}
onClick={() => navigateBack()}
data-testid="modalBack"
>
{t(`${translationsBase}.backWithoutSaving`)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const ApplicationHeader: React.FC<ApplicationReviewProps> = ({
</$ItemWrapper>
</$Col>
<$Col>
<StatusLabel status={data.status} />
<StatusLabel status={data.status} archived={data.archived} />
</$Col>
</$InnerWrapper>
</Container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ export interface ApplicationListProps {
}
const translationBase = 'common:applications.list.headings';

const updateTabToUrl = (tabNumber: APPLICATION_LIST_TABS): void => {
const newUrl = `/?tab=${tabNumber}`;
window.history.replaceState(
{ ...window.history.state, as: '/', url: newUrl },
'',
newUrl
);
};

const isBatchStatusHandlingComplete = (batchStatus: BATCH_STATUSES): boolean =>
[
BATCH_STATUSES.DECIDED_ACCEPTED,
Expand Down Expand Up @@ -113,9 +122,6 @@ const HandlerIndex: React.FC<ApplicationListProps> = ({
);
}

const updateTabToUrl = (tabNumber: APPLICATION_LIST_TABS): void =>
window.history.pushState({ tab }, '', `/?tab=${tabNumber}`);

const isInPayment = (application: ApplicationListItemData): boolean =>
[APPLICATION_STATUSES.ACCEPTED].includes(application.status) &&
!isString(application.batch) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const HandlingApplicationActions: React.FC<Props> = ({
{t(`${translationsBase}.saveAndContinue`)}
</Button>
) : (
<Button onClick={onSaveAndClose} theme="coat" variant="primary">
<Button onClick={onSaveAndClose} theme="black" variant="secondary">
{t(`${translationsBase}.close`)}
</Button>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
StepActionType,
StepStateType,
} from 'benefit/handler/hooks/applicationHandling/useHandlingStepper';
import { useRouterNavigation } from 'benefit/handler/hooks/applicationHandling/useRouterNavigation';
import useCloneApplicationMutation from 'benefit/handler/hooks/useCloneApplicationMutation';
import { APPLICATION_STATUSES } from 'benefit-shared/constants';
import { Application } from 'benefit-shared/types/application';
Expand Down Expand Up @@ -73,6 +74,12 @@ const HandlingApplicationActions: React.FC<Props> = ({
onDoneConfirmation,
} = useHandlingApplicationActions(application);

const { navigateBack } = useRouterNavigation(
application?.status,
application?.batch?.status,
application?.archived
);

const lastStep =
stepState.activeStepIndex === Number(stepState.steps?.length) - 1;
const router = useRouter();
Expand All @@ -88,9 +95,13 @@ const HandlingApplicationActions: React.FC<Props> = ({
(): void =>
void router.push({
pathname: '/',
query: { tab: APPLICATION_LIST_TABS.HANDLING },
query: {
tab: APPLICATION_LIST_TABS[
application?.status as unknown as keyof typeof APPLICATION_LIST_TABS
],
},
}),
[router]
[router, application.status]
);

const effectSaveAndClose = (): void => {
Expand All @@ -99,7 +110,7 @@ const HandlingApplicationActions: React.FC<Props> = ({
isSavingAndClosing
) {
setIsSavingAndClosing(false);
navigateToIndex();
void navigateBack();
}
};

Expand Down Expand Up @@ -136,6 +147,7 @@ const HandlingApplicationActions: React.FC<Props> = ({
stepState.activeStepIndex,
isSavingAndClosing,
navigateToIndex,
navigateBack,
]);
React.useEffect(() => {
setIsSavingAndClosing(false);
Expand Down Expand Up @@ -256,7 +268,7 @@ const HandlingApplicationActions: React.FC<Props> = ({
setIsSavingAndClosing(true);
};

const handleClose = (): void => navigateToIndex();
const handleClose = (): void => void navigateBack();

const { data: clonedData, mutate: cloneApplication } =
useCloneApplicationMutation();
Expand Down Expand Up @@ -325,7 +337,7 @@ const HandlingApplicationActions: React.FC<Props> = ({
<Button
onClick={openDialog}
theme="black"
disabled={isApplicationReadOnly}
disabled={isApplicationReadOnly && !application.ahjoCaseId}
variant="supplementary"
iconLeft={<IconTrash />}
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useRouterNavigation } from 'benefit/handler/hooks/applicationHandling/useRouterNavigation';
import { useDetermineAhjoMode } from 'benefit/handler/hooks/useDetermineAhjoMode';
import useHandlerReviewActions from 'benefit/handler/hooks/useHandlerReviewActions';
import useUpdateApplicationQuery from 'benefit/handler/hooks/useUpdateApplicationQuery';
import { APPLICATION_STATUSES } from 'benefit-shared/constants';
import { Application, ApplicationData } from 'benefit-shared/types/application';
Expand All @@ -24,7 +24,10 @@ const ReceivedApplicationActions: React.FC<Props> = ({
}) => {
const translationsBase = 'common:review.actions';
const { t } = useTranslation();
const { onSaveAndClose } = useHandlerReviewActions(application);
const { navigateBack } = useRouterNavigation(
application?.status,
application?.batch?.status
);

const { mutate: updateApplication } = useUpdateApplicationQuery();

Expand Down Expand Up @@ -61,16 +64,20 @@ const ReceivedApplicationActions: React.FC<Props> = ({

return (
<$Grid data-testid={dataTestId}>
<$GridCell>
<Button
onClick={() => navigateBack()}
theme="black"
variant="secondary"
>
{t(`${translationsBase}.close`)}
</Button>
</$GridCell>
<$GridCell $colSpan={2}>
<Button onClick={handleStatusChange} theme="coat">
{t(`${translationsBase}.handle`)}
</Button>
</$GridCell>
<$GridCell>
<Button onClick={onSaveAndClose} theme="black" variant="secondary">
{t(`${translationsBase}.close`)}
</Button>
</$GridCell>
</$Grid>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ import React from 'react';

import { $StatusLabel } from './StatusLabel.sc';

const StatusLabel: React.FC<{ status: APPLICATION_STATUSES }> = ({
status,
}) => {
const StatusLabel: React.FC<{
status: APPLICATION_STATUSES;
archived?: boolean;
}> = ({ status, archived }) => {
const { t } = useTranslation();
return (
<$StatusLabel status={status}>{t(`common:status.${status}`)}</$StatusLabel>
<$StatusLabel status={status}>
{t(`common:status.${status}`)}
{archived &&
` / ${t('common:header.navigation.archive').toLocaleLowerCase()}`}
</$StatusLabel>
);
};

Expand Down
Loading
Loading