Skip to content

Commit

Permalink
Revert "feature/change-contact-consent-to-read-only (#7392)" (#7434)
Browse files Browse the repository at this point in the history
This reverts commit 96f966f.
  • Loading branch information
chopkinsmade authored Dec 23, 2024
1 parent c295b78 commit 3170151
Show file tree
Hide file tree
Showing 15 changed files with 162 additions and 296 deletions.
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 @@ 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 @@ -24,6 +29,7 @@ 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: 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 @@ import {
FieldInput,
FieldRadios,
FieldTextarea,
FieldCheckboxes,
FieldAddress,
Main,
FormLayout,
Expand Down Expand Up @@ -79,6 +80,7 @@ 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 @@ -173,6 +175,7 @@ const _ContactForm = ({
city,
county,
postcode,
acceptsDitEmailMarketing,
addressSameAsCompany,
primary,
email,
Expand All @@ -186,6 +189,8 @@ 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 @@ -246,9 +251,12 @@ 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 @@ -321,6 +329,21 @@ 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 @@ -371,6 +394,7 @@ 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: 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

0 comments on commit 3170151

Please sign in to comment.