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

Revert "feature/change-contact-consent-to-read-only" #7434

Merged
Merged
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: 5 additions & 0 deletions src/apps/contacts/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ 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 @@ -44,6 +47,8 @@ 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: 13 additions & 0 deletions src/apps/contacts/services/__test__/form.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ 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 @@ -59,6 +60,7 @@ 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 @@ -105,6 +107,7 @@ 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 @@ -115,5 +118,15 @@ 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: 6 additions & 0 deletions src/apps/contacts/services/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
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

Check warning on line 19 in src/apps/contacts/services/form.js

View check run for this annotation

Codecov / codecov/patch

src/apps/contacts/services/form.js#L19

Added line #L19 was not covered by tests
}

let result = {
id: contact.id,
company: contact.company.id,
Expand All @@ -24,6 +29,7 @@
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: 25 additions & 1 deletion src/client/components/ContactForm/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
FieldInput,
FieldRadios,
FieldTextarea,
FieldCheckboxes,
FieldAddress,
Main,
FormLayout,
Expand Down Expand Up @@ -79,6 +80,7 @@
// 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 @@ -173,6 +175,7 @@
city,
county,
postcode,
acceptsDitEmailMarketing,
addressSameAsCompany,
primary,
email,
Expand All @@ -186,6 +189,8 @@
email,
valid_email: true,
notes: moreDetails,
accepts_dit_email_marketing:
acceptsDitEmailMarketing.includes(YES),
primary,
company,
address_same_as_company:
Expand Down Expand Up @@ -246,9 +251,12 @@
country: addressCountry?.id,
primary: boolToYesNo(primary),
addressSameAsCompany: boolToYesNo(addressSameAsCompany),
acceptsDitEmailMarketing: [
boolToYesNo(acceptsDitEmailMarketing),
].filter(Boolean),
}}
>
{() => (
{({ values }) => (
<>
<FieldInput
label="First name"
Expand Down Expand Up @@ -321,6 +329,21 @@
{ 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.',

Check warning on line 343 in src/client/components/ContactForm/index.jsx

View check run for this annotation

Codecov / codecov/patch

src/client/components/ContactForm/index.jsx#L343

Added line #L343 was not covered by tests
},
]}
/>
<FieldTextarea
label="More details (optional)"
name="moreDetails"
Expand Down Expand Up @@ -371,6 +394,7 @@
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: 2 additions & 0 deletions src/client/components/Resource/__stories__/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const CONTACT = {
telephoneCountrycode: '123',
telephoneNumber: '456789',
email: '[email protected]',
acceptsDitEmailMarketing: true,
addressSameAsCompany: true,
address1: 'Foo',
address2: 'Bar',
Expand Down Expand Up @@ -111,6 +112,7 @@ export default {
addressCountry: null,
addressPostcode: null,
notes: null,
acceptsDitEmailMarketing: false,
archived: false,
archivedDocumentsUrlPath: '',
archivedOn: null,
Expand Down
25 changes: 0 additions & 25 deletions src/client/modules/Contacts/ContactDetails/ConsentDetails.jsx

This file was deleted.

13 changes: 10 additions & 3 deletions src/client/modules/Contacts/ContactDetails/ContactDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ 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 @@ -81,6 +82,14 @@ 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 @@ -94,8 +103,6 @@ const ContactDetails = ({ contactId, companyAddress, permissions }) => (
</Button>
) : null}

<ConsentDetails contact={contact} />

<ArchiveForm
id={ID}
submissionTaskName={TASK_ARCHIVE_CONTACT}
Expand Down

This file was deleted.

7 changes: 0 additions & 7 deletions src/client/modules/Contacts/ContactDetails/transformers.js

This file was deleted.

Loading
Loading