Skip to content

Commit

Permalink
Merge pull request #73 from cabinetoffice/fix-redirection-bug-from-ch…
Browse files Browse the repository at this point in the history
…eck-your-requests-page

Fix redirection bug from check your requests page
  • Loading branch information
harley-harris authored May 1, 2024
2 parents 9acd154 + 5eb04d7 commit f486216
Show file tree
Hide file tree
Showing 22 changed files with 538 additions and 412 deletions.
4 changes: 4 additions & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ export const CONTACT_US_URL = '/contact-us';

export const SERVICE_URL = `${BASE_URL}${HOME_URL}`;

// Query Params

export const PREVIOUS_PAGE_QUERY_PARAM = 'previousPage';

// Feature Flags
export const FEATURE_FLAG_ENABLE_AUTH = getEnvironmentValue('FEATURE_FLAG_ENABLE_AUTH', 'false');

Expand Down
9 changes: 8 additions & 1 deletion src/config/nunjucks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@ export const configureNunjucks = (app: express.Application, viewsPath: string) =
express: app
}
);

nunjucksEnv.addGlobal('PARAMS', {
previousPage: config.PREVIOUS_PAGE_QUERY_PARAM
});
nunjucksEnv.addGlobal('ROUTES', {
HOME: config.HOME_URL,
CHECK_YOUR_REQUESTS_URL: config.CHECK_YOUR_REQUESTS_URL
});
nunjucksEnv.addGlobal('CDN_HOST', config.CDN_HOST);
nunjucksEnv.addGlobal('SERVICE_URL', config.SERVICE_URL);
nunjucksEnv.addGlobal('SERVICE_NAME', config.SERVICE_NAME);
nunjucksEnv.addGlobal('DEPARTMENT_NAME', config.DEPARTMENT_NAME);
nunjucksEnv.addGlobal('GITHUB_ORG_NAME', config.GITHUB_ORG_NAME);

};
3 changes: 2 additions & 1 deletion src/controller/add-collaborator.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { v4 as uuidv4 } from 'uuid';

import * as config from '../config';
import { log } from '../utils/logger';
import { getPreviousPageUrl } from '../utils/getPreviousPageUrl';

import { AddCollaborator, AddCollaboratorKey } from '../model/add-collaborator.model';

