-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.`.
- Loading branch information
1 parent
6306203
commit a141b22
Showing
1 changed file
with
20 additions
and
21 deletions.
There are no files selected for viewing
41 changes: 20 additions & 21 deletions
41
src/modules/lists/components/ActionStatusMessage/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <a href='https://www.lib.umich.edu/ask-librarian'>Ask a Librarian</a> for help."; | ||
let alertType = 'warning'; | ||
let alertMessage = "We're sorry. Something went wrong. Please use <a href='https://www.lib.umich.edu/ask-librarian'>Ask a Librarian</a> 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. [email protected])'; | ||
} | ||
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 ( | ||
<Alert type={alertType} className='u-margin-top-1'> | ||
<span dangerouslySetInnerHTML={{ __html: alertMessage }} /> | ||
</Alert> | ||
); | ||
} | ||
|
||
return ( | ||
<div className={'alert alert-inner alert--' + alertType}> | ||
<span dangerouslySetInnerHTML={{ __html: alertMessage }} /> | ||
</div> | ||
); | ||
} | ||
|
||
ActionStatusMessage.propTypes = { | ||
|