on master help sign in
Allow inclusion of custom message when sending invites
98fd7cbFang
src/lib/inviteMail.js+8−2
@@ -30,8 +30,14 @@ async function hasReceived(recipient) {
30 return res.hasReceived;
30 return res.hasReceived;
31}
31}
32
32
33−function sendMail(recipient, ticket, sender, tx) {
33+function sendMail(recipient, ticket, sender, message, tx) {
34− return sendRequest('/send-ticket', { recipient, ticket, sender, tx });
34+ return sendRequest('/send-ticket', {
35+ recipient,
36+ ticket,
37+ sender,
38+ message,
39+ tx,
40+ });
35}
41}
36
42
37export { hasReceived, sendMail };
43export { hasReceived, sendMail };
src/lib/useMailer.js+15−12
@@ -26,18 +26,21 @@ export default function useMailer() {
26
26
27 // prefix to avoid clobbering sendMail import
27 // prefix to avoid clobbering sendMail import
28 // also throws if return value is false
28 // also throws if return value is false
29− const _sendMail = useCallback(async (email, ticket, sender, rawTx) => {
29+ const _sendMail = useCallback(
30+ async (email, ticket, sender, message, rawTx) => {
30− if (STUB_MAILER) {
31+ if (STUB_MAILER) {
31− console.log(`${email} - ${ticket}`);
32+ console.log(`${email} - ${ticket}`);
32− await timeout(Math.random() * 1000); // simulate request with randomness
33+ await timeout(Math.random() * 1000); // simulate request with randomness
33− return true;
34+ return true;
34− }
35+ }
35−
36+
36− const success = await sendMail(email, ticket, sender, rawTx);
37+ const success = await sendMail(email, ticket, sender, message, rawTx);
37− if (!success) {
38+ if (!success) {
38− throw new Error('Failed to send mail');
39+ throw new Error('Failed to send mail');
39− }
40+ }
40− }, []);
41+ },
42+ []
43+ );
41
44
42 return { getHasReceived, sendMail: _sendMail };
45 return { getHasReceived, sendMail: _sendMail };
43}
46}
src/views/Invite/InviteEmail.js+14
@@ -11,6 +11,7 @@ import * as azimuth from 'azimuth-js';
11import {
11import {
12 Grid,
12 Grid,
13 Flex,
13 Flex,
14+ Input,
14 IconButton,
15 IconButton,
15 HelpText,
16 HelpText,
16 Text,
17 Text,
@@ -127,6 +128,7 @@ export default function InviteEmail() {
127 const [errors, addError] = useSetState();
128 const [errors, addError] = useSetState();
128
129
129 // manage general state that affects the whole form
130 // manage general state that affects the whole form
131+ const [message, setMessage] = useState('');
130 const [status, setStatus] = useState(STATUS.INPUT);
132 const [status, setStatus] = useState(STATUS.INPUT);
131 const [needFunds, setNeedFunds] = useState(null);
133 const [needFunds, setNeedFunds] = useState(null);
132 const [generalError, setGeneralError] = useState(null);
134 const [generalError, setGeneralError] = useState(null);
@@ -347,6 +349,7 @@ export default function InviteEmail() {
347 invite.email,
349 invite.email,
348 invite.ticket,
350 invite.ticket,
349 ob.patp(point),
351 ob.patp(point),
352+ message,
350 invite.rawTx
353 invite.rawTx
351 );
354 );
352 } catch (error) {
355 } catch (error) {
@@ -391,6 +394,7 @@ export default function InviteEmail() {
391
394
392 const onSubmit = useCallback(
395 const onSubmit = useCallback(
393 async values => {
396 async values => {
397+ setMessage(values.message);
394 cachedEmails.current = values.emails.reduce((memo, email, i) => {
398 cachedEmails.current = values.emails.reduce((memo, email, i) => {
395 memo[nameForEmailField(i)] = email;
399 memo[nameForEmailField(i)] = email;
396 return memo;
400 return memo;
@@ -599,6 +603,16 @@ export default function InviteEmail() {
599 );
603 );
600 })}
604 })}
601
605
606+ <Grid.Item
607+ full
608+ as={Input}
609+ type="text"
610+ name="message"
611+ label="Message (optional)"
612+ placeholder="Welcome aboard!"
613+ value={message}
614+ />
615+
602 {renderButton({ handleSubmit, fields })}
616 {renderButton({ handleSubmit, fields })}
603
617
604 {needFunds && (
618 {needFunds && (