From c1387f48948db68cab6ca2d4011472dda7b24733 Mon Sep 17 00:00:00 2001 From: "Erin E. Sullivan" Date: Mon, 18 Sep 2023 15:52:20 -0400 Subject: [PATCH] Converting `EmailAction` to a functional component. --- .../lists/components/EmailAction/index.js | 95 ++++++------------- 1 file changed, 30 insertions(+), 65 deletions(-) diff --git a/src/modules/lists/components/EmailAction/index.js b/src/modules/lists/components/EmailAction/index.js index 2acadfbdf..d204457c4 100644 --- a/src/modules/lists/components/EmailAction/index.js +++ b/src/modules/lists/components/EmailAction/index.js @@ -1,82 +1,53 @@ -import React, { Component } from 'react'; -import { connect } from 'react-redux'; +import React, { useState } from 'react'; import ActionStatusMessage from '../ActionStatusMessage'; import { Button } from '../../../reusable'; import PropTypes from 'prop-types'; -class EmailAction extends Component { - state = { - email: '', - sent: false, - status: undefined - }; - - componentDidMount () { - const { email } = this.props.profile; +function EmailAction (props) { + const [email, setEmail] = useState(props.profile.email || ''); + const [status, setStatus] = useState(undefined); - if (email) { - this.setState({ email }); - } + if (props.listLength === 0) { + return null; } - handleChange = (event) => { - this.setState({ email: event.target.value }); - }; - - handleSubmitCallback = (data) => { - this.setState({ status: data }); + const setCloseStatus = () => { + props.setActive(''); + setStatus(undefined); }; - handleSubmit = (event) => { - event.preventDefault(); - this.setState({ sent: true }); - this.props.prejudice.act('email', this.props.datastore.uid, this.state.email, this.handleSubmitCallback); + const handleSubmitCallback = (data) => { + setStatus(data); }; - setCloseStatus = () => { - this.props.setActive(''); - this.setState({ status: undefined, sent: false }); - }; - - renderForm = () => { - const { status } = this.state; - - if (!status || status.status_code !== 'action.response.success') { - return ( -
+ return ( +
+ + {(!status || status.status_code !== 'action.response.success') && + { + event.preventDefault(); + props.prejudice.act('email', props.datastore.uid, email, handleSubmitCallback); + }} + >
{ + setEmail(event.target.value); + }} autoComplete='on' />
- - ); - } - - return null; - }; - - render () { - const { listLength, action } = this.props; - - if (listLength === 0) { - return null; - } - - return ( -
- - {this.renderForm()} -
- ); - } + } +
+ ); } EmailAction.propTypes = { @@ -88,10 +59,4 @@ EmailAction.propTypes = { action: PropTypes.object }; -function mapStateToProps (state) { - return { - profile: state.profile - }; -} - -export default connect(mapStateToProps)(EmailAction); +export default EmailAction;