-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1157 from rdmorganiser/interview-contact-modal
feat(interview): Contact modal [4]
- Loading branch information
Showing
27 changed files
with
678 additions
and
17 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
textarea { | ||
resize: vertical; | ||
} |
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
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
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
84 changes: 84 additions & 0 deletions
84
rdmo/projects/assets/js/interview/actions/contactActions.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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import ContactApi from '../api/ContactApi' | ||
|
||
import { projectId } from '../utils/meta' | ||
|
||
import { | ||
FETCH_CONTACT_INIT, | ||
FETCH_CONTACT_SUCCESS, | ||
FETCH_CONTACT_ERROR, | ||
SEND_CONTACT_INIT, | ||
SEND_CONTACT_SUCCESS, | ||
SEND_CONTACT_ERROR, | ||
CLOSE_CONTACT | ||
} from './actionTypes' | ||
|
||
import { addToPending, removeFromPending } from 'rdmo/core/assets/js/actions/pendingActions' | ||
|
||
export function fetchContact({ questionset, question, values }) { | ||
const pendingId = 'fetchContact' | ||
|
||
return (dispatch, getState) => { | ||
const params = { | ||
page: getState().interview.page.id, | ||
questionset: questionset && questionset.id, | ||
question: question && question.id, | ||
values: values.filter(value => value.id).map(value => value.id) | ||
} | ||
|
||
dispatch(addToPending(pendingId)) | ||
dispatch(fetchContactInit()) | ||
|
||
return ContactApi.fetchContact(projectId, params).then((values) => { | ||
dispatch(removeFromPending(pendingId)) | ||
dispatch(fetchContactSuccess(values)) | ||
}).catch((error) => { | ||
dispatch(removeFromPending(pendingId)) | ||
dispatch(fetchContactError(error)) | ||
}) | ||
} | ||
} | ||
|
||
export function fetchContactInit() { | ||
return {type: FETCH_CONTACT_INIT} | ||
} | ||
|
||
export function fetchContactSuccess(values) { | ||
return {type: FETCH_CONTACT_SUCCESS, values} | ||
} | ||
|
||
export function fetchContactError(error) { | ||
return {type: FETCH_CONTACT_ERROR, error} | ||
} | ||
|
||
export function sendContact(values) { | ||
const pendingId = 'sendContact' | ||
|
||
return (dispatch) => { | ||
dispatch(addToPending(pendingId)) | ||
dispatch(sendContactInit()) | ||
|
||
return ContactApi.sendContact(projectId, values).then(() => { | ||
dispatch(removeFromPending(pendingId)) | ||
dispatch(sendContactSuccess()) | ||
}).catch((error) => { | ||
dispatch(removeFromPending(pendingId)) | ||
dispatch(sendContactError(error)) | ||
}) | ||
} | ||
} | ||
|
||
export function sendContactInit() { | ||
return {type: SEND_CONTACT_INIT} | ||
} | ||
|
||
export function sendContactSuccess() { | ||
return {type: SEND_CONTACT_SUCCESS} | ||
} | ||
|
||
export function sendContactError(error) { | ||
return {type: SEND_CONTACT_ERROR, error} | ||
} | ||
|
||
export function closeContact() { | ||
return {type: CLOSE_CONTACT} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { encodeParams } from 'rdmo/core/assets/js/utils/api' | ||
|
||
import BaseApi from 'rdmo/core/assets/js/api/BaseApi' | ||
|
||
class ContactApi extends BaseApi { | ||
|
||
static fetchContact(projectId, params) { | ||
return this.get(`/api/v1/projects/projects/${projectId}/contact/?${encodeParams(params)}`) | ||
} | ||
|
||
static sendContact(projectId, data) { | ||
return this.post(`/api/v1/projects/projects/${projectId}/contact/`, data) | ||
} | ||
|
||
} | ||
|
||
export default ContactApi |
82 changes: 82 additions & 0 deletions
82
rdmo/projects/assets/js/interview/components/main/Contact.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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import React, { useState, useEffect } from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
import Modal from 'rdmo/core/assets/js/components/Modal' | ||
|
||
import Html from 'rdmo/core/assets/js/components/Html' | ||
|
||
const Contact = ({ templates, contact, sendContact, closeContact }) => { | ||
const { showModal, values: initialValues, errors } = contact | ||
|
||
const [values, setValues] = useState({}) | ||
|
||
useEffect(() => setValues(initialValues), [initialValues]) | ||
|
||
const onSubmit = (event) => { | ||
event.preventDefault() | ||
sendContact(values) | ||
} | ||
|
||
const onClose = () => closeContact() | ||
|
||
return ( | ||
<> | ||
<Modal | ||
show={showModal} | ||
title={gettext('Contact support')} | ||
submitLabel={gettext('Send message')} | ||
onSubmit={onSubmit} | ||
onClose={onClose} | ||
modalProps={{ | ||
bsSize: 'lg' | ||
}}> | ||
<Html html={templates.project_interview_contact_help} /> | ||
<form onSubmit={onSubmit}> | ||
<div className="form-group"> | ||
<label htmlFor="interview-question-contact-subject">Subject</label> | ||
<input | ||
type="text" | ||
id="interview-question-contact-subject" | ||
className="form-control" | ||
value={values.subject || ''} | ||
onChange={event => setValues({ ...values, subject: event.target.value })} | ||
/> | ||
<ul className="help-block list-unstyled"> | ||
{ | ||
errors && errors.subject && errors.subject.map((error, errorIndex) => ( | ||
<li key={errorIndex} className="text-danger">{errors.subject}</li> | ||
)) | ||
} | ||
</ul> | ||
</div> | ||
<div className="form-group"> | ||
<label htmlFor="interview-question-contact-message">Message</label> | ||
<textarea | ||
rows="12" | ||
id="interview-question-contact-message" | ||
className="form-control" | ||
value={values.message || ''} | ||
onChange={event => setValues({...values, message: event.target.value })} | ||
/> | ||
<ul className="help-block list-unstyled"> | ||
{ | ||
errors && errors.message && errors.message.map((error, errorIndex) => ( | ||
<li key={errorIndex} className="text-danger">{errors.message}</li> | ||
)) | ||
} | ||
</ul> | ||
</div> | ||
</form> | ||
</Modal> | ||
</> | ||
) | ||
} | ||
|
||
Contact.propTypes = { | ||
templates: PropTypes.object.isRequired, | ||
contact: PropTypes.object.isRequired, | ||
sendContact: PropTypes.func.isRequired, | ||
closeContact: PropTypes.func.isRequired | ||
} | ||
|
||
export default Contact |
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
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
20 changes: 20 additions & 0 deletions
20
rdmo/projects/assets/js/interview/components/main/question/QuestionContact.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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
const QuestionContact = ({ settings, question, values, fetchContact }) => { | ||
return settings.project_contact && ( | ||
<button className="btn btn-link btn-contact" title={gettext('Contact support.')} | ||
onClick={() => fetchContact({ question, values })}> | ||
<i className="fa fa-commenting-o" aria-hidden="true"></i> | ||
</button> | ||
) | ||
} | ||
|
||
QuestionContact.propTypes = { | ||
settings: PropTypes.object.isRequired, | ||
question: PropTypes.object.isRequired, | ||
values: PropTypes.array.isRequired, | ||
fetchContact: PropTypes.func.isRequired, | ||
} | ||
|
||
export default QuestionContact |
Oops, something went wrong.