MCPcopy Create free account
hub / github.com/ChurchApps/B1Admin / SendTextDialog

Function SendTextDialog

src/groups/components/SendTextDialog.tsx:32–136  ·  view source on GitHub ↗
(props)

Source from the content-addressed store, hash-verified

30}
31
32interface Props {
33 groupId?: string;
34 groupName?: string;
35 range?: TextRange;
36 personId?: string;
37 personName?: string;
38 phoneNumber?: string;
39 personIds?: string[];
40 onClose: () => void;
41}
42
43interface TextTemplateOption {
44 id: string;
45 name: string;
46 category?: string;
47}
48
49interface PreviewData {
50 totalMembers: number;
51 eligibleCount: number;
52 optedOutCount: number;
53 noPhoneCount: number;
54}
55
56interface SendResult {
57 totalMembers: number;
58 recipientCount: number;
59 successCount: number;
60 failCount: number;
61 optedOutCount: number;
62 noPhoneCount: number;
63}
64
65export const SendTextDialog: React.FC<Props> = (props) => {
66 const [message, setMessage] = React.useState("");
67 const inputRef = React.useRef<HTMLTextAreaElement | null>(null);
68 const [templates, setTemplates] = React.useState<TextTemplateOption[]>([]);
69 const [selectedTemplateId, setSelectedTemplateId] = React.useState("");
70 const range = props.range;
71 const isGroupSend = !!props.groupId && !range;
72 const mergeFields = isGroupSend ? [...MERGE_FIELD_KEYS, GROUP_NAME_FIELD] : MERGE_FIELD_KEYS;
73 const resolveGroup = (text: string) => (isGroupSend ? text.replaceAll(GROUP_NAME_FIELD.key, props.groupName || "") : text);
74
75 const insertMergeField = (field: string) => {
76 const input = inputRef.current;
77 const start = input?.selectionStart ?? message.length;
78 const end = input?.selectionEnd ?? message.length;
79 const next = message.slice(0, start) + field + message.slice(end);
80 if (resolveGroup(next).length > MAX_LENGTH) return;
81 const caret = start + field.length;
82 // Commit now and place the caret in the same tick; a deferred caret lands after the next keystroke.
83 flushSync(() => setMessage(next));
84 inputRef.current?.focus();
85 inputRef.current?.setSelectionRange(caret, caret);
86 };
87
88 // Text templates are rows in the email templates list with the "Text" category.
89 React.useEffect(() => {

Callers

nothing calls this directly

Calls 4

useSendDialogFunction · 0.90
getTitleFunction · 0.85
renderResultFunction · 0.70
renderPreviewFunction · 0.70

Tested by

no test coverage detected