Skip to content

Commit

Permalink
feat: allow pasting comma separated list of tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
ajohn25 committed Aug 12, 2023
1 parent 1d1e82c commit 4cde457
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/components/forms/GSAutoReplyTokensField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,16 @@ const GSAutoReplyTokensField: React.FC<GSAutoReplyTokensFieldProps> = ({
}, [optionValue]);

const handleInputChange = (newValue: string) => {
setInputValue(newValue);
if (newValue.includes(",")) {
const splitTokens = newValue.split(",");
const tokenValues = splitTokens.map((token: string) =>
createOption(token)
);

const newOptionsValue = [...optionValue, ...tokenValues];
const uniqValue = uniqBy(newOptionsValue, "value");
setOptionValue(uniqValue);
} else setInputValue(newValue);
};

const handleChange = (newValue: Option[]) => {
Expand All @@ -53,8 +62,8 @@ const GSAutoReplyTokensField: React.FC<GSAutoReplyTokensFieldProps> = ({

const handleKeyDown: KeyboardEventHandler = (event) => {
if (!inputValue) return;

const lowerInputValue = inputValue.toLowerCase().trim();

if (optOutTriggers.includes(lowerInputValue)) {
setInputValue("");
return;
Expand Down Expand Up @@ -88,6 +97,7 @@ const GSAutoReplyTokensField: React.FC<GSAutoReplyTokensFieldProps> = ({
onChange={handleChange}
onInputChange={handleInputChange}
onKeyDown={handleKeyDown}
onPas
placeholder="Words or phrases that Spoke should automatically respond to using this script, separated by commas"
value={optionValue}
isDisabled={disabled}
Expand Down

0 comments on commit 4cde457

Please sign in to comment.