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

Force texting hours at the campaign level #36

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
14 changes: 8 additions & 6 deletions src/components/CampaignTextingHoursForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class CampaignTextingHoursForm extends React.Component {
textingHoursEnforced: yup.boolean(),
textingHoursStart: yup.number().integer(),
textingHoursEnd: yup.number().integer(),
timezone: yup.string()
timezone: yup.string().required()
})

fireOnChangeIfTheFormValuesChanged(fieldName, newValue) {
Expand Down Expand Up @@ -159,20 +159,22 @@ export default class CampaignTextingHoursForm extends React.Component {
>
<CampaignFormSectionHeading
title='Texting hours for campaign'
subtitle='You can use the texting-hours configuration for your organization, or configure texting hours for this campaign.'
subtitle='Please configure texting hours for each campaign, noting the time zone of the individuals in the list you are uploading.'
/>

{this.addToggleFormField(
{/* Removed because it will always be true */}
{/*this.addToggleFormField(
'overrideOrganizationTextingHours',
'Override organization texting hours?'
)}
)*/}

{this.props.formValues.overrideOrganizationTextingHours ? (
<div>
{this.addToggleFormField(
{/* Removed because it will always be true */}
{/*this.addToggleFormField(
'textingHoursEnforced',
'Texting hours enforced?'
)}
)*/}

{this.props.formValues.textingHoursEnforced ? (
<div>
Expand Down
9 changes: 7 additions & 2 deletions src/containers/AdminCampaignEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,18 @@ const campaignInfoFragment = `
editors
`

const valueOverrides = {
overrideOrganizationTextingHours: true,
textingHoursEnforced: true
}

class AdminCampaignEdit extends React.Component {
constructor(props) {
super(props)
const isNew = props.location.query.new
this.state = {
expandedSection: isNew ? 0 : null,
campaignFormValues: props.campaignData.campaign,
campaignFormValues: Object.assign(props.campaignData.campaign, valueOverrides),
startingCampaign: false
}
}
Expand Down Expand Up @@ -126,7 +131,7 @@ class AdminCampaignEdit extends React.Component {
}

this.setState({
campaignFormValues: pushToFormValues
campaignFormValues: Object.assign({}, pushToFormValues, valueOverrides)
})
}

Expand Down
18 changes: 12 additions & 6 deletions src/server/api/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -929,16 +929,19 @@ const rootMutations = {

return []
},
// We've modified campaign creation on the client so that overrideOrganizationHours is always true
// and enforce_texting_hours is always true
// as a result, we're forcing admins to think about the time zone of each campaign
// and saving a join on this query.
sendMessage: async (_, { message, campaignContactId }, { user, loaders }) => {
const record = (await r.knex('campaign_contact')
.join('campaign', 'campaign_contact.campaign_id', 'campaign.id')
.where({ 'campaign_contact.id': parseInt(campaignContactId) })
.where({ 'campaign.is_archived': false })
.where({ 'campaign_contact.assignment_id': parseInt(message.assignmentId) })
.join('assignment', 'campaign_contact.assignment_id', 'assignment.id')
.join('organization', 'organization.id', 'campaign.organization_id')
.leftJoin('opt_out', {
'opt_out.organization_id': 'organization.id',
// 'opt_out.organization_id': 'campaign.organization.id',
'opt_out.cell': 'campaign_contact.cell'
})
.select(
Expand All @@ -952,16 +955,18 @@ const rootMutations = {
'campaign.texting_hours_end as c_texting_hours_end',
'campaign.texting_hours_enforced as c_texting_hours_enforced',
'assignment.user_id as a_assignment_user_id',
'organization.texting_hours_enforced as o_texting_hours_enforced',
'organization.texting_hours_end as o_texting_hours_end',
'opt_out.id as is_opted_out',
'campaign_contact.timezone_offset as contact_timezone_offset'
))[0]

if (!record) {
throw new GraphQLError('Your assignment has changed')
}

// setting defaults based on new forced conditions
record.o_texting_hours_enforced = true;
record.o_texting_hours_end = 21;

// This block will only need to be evaluated if message is sent from admin Message Review
if (record.a_assignment_user_id !== user.id) {
const currentRoles = await r
Expand Down Expand Up @@ -1072,7 +1077,8 @@ const rootMutations = {
return contact
})()

const [messageInstance, contactUpdateResult] = await Promise.all([messageSavePromise, contactSavePromise])
const [messageInsertResult, contactUpdateResult] = await Promise.all([messageSavePromise, contactSavePromise])
const messageInstance = Array.isArray(messageInsertResult) ? messageInsertResult[0] : messageInsertResult;

// Send message after we are sure messageInstance has been persisted
const service = serviceMap[messageInstance.service || process.env.DEFAULT_SERVICE]
Expand Down
3 changes: 0 additions & 3 deletions src/server/models/campaign.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ const Campaign = thinky.createModel('campaign', type.object().schema({
.default(21),
timezone: type
.string()
.required()
.default('US/Eastern')


}).allowExtra(false), { noAutoCreation: true })

Expand Down