Skip to content

Commit

Permalink
Merge pull request #312 from LBHackney-IT/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
gdbarnes authored Apr 28, 2022
2 parents 4702e65 + 598616e commit 160a11e
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 162 deletions.
39 changes: 30 additions & 9 deletions components/layout/resident-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ interface ResidentLayoutProps {
children: ReactNode;
}

const INACTIVITY_TIME_BEFORE_WARNING_DIALOG = 30 * 1000 * 60; // 30 minutes
const TIME_TO_SHOW_DIALOG_BEFORE_SIGN_OUT = 30 * 1000; // 30 seconds
// const INACTIVITY_TIME_BEFORE_WARNING_DIALOG = 30 * 1000 * 60; // 30 minutes
// const TIME_TO_SHOW_DIALOG_BEFORE_SIGN_OUT = 30 * 1000; // 30 seconds

// const INACTIVITY_TIME_BEFORE_WARNING_DIALOG = 10 * 1000; // 10 seconds
// const TIME_TO_SHOW_DIALOG_BEFORE_SIGN_OUT = 10 * 1000; // 10 seconds
const INACTIVITY_TIME_BEFORE_WARNING_DIALOG = 10 * 1000; // 10 seconds
const TIME_TO_SHOW_DIALOG_BEFORE_SIGN_OUT = 10 * 1000; // 10 seconds

export default function ResidentLayout({
pageName,
Expand All @@ -49,24 +49,39 @@ export default function ResidentLayout({
}

dispatch(loadApplication()).then(() => setLoaded(true));

return () => {
setLoaded(false);
};
}, []);

const onSignOut = async () => {
router.push('/');
dispatch(exit());
};

const autoSignOut = () => {
if (!application.id) return;

setShowSignOutDialog(false);
signOutRef.current.click();
onSignOut();
};

const handleShowSignOutDialog = () => {
if (!application.id) return;

setTimeout(() => autoSignOut(), TIME_TO_SHOW_DIALOG_BEFORE_SIGN_OUT);
let timeBeforeAutoSignOut = setTimeout(
() => autoSignOut(),
TIME_TO_SHOW_DIALOG_BEFORE_SIGN_OUT
);
setShowSignOutDialog(true);

if (!application.id) {
clearTimeout(timeBeforeAutoSignOut);
return;
}

return () => {
clearTimeout(timeBeforeAutoSignOut);
};
};

const handleStayLoggedIn = () => {
Expand All @@ -78,10 +93,16 @@ export default function ResidentLayout({
() => handleShowSignOutDialog(),
INACTIVITY_TIME_BEFORE_WARNING_DIALOG
);

if (!application.id) {
clearTimeout(timeBeforeShowSignOutDialog);
return;
}

return () => {
clearTimeout(timeBeforeShowSignOutDialog);
};
}, []);
}, [application.id]);

