Skip to content

Commit

Permalink
Merge pull request #2458 from StateVoicesNational/mz/revert-short-codes
Browse files Browse the repository at this point in the history
Revert short codes
  • Loading branch information
mau11 authored Sep 19, 2024
2 parents f0ee27e + 23f9733 commit a5779a0
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 276 deletions.
3 changes: 0 additions & 3 deletions src/api/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,6 @@ const rootSchema = gql`
areaCode: String!
limit: Int!
): JobRequest
getShortCodes(
organizationId: ID!
): JobRequest
deletePhoneNumbers(organizationId: ID!, areaCode: String!): JobRequest
releaseCampaignNumbers(campaignId: ID!): Campaign!
clearCachedOrgAndExtensionCaches(organizationId: String!): String
Expand Down
75 changes: 11 additions & 64 deletions src/containers/AdminPhoneNumberInventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ class AdminPhoneNumberInventory extends React.Component {
sortCol: "state",
sortOrder: "asc",
filters: {},
deleteNumbersDialogOpen: false,
queriedShortcodes: false
deleteNumbersDialogOpen: false
};
}

Expand Down Expand Up @@ -127,13 +126,6 @@ class AdminPhoneNumberInventory extends React.Component {
});
};

handleGetShortcodes = async() => {
this.setState({
queriedShortcodes: true
});
await this.props.mutations.getShortCodes();
};

handleDeleteNumbersOpen = ([areaCode, , , availableCount]) => {
this.setState({
deleteNumbersDialogOpen: true,
Expand Down Expand Up @@ -339,10 +331,6 @@ class AdminPhoneNumberInventory extends React.Component {
tableData = tableData.filter(data => data.state === filters.state);
}

if (this.state.queriedShortcodes){
this.numShortcodes = ownedAreaCodes.filter(j => ownedAreaCodes.indexOf('Shortcode') === -1).length
}

this.sortTable(tableData, this.state.sortCol, this.state.sortOrder);
const handleSortOrderChange = (key, order) => {
this.setState({
Expand Down Expand Up @@ -388,41 +376,17 @@ class AdminPhoneNumberInventory extends React.Component {
columns={this.tableColumns()}
options={options}
/>
<div
style={theme.layouts.buttons}
>
{this.props.params.ownerPerms ? (
// <Fab
<Button
{...dataTest("buyPhoneNumbers")}
color="primary"
variant="contained"
type="button"
style={theme.components.buyPhoneNumbersButton}
onClick={this.handleBuyNumbersOpen}
>
Buy Phone Numbers
</Button>
) : null}

{this.props.params.ownerPerms ? (
<Button
{...dataTest("getShortcodes")}
color="primary"
variant="contained"
type="button"
style={theme.components.checkShortCodesButton}
onClick={this.handleGetShortcodes}
>
Check for Short Codes
</Button>
) : null}
</div>
<p>
{this.state.queriedShortcodes ? (
`This service has ${this.numShortcodes} shortcodes.`
) : null}
</p>
{this.props.params.ownerPerms ? (
<Fab
{...dataTest("buyPhoneNumbers")}
color="primary"
style={theme.components.floatingButton}
onClick={this.handleBuyNumbersOpen}
>
<AddIcon />
</Fab>
) : null}

<Dialog
open={this.state.buyNumbersDialogOpen}
Expand Down Expand Up @@ -509,23 +473,6 @@ const queries = {
};

const mutations = {
getShortCodes: ownProps => () => ({
mutation: gql`
mutation getShortCodes(
$organizationId: ID!
) {
getShortCodes(
organizationId: $organizationId
) {
id
}
}
`,
variables: {
organizationId: ownProps.params.organizationId,
},
refetchQueries: () => ["getOrganizationData"]
}),
buyPhoneNumbers: ownProps => (areaCode, limit) => ({
mutation: gql`
mutation buyPhoneNumbers(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,6 @@ export async function onBuyPhoneNumbers({ organization, serviceName, opts }) {
};
}

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

