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

Allow users to enter 0 hours for instant reassignment #2474

Draft
wants to merge 2 commits into
base: stage-main-14.1.1
Choose a base branch
from
Draft
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
94 changes: 48 additions & 46 deletions src/components/CampaignDynamicAssignmentForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type from "prop-types";
import React from "react";
import GSForm from "../components/forms/GSForm";
import GSSubmitButton from "../components/forms/GSSubmitButton";
import GSIntegerField from "../components/forms/GSIntegerField"
import GSIntegerField from "../components/forms/GSIntegerField";
import GSTextField from "../components/forms/GSTextField";
import * as yup from "yup";
import Form from "react-formal";
Expand Down Expand Up @@ -54,7 +54,11 @@ class CampaignDynamicAssignmentForm extends React.Component {

render() {
const { joinToken, campaignId, organization } = this.props;
const { useDynamicAssignment, batchPolicies, useDynamicReplies } = this.state;
const {
useDynamicAssignment,
batchPolicies,
useDynamicReplies
} = this.state;
const unselectedPolicies = organization.batchPolicies
.filter(p => !batchPolicies.find(cur => cur === p))
.map(p => ({ id: p, name: p }));
Expand All @@ -74,7 +78,7 @@ class CampaignDynamicAssignmentForm extends React.Component {
label="Allow texters with a link to join and start texting when the campaign is started?"
labelPlacement="start"
/>
<br/>
<br />
<GSForm
schema={this.formSchema}
value={this.state}
Expand Down Expand Up @@ -126,8 +130,8 @@ class CampaignDynamicAssignmentForm extends React.Component {
as={GSIntegerField}
fullWidth
name="responseWindow"
type="number"
label="Expected Response Window (hours)"
inputProps={{ min: 0 }}
/>
<p style={{ paddingLeft: "8px" }}>
How long (in hours) before we should consider reassignment without
Expand All @@ -136,51 +140,49 @@ class CampaignDynamicAssignmentForm extends React.Component {
hours for slower campaigns or 2 hours or less for GOTV campaigns.
</p>
<FormControlLabel
control={
<Switch
color="primary"
checked={useDynamicReplies || false}
Copy link
Member Author

@mau11 mau11 Oct 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

future - we need to add a linter to the repo to avoid these type of indentation updates

onChange={(toggler, val) => {
console.log(toggler, val);
this.toggleChange("useDynamicReplies", val);
}}
control={
<Switch
color="primary"
checked={useDynamicReplies || false}
onChange={(toggler, val) => {
console.log(toggler, val);
this.toggleChange("useDynamicReplies", val);
}}
/>
}
label="Allow texters with a link to dynamically get assigned replies?"
labelPlacement="start"
/>
}
label="Allow texters with a link to dynamically get assigned replies?"
labelPlacement="start"
/>

{!useDynamicReplies ? null : (
<div>
<ul>
<li>
{joinToken ? (
<OrganizationReassignLink
joinToken={joinToken}
campaignId={campaignId}
/>
) : (
"Please save the campaign and reload the page to get the reply link to share with texters."
)}
</li>
<li>
You can turn off dynamic assignment after starting a campaign
to disallow more new texters to receive replies.
</li>
</ul>

<Form.Field
as={GSTextField}
fullWidth
name="replyBatchSize"
type="number"
label="How large should a batch of replies be?"
initialValue={200}
/>
</div>
)
{!useDynamicReplies ? null : (
<div>
<ul>
<li>
{joinToken ? (
<OrganizationReassignLink
joinToken={joinToken}
campaignId={campaignId}
/>
) : (
"Please save the campaign and reload the page to get the reply link to share with texters."
)}
</li>
<li>
You can turn off dynamic assignment after starting a
campaign to disallow more new texters to receive replies.
</li>
</ul>

}
<Form.Field
as={GSTextField}
fullWidth
name="replyBatchSize"
type="number"
label="How large should a batch of replies be?"
initialValue={200}
/>
</div>
)}
{organization.batchPolicies.length > 1 ? (
<div>
<h3>Batch Strategy</h3>
Expand Down
6 changes: 3 additions & 3 deletions src/components/forms/GSIntegerField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default class GSIntegerField extends GSFormField {
style
};
// can't be undefined or react throw uncontroled component error
if (!textFieldProps.value) {
if (textFieldProps.value !== 0 && !textFieldProps.value) {
textFieldProps.value = "";
}
textFieldProps.style = Object.assign(
Expand All @@ -96,8 +96,8 @@ export default class GSIntegerField extends GSFormField {
onChange={event => {
onChange(Number(event.target.value));
}}
type="number"
type="Number"
/>
);
}
}
}
2 changes: 1 addition & 1 deletion src/server/api/campaign.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ export const resolvers = {
const features = getFeatures(campaign);
return features.USE_DYNAMIC_REPLIES ? features.USE_DYNAMIC_REPLIES : false;
},
responseWindow: campaign => campaign.response_window || 48,
responseWindow: campaign => campaign.response_window != null ? campaign.response_window : 48,
organization: async (campaign, _, { loaders }) =>
campaign.organization ||
loaders.organization.load(campaign.organization_id),
Expand Down
5 changes: 3 additions & 2 deletions src/server/api/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -898,8 +898,9 @@ const rootMutations = {
campaign.batch_size ||
Number(getConfig("DEFAULT_BATCHSIZE", organization) || 300),
response_window:
campaign.response_window ||
Number(getConfig("DEFAULT_RESPONSEWINDOW", organization) || 48),
campaign.response_window != null
? campaign.response_window
: Number(getConfig("DEFAULT_RESPONSEWINDOW", organization) || 48),
is_started: false,
is_archived: false,
join_token: uuidv4()
Expand Down
Loading