Skip to content

Commit

Permalink
adding basic mail to functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeGoodall committed Aug 6, 2024
1 parent ba1e318 commit ae67689
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 94 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,4 @@ uploads/*
.idea

.DS_Store
volume/cache/*
15 changes: 15 additions & 0 deletions src/assets/emailTemplates/newEndpoint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
subject: "${organisation} submitted a ${dataset} endpoint"

body: |
Hello data management team,
A new endpoint has been submitted with these details and is ready to check:
Name: ${name}
Organisation: ${organisation}
Email: ${email}
Endpoint URL: ${endpoint}
Documentation URL: ${documentationUrl}
Dataset Type: ${dataset}
I confirm this dataset is provided under the Open Government Licence
91 changes: 0 additions & 91 deletions src/controllers/CheckAnswersController.js

This file was deleted.

30 changes: 30 additions & 0 deletions src/controllers/confirmationController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import PageController from './pageController.js'
import yaml from 'js-yaml';
import fs from 'fs';

const templateFile = 'src/assets/emailTemplates/newEndpoint.yml'

const templateContent = fs.readFileSync(templateFile, 'utf8');
const template = yaml.load(templateContent);

class confirmationController extends PageController {
locals(req, res, next) {
const name = req.sessionModel.get('name')
const email = req.sessionModel.get('email')
const organisation = req.sessionModel.get('lpa')
const dataset = req.sessionModel.get('dataset')
const documentationUrl = req.sessionModel.get('documentation-url')
const endpoint = req.sessionModel.get('endpoint-url')

const recipient = '[email protected]'
const templateVars = { name, organisation, email, endpoint, documentationUrl, dataset };
const subject = template.subject.replace(/\${(.*?)}/g, (match, key) => templateVars[key]);
const body = template.body.replace(/\${(.*?)}/g, (match, key) => templateVars[key]);

req.form.options.mailTo = `mailto:${recipient}?subject=${encodeURIComponent(subject)}&body=${encodeURIComponent(body)}`

super.locals(req, res, next)
}
}

export default confirmationController
4 changes: 2 additions & 2 deletions src/routes/form-wizard/endpoint-submission-form/steps.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import chooseDatasetController from '../../../controllers/chooseDatasetController.js'
import LpaDetailsController from '../../../controllers/lpaDetailsController.js'
import PageController from '../../../controllers/pageController.js'
import CheckAnswersController from '../../../controllers/CheckAnswersController.js'
import confirmationController from '../../../controllers/confirmationController.js'

const defaultParams = {
entryPoint: false,
Expand Down Expand Up @@ -38,12 +38,12 @@ export default {
},
'/check-answers': {
...defaultParams,
controller: CheckAnswersController,
next: 'confirmation',
backLink: '/dataset-details'
},
'/confirmation': {
...defaultParams,
controller: confirmationController,
template: 'submit/confirmation.html'
}
}
2 changes: 1 addition & 1 deletion src/views/submit/check.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ <h1 class="govuk-heading-l">

<form novalidate method="post">
{{ govukButton({
text: "Send data"
text: "Continue"
}) }}
</form>
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/views/submit/confirmation.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

## What happens next

We need you to send an email to [[email protected]]({{options.mailTo}}).

you can do that by clicking [this link]({{options.mailTo}})

We will process your submission and add your dataset to the [planning data platform](https://www.planning.data.gov.uk/).

Your dataset should appear on the platform within 5 working days.
Expand Down

0 comments on commit ae67689

Please sign in to comment.