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

feature/change-contact-consent-to-read-only #7392

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
5 changes: 0 additions & 5 deletions src/apps/contacts/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ const QUERY_FIELDS = [
'company_uk_region',
]

const EMAIL_CONSENT_YES = 'Can be marketed to'
const EMAIL_CONSENT_NO = 'Cannot be marketed to'

const LEFT_COMPANY_OPTION = 'Left the company'
const NO_CONTACT_OPTION = 'Does not want to be contacted'
const ROLE_CHANGE_OPTION = 'Changed role/responsibility'
Expand All @@ -47,8 +44,6 @@ module.exports = {
LOCAL_NAV,
APP_PERMISSIONS,
QUERY_FIELDS,
EMAIL_CONSENT_YES,
EMAIL_CONSENT_NO,
LEFT_COMPANY_OPTION,
NO_CONTACT_OPTION,
ROLE_CHANGE_OPTION,
Expand Down
13 changes: 0 additions & 13 deletions src/apps/contacts/services/__test__/form.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ describe('contact form service', () => {
primary: true,
full_telephone_number: '+1 652423467167',
email: '[email protected]',
accepts_dit_email_marketing: true,
address_same_as_company: false,
notes: 'Some notes',
archived_by: null,
Expand Down Expand Up @@ -60,7 +59,6 @@ describe('contact form service', () => {
primary: 'yes',
full_telephone_number: '+1 652423467167',
email: '[email protected]',
accepts_dit_email_marketing: true,
address_same_as_company: 'no',
address_1: '99 N Shore Road',
address_2: 'Suite 20',
Expand Down Expand Up @@ -107,7 +105,6 @@ describe('contact form service', () => {
address_postcode: null,
address_country: null,
notes: 'Some notes',
accepts_dit_email_marketing: true,
}

const actual = contactFormService.getContactAsFormData(contact)
Expand All @@ -118,15 +115,5 @@ describe('contact form service', () => {
it('should handle a null contact', () => {
expect(contactFormService.getContactAsFormData(null)).to.be.null
})

context('when the contact accepts DBT email marketing', () => {
it('should set the marketing preferences to accepts_dit_email_marketing', () => {
const contact = assign({}, contactData, {
accepts_dit_email_marketing: true,
})
const actual = contactFormService.getContactAsFormData(contact)
expect(actual.accepts_dit_email_marketing).to.be.true
})
})
})
})
6 changes: 0 additions & 6 deletions src/apps/contacts/services/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ function getContactAsFormData(contact) {
return null
}

// default is that people are always marketable, unless opted out
if (!contact.hasOwnProperty('accepts_dit_email_marketing')) {
contact.accepts_dit_email_marketing = true
}

let result = {
id: contact.id,
company: contact.company.id,
Expand All @@ -29,7 +24,6 @@ function getContactAsFormData(contact) {
primary: contact.primary ? 'yes' : 'no',
full_telephone_number: contact.full_telephone_number,
email: contact.email,
accepts_dit_email_marketing: contact.accepts_dit_email_marketing,
address_same_as_company: contact.address_same_as_company ? 'yes' : 'no',
address_1: contact.address_1,
address_2: contact.address_2,
Expand Down
26 changes: 1 addition & 25 deletions src/client/components/ContactForm/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
FieldInput,
FieldRadios,
FieldTextarea,
FieldCheckboxes,
FieldAddress,
Main,
FormLayout,
Expand Down Expand Up @@ -80,7 +79,6 @@ const _ContactForm = ({
// We need to convert these to YES / NO strings
primary,
addressSameAsCompany,
acceptsDitEmailMarketing,
// These need to be renamed, so that they are compatible with the fields of
// the address sub-form
addressPostcode: postcode,
Expand Down Expand Up @@ -175,7 +173,6 @@ const _ContactForm = ({
city,
county,
postcode,
acceptsDitEmailMarketing,
addressSameAsCompany,
primary,
email,
Expand All @@ -189,8 +186,6 @@ const _ContactForm = ({
email,
valid_email: true,
notes: moreDetails,
accepts_dit_email_marketing:
acceptsDitEmailMarketing.includes(YES),
primary,
company,
address_same_as_company:
Expand Down Expand Up @@ -251,12 +246,9 @@ const _ContactForm = ({
country: addressCountry?.id,
primary: boolToYesNo(primary),
addressSameAsCompany: boolToYesNo(addressSameAsCompany),
acceptsDitEmailMarketing: [
boolToYesNo(acceptsDitEmailMarketing),
].filter(Boolean),
}}
>
{({ values }) => (
{() => (
<>
<FieldInput
label="First name"
Expand Down Expand Up @@ -329,21 +321,6 @@ const _ContactForm = ({
{ value: NO, label: NO },
]}
/>
<FieldCheckboxes
name="acceptsDitEmailMarketing"
options={[
{
value: YES,
label:
'The company contact does accept email marketing',
hint:
values?.acceptsDitEmailMarketing?.includes(
YES
) &&
'By checking this box, you confirm that the contact has opted in to email marketing.',
},
]}
/>
<FieldTextarea
label="More details (optional)"
name="moreDetails"
Expand Down Expand Up @@ -394,7 +371,6 @@ ContactForm.propTypes = {
primary: PropTypes.bool,
fullTelephoneNumber: PropTypes.string,
email: PropTypes.string,
acceptsDitEmailMarketing: PropTypes.bool,
addressSameAsCompany: PropTypes.bool,
address1: PropTypes.string,
address2: PropTypes.string,
Expand Down
2 changes: 0 additions & 2 deletions src/client/components/Resource/__stories__/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const CONTACT = {
telephoneCountrycode: '123',
telephoneNumber: '456789',
email: '[email protected]',
acceptsDitEmailMarketing: true,
addressSameAsCompany: true,
address1: 'Foo',
address2: 'Bar',
Expand Down Expand Up @@ -112,7 +111,6 @@ export default {
addressCountry: null,
addressPostcode: null,
notes: null,
acceptsDitEmailMarketing: false,
archived: false,
archivedDocumentsUrlPath: '',
archivedOn: null,
Expand Down
25 changes: 25 additions & 0 deletions src/client/modules/Contacts/ContactDetails/ConsentDetails.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react'
import { isNil } from 'lodash'

import { SectionHeader } from '../../../components'
import { transformContactConsents } from './transformers'

const ConsentDetails = ({ contact }) => {
const consentGiven = transformContactConsents(contact)
return (
<div>
<SectionHeader type="contact-consent">Contact consent</SectionHeader>
{isNil(contact.consentData) ? (
<p data-test="no-contact-consents">
There is no consent data available for this contact
</p>
) : (
<p>
{`This contact has ${consentGiven ? 'given' : 'not given'} consent to be contacted.`}
</p>
)}
</div>
)
}

export default ConsentDetails
13 changes: 3 additions & 10 deletions src/client/modules/Contacts/ContactDetails/ContactDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import { ContactResource } from '../../../components/Resource'
import { SummaryTable, ErrorSummary } from '../../../components'
import urls from '../../../../lib/urls'
import {
EMAIL_CONSENT_NO,
EMAIL_CONSENT_YES,
LEFT_COMPANY_OPTION,
NO_CONTACT_OPTION,
ROLE_CHANGE_OPTION,
} from '../../../../apps/contacts/constants'
import { ID, TASK_ARCHIVE_CONTACT } from './state'
import ArchiveForm from '../../../components/ArchiveForm'
import ContactLayout from '../../../components/Layout/ContactLayout'
import ConsentDetails from './ConsentDetails'

const getAddress = (contact, companyAddress) => {
const address = contact.addressSameAsCompany
Expand Down Expand Up @@ -82,14 +81,6 @@ const ContactDetails = ({ contactId, companyAddress, permissions }) => (
children={contact.notes}
/>
) : null}
<SummaryTable.Row
heading="Email marketing"
children={
contact.acceptsDitEmailMarketing
? EMAIL_CONSENT_YES
: EMAIL_CONSENT_NO
}
/>
</SummaryTable>
{!contact.archived ? (
<Button
Expand All @@ -103,6 +94,8 @@ const ContactDetails = ({ contactId, companyAddress, permissions }) => (
</Button>
) : null}

<ConsentDetails contact={contact} />

<ArchiveForm
id={ID}
submissionTaskName={TASK_ARCHIVE_CONTACT}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import 'core-js/proposals/array-grouping-v2'
import { transformContactConsents } from '../transformers'

describe('transformContactConsents', () => {
context('When a falsey contact is passed', () => {
it('Should return false', () => {
expect(transformContactConsents(undefined)).to.equal(false)
})
})

context('When a contact has no consent data', () => {
it('Should return false', () => {
expect(transformContactConsents({})).to.equal(false)
})
})

context(
'When a contact has a single domain and has not given consent',
() => {
it('Should return false', () => {
expect(
transformContactConsents({
consentData: [
{
consentDomain: 'International',
emailContactConsent: false,
},
],
})
).to.equal(false)
})
}
)

context('When a contact has a single domain and has given consent', () => {
it('Should return true', () => {
expect(
transformContactConsents({
consentData: [
{
consentDomain: 'International',
emailContactConsent: true,
},
],
})
).to.equal(true)
})
})

context(
'When a contact has a multiple domains and has given consent to one',
() => {
it('Should return true', () => {
expect(
transformContactConsents({
consentData: [
{
consentDomain: 'International',
emailContactConsent: true,
},
{
consentDomain: 'International',
emailContactConsent: false,
},
],
})
).to.equal(true)
})
}
)

context(
'When a contact has a multiple domains and has given consent to all',
() => {
it('Should return true', () => {
expect(
transformContactConsents({
consentData: [
{
consentDomain: 'International',
emailContactConsent: true,
},
{
consentDomain: 'International',
emailContactConsent: true,
},
],
})
).to.equal(true)
})
}
)
})
7 changes: 7 additions & 0 deletions src/client/modules/Contacts/ContactDetails/transformers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const transformContactConsents = (contact) => {
if (!contact || !contact.consentData) {
return false
}

return contact.consentData.some((consent) => consent.emailContactConsent)
}
Loading
Loading