Skip to content

Commit

Permalink
Merge pull request #2053 from MoveOnOrg/stage-main-11-1-bugfixes-only
Browse files Browse the repository at this point in the history
Stage main 11.1 release candidate
  • Loading branch information
crayolakat authored Oct 4, 2021
2 parents 9df3984 + 44767f3 commit 5e20141
Show file tree
Hide file tree
Showing 18 changed files with 202 additions and 156 deletions.
4 changes: 3 additions & 1 deletion __test__/extensions/service-vendors/twilio.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,9 @@ describe("twilio", () => {
describe("Number buying", () => {
it("buys numbers in batches from twilio", async () => {
const org2 = await cacheableData.organization.load(organizationId2);
await twilio.buyNumbersInAreaCode(org2, "212", 35);
await twilio.buyNumbersInAreaCode(org2, "212", 35, {
skipOrgMessageService: true
});
const inventoryCount = await r.getCount(
r.knex("owned_phone_number").where({
area_code: "212",
Expand Down
1 change: 0 additions & 1 deletion src/api/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,6 @@ const rootSchema = gql`
organizationId: ID!
areaCode: String!
limit: Int!
addToOrganizationMessagingService: Boolean
): JobRequest
deletePhoneNumbers(organizationId: ID!, areaCode: String!): JobRequest
releaseCampaignNumbers(campaignId: ID!): Campaign!
Expand Down
1 change: 0 additions & 1 deletion src/components/AssignmentTexter/ContactController.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export class ContactController extends React.Component {
// In fact, without the code below, we will 'double-jump' each message
// we send or change the status in some way.
// Below, we update our index with the contact that matches our current index.

if (nextState.currentContactIndex != this.state.currentContactIndex) {
console.log(
"updateindex <cur> <next>",
Expand Down
71 changes: 42 additions & 29 deletions src/components/AssignmentTexter/Controls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -530,36 +530,49 @@ export class AssignmentTexterContactControls extends React.Component {
renderNeedsResponseToggleButton(contact) {
const { messageStatus } = contact;
let button = null;
if (messageStatus === "needsMessage") {
return null;
} else if (messageStatus === "closed") {
// todo: add flex: style.
button = (
<Button
onClick={() => this.props.onEditStatus("needsResponse")}
className={css(flexStyles.button)}
style={{ flex: "1 1 auto" }}
disabled={!!this.props.contact.optOut}
color="default"
variant="outlined"
>
Reopen
</Button>
);
} else {
button = (
<Button
onClick={() => this.props.onEditStatus("closed", true)}
className={css(flexStyles.button)}
disabled={!!this.props.contact.optOut}
color="default"
variant="outlined"
>
Skip
</Button>
);
if (messageStatus !== "needsMessage") {
const status = this.state.messageStatus || messageStatus;
const onClick = (newStatus, finishContact) => async () => {
const res = await this.props.onEditStatus(newStatus, finishContact);
if (
res &&
res.data &&
res.data.editCampaignContactMessageStatus &&
res.data.editCampaignContactMessageStatus.messageStatus
) {
this.setState({
messageStatus:
res.data.editCampaignContactMessageStatus.messageStatus
});
}
};
if (status === "closed") {
button = (
<Button
onClick={onClick("needsResponse")}
className={css(flexStyles.button)}
style={{ flex: "1 1 auto" }}
disabled={!!this.props.contact.optOut}
color="default"
variant="outlined"
>
Reopen
</Button>
);
} else {
button = (
<Button
onClick={onClick("closed", true)}
className={css(flexStyles.button)}
disabled={!!this.props.contact.optOut}
color="default"
variant="outlined"
>
Skip
</Button>
);
}
}

return button;
}

Expand Down
10 changes: 9 additions & 1 deletion src/components/forms/GSTextField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export default class GSTextField extends GSFormField {
multiline,
name,
onChange,
onFocus,
onBlur,
placeholder,
required,
rows,
Expand Down Expand Up @@ -56,6 +58,7 @@ export default class GSTextField extends GSFormField {
margin,
multiline,
name,
onBlur,
placeholder,
required,
rows,
Expand Down Expand Up @@ -83,7 +86,12 @@ export default class GSTextField extends GSFormField {
<TextField
{...dataTest}
label={this.floatingLabelText()}
onFocus={event => event.target.select()}
onFocus={event => {
event.target.select();
if (onFocus) {
onFocus(event);
}
}}
{...textFieldProps}
onChange={event => {
onChange(event.target.value);
Expand Down
57 changes: 7 additions & 50 deletions src/containers/AdminPhoneNumberInventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ class AdminPhoneNumberInventory extends React.Component {

this.state = {
buyNumbersDialogOpen: false,
buyNumbersFormValues: {
addToOrganizationMessagingService: false
},
buyNumbersFormValues: {},
sortCol: "state",
sortOrder: "asc",
filters: {},
Expand All @@ -84,8 +82,7 @@ class AdminPhoneNumberInventory extends React.Component {
.number()
.required()
.max(window.MAX_NUMBERS_PER_BUY_JOB)
.min(1),
addToOrganizationMessagingService: yup.bool()
.min(1)
});
}

Expand Down Expand Up @@ -117,23 +114,14 @@ class AdminPhoneNumberInventory extends React.Component {
};

handleBuyNumbersSubmit = async () => {
const {
areaCode,
limit,
addToOrganizationMessagingService
} = this.state.buyNumbersFormValues;
await this.props.mutations.buyPhoneNumbers(
areaCode,
limit,
addToOrganizationMessagingService
);
const { areaCode, limit } = this.state.buyNumbersFormValues;
await this.props.mutations.buyPhoneNumbers(areaCode, limit);

this.setState({
buyNumbersDialogOpen: false,
buyNumbersFormValues: {
areaCode: null,
limit: null,
addToOrganizationMessagingService: false
limit: null
}
});
};
Expand Down Expand Up @@ -299,30 +287,6 @@ class AdminPhoneNumberInventory extends React.Component {
name="limit"
{...dataTest("limit")}
/>
{serviceName === "twilio" &&
serviceConfig.TWILIO_MESSAGE_SERVICE_SID &&
serviceConfig.TWILIO_MESSAGE_SERVICE_SID.length > 0 &&
!this.props.data.organization.campaignPhoneNumbersEnabled && (
<Form.Field
name="addToOrganizationMessagingService"
as={props => (
<FormControlLabel
{...props}
checked={props.value}
label="Add to this organization's Messaging Service"
control={<Switch color="primary" />}
/>
)}
style={{
marginTop: 30
}}
onToggle={(_, toggled) => {
this.handleFormChange({
addToOrganizationMessagingService: toggled
});
}}
/>
)}
</div>
<div style={inlineStyles.dialogActions}>
<Button
Expand Down Expand Up @@ -507,23 +471,17 @@ const queries = {
};

const mutations = {
buyPhoneNumbers: ownProps => (
areaCode,
limit,
addToOrganizationMessagingService
) => ({
buyPhoneNumbers: ownProps => (areaCode, limit) => ({
mutation: gql`
mutation buyPhoneNumbers(
$organizationId: ID!
$areaCode: String!
$limit: Int!
$addToOrganizationMessagingService: Boolean
) {
buyPhoneNumbers(
organizationId: $organizationId
areaCode: $areaCode
limit: $limit
addToOrganizationMessagingService: $addToOrganizationMessagingService
) {
id
}
Expand All @@ -532,8 +490,7 @@ const mutations = {
variables: {
organizationId: ownProps.params.organizationId,
areaCode,
limit,
addToOrganizationMessagingService
limit
},
refetchQueries: () => ["getOrganizationData"]
}),
Expand Down
3 changes: 2 additions & 1 deletion src/containers/AssignmentTexterContact.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,15 @@ export class AssignmentTexterContact extends React.Component {

handleEditStatus = async (messageStatus, finishContact) => {
const { contact } = this.props;
await this.props.mutations.editCampaignContactMessageStatus(
const res = await this.props.mutations.editCampaignContactMessageStatus(
messageStatus,
contact.id
);
if (finishContact) {
await this.handleSubmitSurveys();
this.props.onFinishContact();
}
return res;
};

handleOptOut = async ({ optOutMessageText }) => {
Expand Down
4 changes: 0 additions & 4 deletions src/extensions/contact-loaders/redash/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ export async function processContactLoad(job, maxContacts, organization) {
}
// 1. start query
const startQueryUrl = `${baseUrl}/api/queries/${queryId}/refresh${params}`;
console.log("REDASH 1");
let refreshRedashResult;
try {
refreshRedashResult = await httpRequest(startQueryUrl, {
Expand Down Expand Up @@ -249,12 +248,10 @@ export async function processContactLoad(job, maxContacts, organization) {
// 2. poll job status
const jobQueryId = redashJobData.job.id;
const redashPollStatusUrl = `${baseUrl}/api/jobs/${jobQueryId}`;
console.log("REDASH 2", redashJobData);
const redashQueryCompleted = await httpRequest(redashPollStatusUrl, {
method: "get",
bodyRetryFunction: async res => {
const json = await res.json();
console.log("statusValidation", json);
const jobStatus = json && json.job && json.job.status;
return jobStatus === 3 || jobStatus === 4 ? json : { RETRY: 1 };
},
Expand All @@ -263,7 +260,6 @@ export async function processContactLoad(job, maxContacts, organization) {
retryDelayMs: 3000, // 3 seconds
...httpsArgs(organization)
});
console.log("refreshDataResult", redashQueryCompleted);
if (redashQueryCompleted.job.status === 4) {
await failedContactLoad(
job,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,14 @@ export async function onCampaignUpdateSignal({
return await _editCampaignData(organization, campaign);
}

export async function onBuyPhoneNumbers({ organization, serviceName, opts }) {
return {
opts: {
skipOrgMessageService: true
}
};
}

export async function onVendorServiceFullyConfigured({
organization,
serviceName
Expand Down
14 changes: 10 additions & 4 deletions src/extensions/service-managers/scrub-bad-mobilenums/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _ from "lodash";
import { r, cacheableData } from "../../../server/models";
import { getFeatures } from "../../../server/api/lib/config";
import { getConfig, getFeatures } from "../../../server/api/lib/config";
import { Jobs } from "../../../workers/job-processes";
import { jobRunner } from "../../job-runners";
import { getServiceFromOrganization } from "../../service-vendors";
Expand Down Expand Up @@ -80,7 +80,6 @@ export async function getCampaignData({
// MUST NOT RETURN SECRETS!
// called both from edit and stats contexts: editMode==true for edit page
if (!fromCampaignStatsPage) {
// TODO: get campaignFeatures current
const features = getFeatures(campaign);
const {
scrubBadMobileNumsFreshStart = false,
Expand All @@ -90,6 +89,10 @@ export async function getCampaignData({
scrubBadMobileNumsDeletedOnUpload = null
} = features;

const scrubMobileOptional = getConfig(
"SCRUB_MOBILE_OPTIONAL",
organization
);
const serviceClient = getServiceFromOrganization(organization);
const scrubBadMobileNumsGettable =
typeof serviceClient.getContactInfo === "function";
Expand All @@ -111,10 +114,13 @@ export async function getCampaignData({
scrubBadMobileNumsGettable,
scrubBadMobileNumsCount,
scrubBadMobileNumsFinishedDeleteCount,
scrubBadMobileNumsDeletedOnUpload
scrubBadMobileNumsDeletedOnUpload,
scrubMobileOptional
},
fullyConfigured:
scrubBadMobileNumsFinished || scrubBadMobileNumsCount === 0
scrubBadMobileNumsFinished ||
scrubBadMobileNumsCount === 0 ||
scrubMobileOptional
};
}
}
Expand Down
Loading

0 comments on commit 5e20141

Please sign in to comment.