export async function onVendorServiceFullyConfigured({
organization,
serviceName
Expand Down
7 changes: 0 additions & 7 deletions src/extensions/service-managers/test-fake-example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,6 @@ export async function onBuyPhoneNumbers({
opts
}) {}

export async function onGetShortcodes({
organization,
user,
serviceName,
opts
}) {}

export async function onOrganizationServiceVendorSetup({
organization,
user,
Expand Down
49 changes: 0 additions & 49 deletions src/extensions/service-vendors/twilio/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,54 +772,6 @@ async function getPhoneNumbersForService(organization, messagingServiceSid) {
.phoneNumbers.list({ limit: 400 });
}

/**
* Figure out if Twilio account has a shortcode and if so, add it
* to the owned_phone_numbers table
*
* TO DO: what happens if you've already added that phone number to the table?
* TO DO: what should we do with allocation fields
*/
export async function getShortCode(
organization,
opts = {},
) {

// var for count of short codes
let shortCodeCount = 0;

// getting the shortcode list from twilio
const twilioInstance = await exports.getTwilio(organization);
const response = await twilioInstance.shortCodes.list();

// throw error if we get a bad response
if (response.error) {
throw new Error(`Error collecting ShortCode: ${response.error}`);
}

// add each shortcode to the table
async function addShortCodeToPhoneNumberTable(shortcode){
return await r.knex("owned_phone_number").insert({
organization_id: organization.id,
phone_number: shortcode.shortCode,
service: "twilio",
service_id: shortcode.sid,
area_code: "Shortcode"
//...allocationFields
});

}

// for each response, add it to the table
const shortcodeResponse = response.map(shortcode => {
addShortCodeToPhoneNumberTable(shortcode);
shortCodeCount++;
});

// return the count of short codes
return shortCodeCount;

}

/**
* Add bought phone number to a Messaging Service
*/
Expand Down Expand Up @@ -1269,7 +1221,6 @@ export default {
getTwilio,
getServiceConfig,
getMessageServiceSid,
getShortCode,
messageServiceLink,
updateConfig,
getMetadata,
Expand Down
89 changes: 0 additions & 89 deletions src/server/api/mutations/getShortCodes.js

This file was deleted.

1 change: 0 additions & 1 deletion src/server/api/mutations/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export { bulkSendMessages } from "./bulkSendMessages";
export { bulkUpdateScript } from "./bulkUpdateScript";
export { buyPhoneNumbers, deletePhoneNumbers } from "./buyPhoneNumbers";
export { getShortCodes} from "./getShortCodes";
export { editOrganization } from "./editOrganization";
export { findNewCampaignContact } from "./findNewCampaignContact";
export { getOptOutMessage } from "./getOptOutMessage";
Expand Down
2 changes: 0 additions & 2 deletions src/server/api/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ import {
bulkUpdateScript,
buyPhoneNumbers,
deletePhoneNumbers,
getShortCodes,
findNewCampaignContact,
getOptOutMessage,
joinOrganization,
Expand Down Expand Up @@ -498,7 +497,6 @@ const rootMutations = {
bulkSendMessages,
bulkUpdateScript,
buyPhoneNumbers,
getShortCodes,
deletePhoneNumbers,
editOrganization,
findNewCampaignContact,
Expand Down
17 changes: 2 additions & 15 deletions src/styles/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,17 @@ const layouts = {
marginLeft: "auto",
marginRight: "auto",
textAlign: "center"
},
buttons: {
display: "flex",
justifyContent: "space-evenly",
marginTop: 20
}
};

const components = {
buyPhoneNumberButton: {
floatingButton: {
margin: 0,
top: "auto",
right: 20,
bottom: 20,
left: "auto",
position: "inherit"
},
checkShortCodesButton: {
marginLeft: 0,
top: "auto",
right: 20,
bottom: 20,
left: "auto",
position: "inherit"
position: "fixed"
},
logoDiv: {
margin: "50 auto",
Expand Down
5 changes: 1 addition & 4 deletions src/workers/job-processes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
clearOldJobs,
importScript,
buyPhoneNumbers,
getShortCodes,
deletePhoneNumbers,
startCampaign,
extensionJob
Expand Down Expand Up @@ -45,16 +44,14 @@ export const Jobs = Object.freeze({
BUY_PHONE_NUMBERS: "buy_phone_numbers",
DELETE_PHONE_NUMBERS: "delete_phone_numbers",
START_CAMPAIGN: "start_campaign",
EXTENSION_JOB: "extension_job",
GET_SHORT_CODES: "get_short_codes"
EXTENSION_JOB: "extension_job"
});

const jobMap = Object.freeze({
[Jobs.EXPORT]: exportCampaign,
[Jobs.ASSIGN_TEXTERS]: assignTexters,
[Jobs.IMPORT_SCRIPT]: importScript,
[Jobs.BUY_PHONE_NUMBERS]: buyPhoneNumbers,
[Jobs.GET_SHORT_CODES]: getShortCodes,
[Jobs.DELETE_PHONE_NUMBERS]: deletePhoneNumbers,
[Jobs.START_CAMPAIGN]: startCampaign,
[Jobs.EXTENSION_JOB]: extensionJob
Expand Down
Loading

0 comments on commit a5779a0

Please sign in to comment.