Expand Down Expand Up @@ -60,7 +61,7 @@ export const postById = (req: Request, res: Response, next: NextFunction) => {

setApplicationDataByID(req.session, { ...req.body, [config.ID]: collaboratorID }, AddCollaboratorKey, collaboratorID);

return res.redirect(config.HOME_URL);
return res.redirect(getPreviousPageUrl(req));
} catch (err: any) {
log.errorRequest(req, err.message);
next(err);
Expand Down
3 changes: 2 additions & 1 deletion src/controller/add-member.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { v4 as uuidv4 } from 'uuid';

import * as config from '../config';
import { log } from '../utils/logger';
import { getPreviousPageUrl } from '../utils/getPreviousPageUrl';

import { AddMember, AddMemberKey } from '../model/add-member.model';

Expand Down Expand Up @@ -71,7 +72,7 @@ export const postById = (req: Request, res: Response, next: NextFunction) => {
AddMemberKey, memberID
);

return res.redirect(config.HOME_URL);
return res.redirect(getPreviousPageUrl(req));
} catch (err: any) {
log.errorRequest(req, err.message);
next(err);
Expand Down
3 changes: 2 additions & 1 deletion src/controller/add-repo.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { v4 as uuidv4 } from 'uuid';

import * as config from '../config';
import { log } from '../utils/logger';
import { getPreviousPageUrl } from '../utils/getPreviousPageUrl';

import { AddRepo, AddRepoKey } from '../model/add-repo.model';

Expand Down Expand Up @@ -56,7 +57,7 @@ export const postById = (req: Request, res: Response, next: NextFunction) => {

setApplicationDataByID(req.session, { ...req.body, [config.ID]: repoID }, AddRepoKey, repoID);

return res.redirect(config.HOME_URL);
return res.redirect(getPreviousPageUrl(req));
} catch (err: any) {
log.errorRequest(req, err.message);
next(err);
Expand Down
3 changes: 2 additions & 1 deletion src/controller/add-team-member.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as config from '../config';
import { log } from '../utils/logger';

import { AddTeamMember, AddTeamMemberKey } from '../model/add-team-member.model';
import { getPreviousPageUrl } from '../utils/getPreviousPageUrl';

export const get = (_req: Request, res: Response) => {
return res.render(config.ADD_TEAM_MEMBER);
Expand Down Expand Up @@ -57,7 +58,7 @@ export const postById = (req: Request, res: Response, next: NextFunction) => {

setApplicationDataByID(req.session, { ...req.body, [config.ID]: teamMembersID }, AddTeamMemberKey, teamMembersID);

return res.redirect(config.HOME_URL);
return res.redirect(getPreviousPageUrl(req));
} catch (err: any) {
log.errorRequest(req, err.message);
next(err);
Expand Down
3 changes: 2 additions & 1 deletion src/controller/add-team.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as config from '../config';
import { log } from '../utils/logger';

import { AddTeam, AddTeamKey } from '../model/add-team.model';
import { getPreviousPageUrl } from '../utils/getPreviousPageUrl';

export const get = (_req: Request, res: Response) => {
return res.render(config.ADD_TEAM);
Expand Down Expand Up @@ -56,7 +57,7 @@ export const postById = (req: Request, res: Response, next: NextFunction) => {

setApplicationDataByID(req.session, { ...req.body, [config.ID]: teamID }, AddTeamKey, teamID);

return res.redirect(config.HOME_URL);
return res.redirect(getPreviousPageUrl(req));
} catch (err: any) {
log.errorRequest(req, err.message);
next(err);
Expand Down
3 changes: 2 additions & 1 deletion src/controller/additional-requests.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as config from '../config';
import { log } from '../utils/logger';

import { AdditionalRequests, AdditionalRequestsKey } from '../model/additional-requests.model';
import { getPreviousPageUrl } from '../utils/getPreviousPageUrl';

export const get = (_req: Request, res: Response) => {
return res.render(config.ADDITIONAL_REQUESTS);
Expand Down Expand Up @@ -55,7 +56,7 @@ export const postById = (req: Request, res: Response, next: NextFunction) => {

setApplicationDataByID(req.session, { ...req.body, [config.ID]: additionalRequestsID }, AdditionalRequestsKey, additionalRequestsID);

return res.redirect(config.HOME_URL);
return res.redirect(getPreviousPageUrl(req));
} catch (err: any) {
log.errorRequest(req, err.message);
next(err);
Expand Down
4 changes: 4 additions & 0 deletions src/utils/getPreviousPageUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Request } from 'express';
import * as config from '../config';

export const getPreviousPageUrl = (req: Request): string => (config.PREVIOUS_PAGE_QUERY_PARAM in req.query) ? config.CHECK_YOUR_REQUESTS_URL : config.HOME_URL;
182 changes: 92 additions & 90 deletions src/views/include/check-your-requests/add-collaborator.html
Original file line number Diff line number Diff line change
@@ -1,99 +1,101 @@
{% set previousPageQueryParam = "?" + PARAMS.previousPage + "=" + ROUTES.CHECK_YOUR_REQUESTS_URL %}

{% for collaborator in add_collaborator %}

{% set firstNameHref = "/add-collaborator/" + collaborator.id + "#first_name" %}
{% set lastNameHref = "/add-collaborator/" + collaborator.id + "#last_name" %}
{% set githubHandleHref = "/add-collaborator/" + collaborator.id + "#github_handle" %}
{% set emailAddressHref = "/add-collaborator/" + collaborator.id + "#email_address" %}
{% set repoHref = "/add-collaborator/" + collaborator.id + "#repo_name" %}
{% set firstNameHref = "/add-collaborator/" + collaborator.id + previousPageQueryParam + "#first_name" %}
{% set lastNameHref = "/add-collaborator/" + collaborator.id + previousPageQueryParam + "#last_name" %}
{% set githubHandleHref = "/add-collaborator/" + collaborator.id + previousPageQueryParam + "#github_handle" %}
{% set emailAddressHref = "/add-collaborator/" + collaborator.id + previousPageQueryParam + "#email_address" %}
{% set repoHref = "/add-collaborator/" + collaborator.id + previousPageQueryParam + "#repo_name" %}

<br>
{{ govukSummaryList({
rows: [
{
key: {
text: "First Name"
},
value: {
text: collaborator.first_name
},
actions: {
items: [
{
href: firstNameHref,
text: "Change",
visuallyHiddenText: "First Name"
}
]
}
},
{
key: {
text: "Last Name"
},
value: {
text: collaborator.last_name
<br>
{{ govukSummaryList({
rows: [
{
key: {
text: "First Name"
},
value: {
text: collaborator.first_name
},
actions: {
items: [
{
href: firstNameHref,
text: "Change",
visuallyHiddenText: "First Name"
}
]
}
},
actions: {
items: [
{
href: lastNameHref,
text: "Change",
visuallyHiddenText: "Last Name"
}
]
}
},
{
key: {
text: "GitHub Handle"
{
key: {
text: "Last Name"
},
value: {
text: collaborator.last_name
},
actions: {
items: [
{
href: lastNameHref,
text: "Change",
visuallyHiddenText: "Last Name"
}
]
}
},
value: {
text: collaborator.github_handle
},
actions: {
items: [
{
href: githubHandleHref,
text: "Change",
visuallyHiddenText: "Github Handle"
}
]
}
},
{
key: {
text: "Email Address"
},
value: {
text: collaborator.email_address
},
actions: {
items: [
{
href: emailAddressHref,
text: "Change",
visuallyHiddenText: "Email Address"
}
]
}
},
{
key: {
text: "Repository Name"
{
key: {
text: "GitHub Handle"
},
value: {
text: collaborator.github_handle
},
actions: {
items: [
{
href: githubHandleHref,
text: "Change",
visuallyHiddenText: "Github Handle"
}
]
}
},
value: {
text: collaborator.repo_name
{
key: {
text: "Email Address"
},
value: {
text: collaborator.email_address
},
actions: {
items: [
{
href: emailAddressHref,
text: "Change",
visuallyHiddenText: "Email Address"
}
]
}
},
actions: {
items: [
{
href: repoHref,
text: "Change",
visuallyHiddenText: "Repository name"
}
]
{
key: {
text: "Repository Name"
},
value: {
text: collaborator.repo_name
},
actions: {
items: [
{
href: repoHref,
text: "Change",
visuallyHiddenText: "Repository name"
}
]
}
}
}
]
}) }}
]
}) }}
{% endfor %}
Loading

0 comments on commit f486216

Please sign in to comment.