Skip to content

Commit

Permalink
Merge pull request #463 from mlibrary/bug-email-text-actions
Browse files Browse the repository at this point in the history
TypeError: Cannot read properties of undefined (reading 'email')
  • Loading branch information
erinesullivan authored May 14, 2024
2 parents a2c9700 + 660344d commit ff2a4f8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/modules/lists/components/ActionsList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ function ActionsList (props) {
<AuthenticationRequired profile={profile}>
<EmailAction
action={props.active}
emailAddress={profile?.email || ''}
{...props}
/>
</AuthenticationRequired>
Expand All @@ -96,6 +97,7 @@ function ActionsList (props) {
<AuthenticationRequired profile={profile}>
<TextAction
action={props.active}
phoneNumber={profile?.text || ''}
{...props}
/>
</AuthenticationRequired>
Expand Down
12 changes: 6 additions & 6 deletions src/modules/lists/components/EmailAction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import React, { useState } from 'react';
import ActionStatusMessage from '../ActionStatusMessage';
import PropTypes from 'prop-types';

function EmailAction (props) {
const [email, setEmail] = useState(props.profile.email || '');
function EmailAction ({ emailAddress, prejudice, datastore, setActive, action }) {
const [email, setEmail] = useState(emailAddress);
const [status, setStatus] = useState(undefined);

const setCloseStatus = () => {
props.setActive('');
setActive('');
setStatus(undefined);
};

Expand All @@ -17,13 +17,13 @@ function EmailAction (props) {

return (
<section className='lists-action'>
<ActionStatusMessage status={status} action={props.action} setCloseStatus={setCloseStatus} />
<ActionStatusMessage status={status} action={action} setCloseStatus={setCloseStatus} />
{(!status || status.status_code !== 'action.response.success') &&
<form
className='lists-action-form'
onSubmit={(event) => {
event.preventDefault();
props.prejudice.act('email', props.datastore.uid, email, handleSubmitCallback);
prejudice.act('email', datastore.uid, email, handleSubmitCallback);
}}
>
<div className='lists-action-field-container'>
Expand Down Expand Up @@ -52,7 +52,7 @@ function EmailAction (props) {
}

EmailAction.propTypes = {
profile: PropTypes.object,
emailAddress: PropTypes.string,
prejudice: PropTypes.object,
datastore: PropTypes.object,
setActive: PropTypes.func,
Expand Down
12 changes: 6 additions & 6 deletions src/modules/lists/components/TextAction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import React, { useState } from 'react';
import ActionStatusMessage from '../ActionStatusMessage';
import PropTypes from 'prop-types';

function TextAction (props) {
const [text, setText] = useState(props.profile.text || '');
function TextAction ({ phoneNumber, prejudice, datastore, setActive, action }) {
const [text, setText] = useState(phoneNumber);
const [status, setStatus] = useState(undefined);

const setCloseStatus = () => {
props.setActive('');
setActive('');
setStatus(undefined);
};

Expand All @@ -17,13 +17,13 @@ function TextAction (props) {

return (
<section className='lists-action'>
<ActionStatusMessage status={status} action={props.action} setCloseStatus={setCloseStatus} />
<ActionStatusMessage status={status} action={action} setCloseStatus={setCloseStatus} />
{(!status || status.status_code !== 'action.response.success') &&
<form
className='lists-action-form'
onSubmit={(event) => {
event.preventDefault();
props.prejudice.act('text', props.datastore.uid, text, handleSubmitCallback);
prejudice.act('text', datastore.uid, text, handleSubmitCallback);
}}
>
<div className='lists-action-field-container'>
Expand Down Expand Up @@ -55,7 +55,7 @@ function TextAction (props) {
}

TextAction.propTypes = {
profile: PropTypes.object,
phoneNumber: PropTypes.string,
prejudice: PropTypes.object,
datastore: PropTypes.object,
setActive: PropTypes.func,
Expand Down

0 comments on commit ff2a4f8

Please sign in to comment.