From a141b22dfd8e6020a095ab6f94ad413fc4e1ae8d Mon Sep 17 00:00:00 2001 From: "Erin E. Sullivan" Date: Wed, 6 Sep 2023 07:44:09 -0400 Subject: [PATCH] Converting to a functional component. - Adding a check to see if `status.status_code` exists. - Adding a check to see if `status.status_code` starts with `action.response.`. --- .../components/ActionStatusMessage/index.js | 41 +++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/modules/lists/components/ActionStatusMessage/index.js b/src/modules/lists/components/ActionStatusMessage/index.js index 978cbe62c..10547ab68 100644 --- a/src/modules/lists/components/ActionStatusMessage/index.js +++ b/src/modules/lists/components/ActionStatusMessage/index.js @@ -1,39 +1,38 @@ -import React, { Component } from 'react'; -import { Alert } from '../../../reusable'; +import React from 'react'; import PropTypes from 'prop-types'; -class ActionStatusMessage extends Component { - render () { - const { status, action } = this.props; +function ActionStatusMessage (props) { + const { status, action } = props; - if (!status) { - return null; - } + if (!status) { + return null; + } - let alertType = 'warning'; - let alertMessage = "We're sorry. Something went wrong. Please use Ask a Librarian for help."; + let alertType = 'warning'; + let alertMessage = "We're sorry. Something went wrong. Please use Ask a Librarian for help."; - if (status.status_code === 'action.response.success') { + if (status.status_code?.startsWith('action.response.')) { + const statusCode = status.status_code; + if (statusCode.endsWith('success')) { alertType = 'success'; alertMessage = `${action.name} successfully sent.`; } - - if (status.status_code.startsWith('action.response.invalid.')) { + if (statusCode.includes('invalid.')) { alertType = 'error'; - if (status.status_code.endsWith('email')) { + if (statusCode.endsWith('email')) { alertMessage = 'Please enter a valid email address (e.g. uniqname@umich.edu)'; } - if (status.status_code.endsWith('number')) { + if (statusCode.endsWith('number')) { alertMessage = 'Please enter a valid 10-digit phone number (e.g. 000-123-5555)'; } } - - return ( - - - - ); } + + return ( +
+ +
+ ); } ActionStatusMessage.propTypes = {