diff --git a/pages/pil/unscoped/courses/content/fields.js b/pages/pil/unscoped/courses/content/fields.js index 31c36d3f2..6db322c20 100644 --- a/pages/pil/unscoped/courses/content/fields.js +++ b/pages/pil/unscoped/courses/content/fields.js @@ -3,6 +3,10 @@ module.exports = { label: 'Course title', hint: 'For your records' }, + coursePurpose: { + name: 'coursePurpose', + label: 'Course purpose' + }, startDate: { label: 'Course start date', hint: `This helps ensure the licences are approved in time. Licences will be valid for 3 months from the date of approval. diff --git a/pages/pil/unscoped/courses/content/index.js b/pages/pil/unscoped/courses/content/index.js index 22847a96f..fd5d712c5 100644 --- a/pages/pil/unscoped/courses/content/index.js +++ b/pages/pil/unscoped/courses/content/index.js @@ -8,6 +8,9 @@ module.exports = merge({}, baseContent, { title: { required: 'Enter a course title' }, + coursePurpose: { + required: 'Please select higher education or training' + }, startDate: { required: 'Enter the course start date', validDate: 'Enter a valid date', diff --git a/pages/pil/unscoped/courses/participants/add/content/index.js b/pages/pil/unscoped/courses/participants/add/content/index.js index ee415dd9e..4562f6075 100644 --- a/pages/pil/unscoped/courses/participants/add/content/index.js +++ b/pages/pil/unscoped/courses/participants/add/content/index.js @@ -1,5 +1,6 @@ module.exports = { - title: 'Apply for category E licence', + title: 'Enter participant details', + description: 'You are applying for a PIL-E on behalf of this participant. A PIL-E is a personal licence for higher education and training courses.', fields: { firstName: { label: 'First name' @@ -14,9 +15,30 @@ module.exports = { label: 'Date of birth', hint: 'For example, 12 11 1980' }, - trainingNeed: { - label: 'Training need', - hint: 'Include details about the participant\'s organisation, job title, specialism and grade (for example, trainee doctor or registrar). Explain how their career will benefit from training.' + organisation: { + label: 'Organisation' + }, + qualificationLevelAndSubject: { + label: 'Qualification level and subject', + hint: 'For example BSc Pharmacology' + }, + applicantLearningUse: { + label: 'How will the applicant use this learning in future scientific work using living animals', + hint: 'Explain how they intent to use it to design, conduct or analyse research.' + }, + jobTitleOrQualification: { + label: 'Job title, career stage or qualification', + hint: 'For example trainee doctor, consultant or registrar' + }, + fieldOfExpertise: { + label: 'Field of expertise', + hint: 'For example head and neck surgeon' + }, + applicantTrainingUseAtWork: { + label: 'How will the applicant use this training in their work' + }, + otherNotes: { + label: 'Other notes (optional)' } }, errors: { diff --git a/pages/pil/unscoped/courses/participants/add/helpers/participant-details-schema-helper.js b/pages/pil/unscoped/courses/participants/add/helpers/participant-details-schema-helper.js new file mode 100644 index 000000000..ce4e09597 --- /dev/null +++ b/pages/pil/unscoped/courses/participants/add/helpers/participant-details-schema-helper.js @@ -0,0 +1,13 @@ +const { omit } = require('lodash'); + +function participantDetailsSchemaHelper (schema, trainingCourse) { + if (trainingCourse.coursePurpose === 'higher-education') { + return omit(schema, ['jobTitleOrQualification', 'fieldOfExpertise', 'applicantTrainingUseAtWork']); + } else if (trainingCourse.coursePurpose === 'training') { + return omit(schema, ['qualificationLevelAndSubject', 'applicantLearningUse']); + } else { + throw new Error(`Invalid course purpose: ${trainingCourse.coursePurpose}`); + } +} + +module.exports = participantDetailsSchemaHelper; diff --git a/pages/pil/unscoped/courses/participants/add/index.js b/pages/pil/unscoped/courses/participants/add/index.js index 120da2e34..22c0b5de0 100644 --- a/pages/pil/unscoped/courses/participants/add/index.js +++ b/pages/pil/unscoped/courses/participants/add/index.js @@ -3,6 +3,7 @@ const { page } = require('@asl/service/ui'); const { form } = require('../../../../../common/routers'); const { buildModel } = require('../../../../../../lib/utils'); const confirm = require('./routers/confirm'); +const participantDetailsSchemaHelper = require('./helpers/participant-details-schema-helper'); const schema = require('./schema'); module.exports = () => { @@ -11,17 +12,24 @@ module.exports = () => { paths: ['/confirm'] }); + let modifiedSchema; + app.use((req, res, next) => { res.locals.static.course = req.trainingCourse; + + modifiedSchema = participantDetailsSchemaHelper(schema, req.trainingCourse); req.model = { id: 'new-participant', - ...buildModel(schema) + ...buildModel(modifiedSchema) }; next(); }); app.use(form({ - schema, + configure: (req, res, next) => { + req.form.schema = modifiedSchema; + next(); + }, process: (req, res, next) => { const day = req.body['dob-day']; const month = req.body['dob-month']; diff --git a/pages/pil/unscoped/courses/participants/add/schema/index.js b/pages/pil/unscoped/courses/participants/add/schema/index.js index 497bf14f5..5d8309e9c 100644 --- a/pages/pil/unscoped/courses/participants/add/schema/index.js +++ b/pages/pil/unscoped/courses/participants/add/schema/index.js @@ -27,10 +27,40 @@ module.exports = { { dateIsBefore: 'now' } ] }, - trainingNeed: { + organisation: { + inputType: 'inputText', + validate: [ + 'required' + ] + }, + qualificationLevelAndSubject: { + inputType: 'inputText', + validate: [ + 'required' + ] + }, + applicantLearningUse: { inputType: 'textarea', validate: [ 'required' ] + }, + jobTitleOrQualification: { + inputType: 'inputText', + validate: [ + 'required' + ] + }, + fieldOfExpertise: { + inputType: 'inputText', + validate: [ + 'required' + ] + }, + applicantTrainingUseAtWork: { + inputType: 'textarea' + }, + otherNotes: { + inputType: 'textarea' } }; diff --git a/pages/pil/unscoped/courses/participants/add/views/confirm.jsx b/pages/pil/unscoped/courses/participants/add/views/confirm.jsx index 340ed0258..cf4a2de77 100644 --- a/pages/pil/unscoped/courses/participants/add/views/confirm.jsx +++ b/pages/pil/unscoped/courses/participants/add/views/confirm.jsx @@ -1,12 +1,13 @@ import React from 'react'; import { useSelector } from 'react-redux'; -import pick from 'lodash/pick'; +import { pick, omit } from 'lodash'; import { FormLayout, Header, Snippet, ModelSummary } from '@ukhomeoffice/asl-components'; import { format } from 'date-fns'; import { dateFormat } from '../../../../../../../constants'; import participantSchema from '../schema'; import courseSchema from '../../../schema'; import formatters from '../../../formatters'; +import participantDetailsSchemaHelper from '../helpers/participant-details-schema-helper'; const localFormatters = { dob: { @@ -16,15 +17,20 @@ const localFormatters = { export default function Confirm() { const course = useSelector(state => state.static.course); + const coursePurposeSchema = participantDetailsSchemaHelper(participantSchema, course); + + const selectedSchemaItems = ['firstName', 'lastName', 'email', 'dob']; + const selectedCourseSchemaItems = ['title', 'coursePurpose', 'startDate', 'species', 'projectId', 'projectTitle']; + return (
title} subtitle={course.title} /> - - - + + + ); } diff --git a/pages/pil/unscoped/courses/participants/add/views/index.jsx b/pages/pil/unscoped/courses/participants/add/views/index.jsx index 406d69542..0a05fef86 100644 --- a/pages/pil/unscoped/courses/participants/add/views/index.jsx +++ b/pages/pil/unscoped/courses/participants/add/views/index.jsx @@ -1,6 +1,7 @@ import React from 'react'; import { useSelector } from 'react-redux'; import { Header, Snippet, FormLayout } from '@ukhomeoffice/asl-components'; +import * as schema from '../content/index'; export default function Page() { const course = useSelector(state => state.static.course); @@ -10,6 +11,8 @@ export default function Page() { title={title} subtitle={course.title} /> + +

{schema.description}

); } diff --git a/pages/pil/unscoped/courses/read/schema/index.js b/pages/pil/unscoped/courses/read/schema/index.js index 6eee90c51..5795cf0e6 100644 --- a/pages/pil/unscoped/courses/read/schema/index.js +++ b/pages/pil/unscoped/courses/read/schema/index.js @@ -1,4 +1,4 @@ const { pick } = require('lodash'); const schema = require('../../schema'); -module.exports = pick(schema, 'title', 'startDate', 'species', 'projectId', 'projectTitle'); +module.exports = pick(schema, 'title', 'coursePurpose', 'startDate', 'species', 'projectId', 'projectTitle'); diff --git a/pages/pil/unscoped/courses/schema/index.js b/pages/pil/unscoped/courses/schema/index.js index be6a4544a..2de83cdbf 100644 --- a/pages/pil/unscoped/courses/schema/index.js +++ b/pages/pil/unscoped/courses/schema/index.js @@ -2,6 +2,19 @@ module.exports = { projectTitle: { accessor: 'project.title' }, + coursePurpose: { + inputType: 'radioGroup', + options: [{ + value: 'higher-education', + label: 'Higher education', + hint: 'For example a degree in pharmacology or physiology' + }, { + value: 'training', + label: 'Training', + hint: 'For example to learn a new surgical procedure' + }], + validate: ['required'] + }, title: { inputType: 'inputText', show: true, diff --git a/pages/pil/unscoped/courses/schema/update.js b/pages/pil/unscoped/courses/schema/update.js index ed5e1b5b6..88c0c05e4 100644 --- a/pages/pil/unscoped/courses/schema/update.js +++ b/pages/pil/unscoped/courses/schema/update.js @@ -1,4 +1,4 @@ const { pick } = require('lodash'); const schema = require('./'); -module.exports = pick(schema, 'title', 'startDate', 'species', 'projectId'); +module.exports = pick(schema, 'title', 'coursePurpose', 'startDate', 'species', 'projectId'); diff --git a/pages/task/read/views/components/task-details.jsx b/pages/task/read/views/components/task-details.jsx index 42c0e840b..2db45b0e2 100644 --- a/pages/task/read/views/components/task-details.jsx +++ b/pages/task/read/views/components/task-details.jsx @@ -75,6 +75,17 @@ function EstablishmentLink({ establishment }) { ); } +function OrgAndQualificationDetails({ course }) { + return ( + +
Organisation
+
+ {course.organisation} +
+
+ ); +} + function EstablishmentsList({ establishments }) { return ( @@ -128,6 +139,7 @@ function ProjectDetails({ task }) { function PilDetails({ task }) { const profile = useSelector(state => state.static.profile) || get(task, 'data.modelData.profile'); + const course = useSelector(state => state.static.course) || get(task, 'data.modelData.trainingCourse'); const pil = profile.pil; const establishment = (pil && pil.establishment) ? pil.establishment : get(task, 'data.establishment'); const isApplication = task.type === 'application'; @@ -142,6 +154,7 @@ function PilDetails({ task }) { } + ); diff --git a/test/unit/pages/pil/unscoped/courses/participants/add/helpers/participant-details-schema-helper.spec.js b/test/unit/pages/pil/unscoped/courses/participants/add/helpers/participant-details-schema-helper.spec.js new file mode 100644 index 000000000..b974baf72 --- /dev/null +++ b/test/unit/pages/pil/unscoped/courses/participants/add/helpers/participant-details-schema-helper.spec.js @@ -0,0 +1,29 @@ +import participantDetailsSchemaHelper from '../../../../../pages/pil/unscoped/courses/participants/add/helpers/participant-details-schema-helper'; +import { omit } from 'lodash'; + +describe('participantDetailsSchemaHelper', () => { + const schema = { + jobTitle: 'Developer', + fieldOfExpertise: 'Software Engineering', + applicantTrainingUse: 'Development', + qualificationLevelAndSubject: 'BSc Computer Science', + applicantLearning: 'Advanced Programming' + }; + + it('should omit jobTitle, fieldOfExpertise, and applicantTrainingUse for higher-education course purpose', () => { + const trainingCourse = { coursePurpose: 'higher-education' }; + const result = participantDetailsSchemaHelper(schema, trainingCourse); + expect(result).toEqual(omit(schema, ['jobTitle', 'fieldOfExpertise', 'applicantTrainingUse'])); + }); + + it('should omit qualificationLevelAndSubject and applicantLearning for training course purpose', () => { + const trainingCourse = { coursePurpose: 'training' }; + const result = participantDetailsSchemaHelper(schema, trainingCourse); + expect(result).toEqual(omit(schema, ['qualificationLevelAndSubject', 'applicantLearning'])); + }); + + it('should throw an error for invalid course purpose', () => { + const trainingCourse = { coursePurpose: 'invalid-purpose' }; + expect(() => participantDetailsSchemaHelper(schema, trainingCourse)).toThrowError('Invalid course purpose: invalid-purpose'); + }); +});