return (
<>
Expand Down
23 changes: 12 additions & 11 deletions lib/hoc/withApplication.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
import { useRouter } from 'next/router';
import React, { useEffect } from 'react';
import { useAppSelector } from '../store/hooks';
import { useAppSelector, useAppDispatch } from '../store/hooks';
import { exit } from '../store/auth';
import { ApplicationStatus } from '../../lib/types/application-status';

export default function withApplication<P>(
WrappedComponent: React.ComponentType<P>
) {
return (props: P) => {
const router = useRouter();
const { id, status } = useAppSelector((store) => store.application);
const dispatch = useAppDispatch();
const application = useAppSelector((store) => store.application);

if (!application) {
router.push('/');
dispatch(exit());
}

useEffect(() => {
if (status === ApplicationStatus.DISQUALIFIED) {
if (application.status === ApplicationStatus.DISQUALIFIED) {
router.push('/apply/not-eligible');
}

if (status === ApplicationStatus.SUBMITTED) {
if (application.status === ApplicationStatus.SUBMITTED) {
router.push('/apply/confirmation');
}
}, [status]);

useEffect(() => {
if (!id) {
router.push('/');
}
}, [id]);
}, [application]);

return <WrappedComponent {...props} />;
};
Expand Down
27 changes: 9 additions & 18 deletions pages/apply/[resident]/[section].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { useAppSelector } from '../../../lib/store/hooks';
import { getApplicationSectionFromId } from '../../../lib/utils/application-forms';
import { isOver18 } from '../../../lib/utils/dateOfBirth';
import { getApplicationSectionsForResident } from '../../../lib/utils/resident';
import Custom404 from '../../404';

const ApplicationSection = (): JSX.Element => {
const router = useRouter();
Expand All @@ -20,11 +19,7 @@ const ApplicationSection = (): JSX.Element => {
const applicant = useAppSelector(selectApplicant(resident)) as Applicant;
const mainResident = useAppSelector((s) => s.application.mainApplicant);

if (!applicantHasId(applicant)) {
return <Custom404 />;
}

const baseHref = `/apply/${applicant.person?.id}`;
const baseHref = `/apply/${applicant?.person?.id}`;
const returnHref = '/apply/overview';

const sectionGroups = applicant
Expand Down Expand Up @@ -59,18 +54,14 @@ const ApplicationSection = (): JSX.Element => {

return (
<>
{applicantHasId(applicant) ? (
<Layout pageName={sectionName} breadcrumbs={breadcrumbs}>
<ApplicationForms
applicant={applicant}
sectionGroups={sectionGroups}
activeStep={section}
onSubmit={onSubmit}
/>
</Layout>
) : (
<Custom404 />
)}
<Layout pageName={sectionName} breadcrumbs={breadcrumbs}>
<ApplicationForms
applicant={applicant}
sectionGroups={sectionGroups}
activeStep={section}
onSubmit={onSubmit}
/>
</Layout>
</>
);
};
Expand Down
116 changes: 55 additions & 61 deletions pages/apply/[resident]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,67 +119,61 @@ const ResidentIndex = (): JSX.Element => {

return (
<>
{currentResident && mainResident ? (
<Layout pageName="Person overview" breadcrumbs={breadcrumbs}>
<h1 className="lbh-heading-h1" style={{ marginBottom: '40px' }}>
<span className="govuk-hint lbh-hint">
Complete information for:
</span>
{`${currentResident.person?.firstName} ${currentResident.person?.surname}`}
</h1>

{steps.map((step, index) => (
<div key={index}>
<HeadingTwo content={step.heading} />
<SummaryList>
{step.sections.map((formStep, index) => (
<SummaryListRow key={index}>
<SummaryListValue>
{isSectionActive(formStep.id) ? (
<Link href={`${baseHref}/${formStep.id}`}>
<a className="lbh-link">{formStep.heading}</a>
</Link>
) : (
formStep.heading
)}
</SummaryListValue>
<SummaryListActions>
{getQuestionValue(
currentResident.questions,
formStep.id,
'sectionCompleted',
false
) ? (
<Tag content="Completed" variant="green" />
) : (
cantStartYetTag(formStep.id)
)}
</SummaryListActions>
</SummaryListRow>
))}
</SummaryList>
</div>
))}
{tasks.remaining == 0 && (
<ButtonLink href={`/apply/${currentResident.person?.id}/summary/`}>
Check answers
</ButtonLink>
)}
<br />
<Button onClick={goBack} secondary={true}>
Save and go back
</Button>
{currentResident !== mainResident && (
<DeleteLink
content="Delete this information"
details="This information will be permanently deleted."
onDelete={onDelete}
/>
)}
</Layout>
) : (
<Custom404 />
)}
<Layout pageName="Person overview" breadcrumbs={breadcrumbs}>
<h1 className="lbh-heading-h1" style={{ marginBottom: '40px' }}>
<span className="govuk-hint lbh-hint">Complete information for:</span>
{`${currentResident.person?.firstName} ${currentResident.person?.surname}`}
</h1>

{steps.map((step, index) => (
<div key={index}>
<HeadingTwo content={step.heading} />
<SummaryList>
{step.sections.map((formStep, index) => (
<SummaryListRow key={index}>
<SummaryListValue>
{isSectionActive(formStep.id) ? (
<Link href={`${baseHref}/${formStep.id}`}>
<a className="lbh-link">{formStep.heading}</a>
</Link>
) : (
formStep.heading
)}
</SummaryListValue>
<SummaryListActions>
{getQuestionValue(
currentResident.questions,
formStep.id,
'sectionCompleted',
false
) ? (
<Tag content="Completed" variant="green" />
) : (
cantStartYetTag(formStep.id)
)}
</SummaryListActions>
</SummaryListRow>
))}
</SummaryList>
</div>
))}
{tasks.remaining == 0 && (
<ButtonLink href={`/apply/${currentResident.person?.id}/summary/`}>
Check answers
</ButtonLink>
)}
<br />
<Button onClick={goBack} secondary={true}>
Save and go back
</Button>
{currentResident !== mainResident && (
<DeleteLink
content="Delete this information"
details="This information will be permanently deleted."
onDelete={onDelete}
/>
)}
</Layout>
</>
);
};
Expand Down
1 change: 1 addition & 0 deletions pages/apply/confirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const ApplicationConfirmation = (): JSX.Element => {
);

const signOut = () => {
router.push('/');
dispatch(exit());
};

Expand Down
1 change: 1 addition & 0 deletions pages/apply/expect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const WhatToExpect = (): JSX.Element => {

const onCancel = () => {
// TODO: delete application
router.push('/');
dispatch(exit());
};

Expand Down
1 change: 1 addition & 0 deletions pages/apply/household/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const ApplicationHouseholdOverview = (): JSX.Element => {

const onDelete = () => {
// TODO: delete application
router.push('/');
dispatch(exit());
};

Expand Down
1 change: 1 addition & 0 deletions pages/apply/not-eligible.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const NotEligible = (): JSX.Element => {
}

const signOut = () => {
router.push('/');
dispatch(exit());
};

Expand Down
Loading

0 comments on commit 160a11e

Please sign in to comment.