From 7a286c11eccbc90fb66143025092ee80d4975996 Mon Sep 17 00:00:00 2001 From: Emma Smith Date: Tue, 22 Sep 2020 13:13:18 -0400 Subject: [PATCH 1/3] Replace hardcoded keys with the centralized list of Airtable keys Resolves #124 --- src/lib/airtable/tables/requests.js | 2 +- src/webapp/components/RequestPopup.js | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/lib/airtable/tables/requests.js b/src/lib/airtable/tables/requests.js index 98efe2a7..813299ab 100644 --- a/src/lib/airtable/tables/requests.js +++ b/src/lib/airtable/tables/requests.js @@ -1,6 +1,6 @@ const { merge } = require("lodash"); const _ = require("lodash"); -const { airbase } = require("~airtable/bases"); +const { airbase } = require("../bases"); const requestNotInSlack = (r) => { const meta = r.get(fields.meta); diff --git a/src/webapp/components/RequestPopup.js b/src/webapp/components/RequestPopup.js index e1db31c1..0edc9fa9 100644 --- a/src/webapp/components/RequestPopup.js +++ b/src/webapp/components/RequestPopup.js @@ -12,6 +12,7 @@ import HouseholdSizeChip from "./HouseholdSizeChip"; import DrivingClusterChip from "./DrivingClusterChip"; import { daysSinceSlackMessage } from "../helpers/time"; import ClusterMapContext from "../context/ClusterMapContext"; +import { fields } from "../../lib/airtable/tables/requests"; const useStyles = makeStyles((theme) => ({ divider: { @@ -70,17 +71,17 @@ const RequestPopup = ({ requests, closePopup }) => { underline="always" target="_blank" > - {meta["First Name"] || ""} + {meta[fields.firstName] || ""} ) : ( - meta["First Name"] + meta[fields.firstName] )} - {meta["Cross Street #1"]} + {meta[fields.crossStreetFirst]} {" and "} - {meta["Cross Street #2"]} + {meta[fields.crossStreetSecond]} @@ -91,9 +92,9 @@ const RequestPopup = ({ requests, closePopup }) => { - + - {meta["For Driving Clusters"] && } + {meta[fields.forDrivingClusters] && } {meta.slackPermalink ? ( From 31f9fd8f20ac67a121d3ca64f1244cc1455f2976 Mon Sep 17 00:00:00 2001 From: Emma Smith Date: Tue, 29 Sep 2020 12:28:18 -0400 Subject: [PATCH 2/3] Add the remaining raw airtable strings --- src/lib/airtable/tables/requests.js | 2 ++ src/workers/airtable-sync/actions/updateMessageContent.js | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lib/airtable/tables/requests.js b/src/lib/airtable/tables/requests.js index 813299ab..d9f07c8e 100644 --- a/src/lib/airtable/tables/requests.js +++ b/src/lib/airtable/tables/requests.js @@ -322,6 +322,8 @@ const fields = (exports.fields = { neighborhood: "Neighborhood MA-NYC", householdSize: "Household Size", forDrivingClusters: "For Driving Clusters", + slackChannel: "slack_channel", + slackTimestamp: "slack_ts", }); exports.SENSITIVE_FIELDS = [ fields.phone, diff --git a/src/workers/airtable-sync/actions/updateMessageContent.js b/src/workers/airtable-sync/actions/updateMessageContent.js index 19d06439..b5c90b41 100644 --- a/src/workers/airtable-sync/actions/updateMessageContent.js +++ b/src/workers/airtable-sync/actions/updateMessageContent.js @@ -2,6 +2,7 @@ const slackapi = require("~slack/webApi"); const { getExistingMessage } = require("~slack/channels"); const { fields: requestFields } = require("~airtable/tables/requests"); const { str } = require("~strings/i18nextWrappers"); +const { fields } = require("lib/airtable/tables/donorPaymentsSchema"); const mappings = { [requestFields.status_options.deliveryAssigned]: str( @@ -24,7 +25,7 @@ const mappings = { module.exports = async function updateMessageContent(record) { /* eslint dot-notation: ["error", { "allowPattern": "^[a-z]+(_[a-z]+)+$" }] */ const meta = record.getMeta(); - if (!meta["slack_ts"]) { + if (!requestFields.slackTimestamp) { return; } const existingMessage = await getExistingMessage( @@ -69,8 +70,8 @@ module.exports = async function updateMessageContent(record) { } await slackapi.chat.update({ - channel: meta["slack_channel"], - ts: meta["slack_ts"], + channel: requestFields.slackChannel, + ts: requestFields.slackTimestamp, text: newContent, }); }; From 6f14a5f11315f02b4570492aa35c1b4524ec1b62 Mon Sep 17 00:00:00 2001 From: Emma Smith Date: Tue, 29 Sep 2020 12:45:47 -0400 Subject: [PATCH 3/3] Oops, fixing linting error. --- src/workers/airtable-sync/actions/updateMessageContent.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/workers/airtable-sync/actions/updateMessageContent.js b/src/workers/airtable-sync/actions/updateMessageContent.js index b5c90b41..9bbbbce5 100644 --- a/src/workers/airtable-sync/actions/updateMessageContent.js +++ b/src/workers/airtable-sync/actions/updateMessageContent.js @@ -2,7 +2,6 @@ const slackapi = require("~slack/webApi"); const { getExistingMessage } = require("~slack/channels"); const { fields: requestFields } = require("~airtable/tables/requests"); const { str } = require("~strings/i18nextWrappers"); -const { fields } = require("lib/airtable/tables/donorPaymentsSchema"); const mappings = { [requestFields.status_options.deliveryAssigned]: str(