Skip to content

Commit

Permalink
Merge pull request #1198 from zetkin/enhancement/full-join-sub-data
Browse files Browse the repository at this point in the history
More information in JoinSubmissionPane
  • Loading branch information
richardolsson authored Dec 7, 2020
2 parents 3f58e33 + 747b70c commit fab0f45
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 23 deletions.
12 changes: 12 additions & 0 deletions locale/misc/fields/en.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
alt_phone: Alt. phone number
city: City
co_address: C/O address
country: Country
email: E-mail
ext_id: External ID
first_name: First name
gender: Gender
last_name: Last name
phone: Phone number
street_address: Street address
zip: Zip code
2 changes: 2 additions & 0 deletions locale/panes/joinSubmission/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ action:
acceptButton: Accept
h: Request pending
p: Click Accept to add {person} to your database.
data:
h: Data submitted
meta:
h: Meta-data
state:
Expand Down
104 changes: 81 additions & 23 deletions src/components/panes/JoinSubmissionPane.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,46 @@ import Button from '../misc/Button';
import LoadingIndicator from '../misc/LoadingIndicator';
import PaneBase from './PaneBase';
import { getListItemById } from '../../utils/store';
import { retrieveFieldTypesForOrganization } from '../../actions/personField';
import {
acceptJoinSubmission,
retrieveJoinForm,
retrieveJoinSubmission,
} from '../../actions/joinForm';
import InfoList from '../misc/InfoList';


const ADDR_FIELDS = [ 'co_address', 'street_address', 'zip_code', 'city', 'country' ];

const mapStateToProps = (state, props) => ({
subItem: getListItemById(state.joinForms.submissionList,
props.paneData.params[0]),
});
const NATIVE_FIELDS = [
'ext_id',
'first_name',
'last_name',
'email',
'phone',
'alt_phone',
'co_address',
'street_address',
'zip_code',
'city',
'country',
];


const mapStateToProps = (state, props) => {
const subItem = getListItemById(state.joinForms.submissionList,
props.paneData.params[0]);

if (subItem) {
return {
fieldTypes: state.personFields.fieldTypes,
formItem: getListItemById(state.joinForms.formList,
subItem.data.form.id),
subItem: subItem,
}
}
else {
return {};
}
};

@connect(mapStateToProps)
@injectIntl
Expand All @@ -34,6 +61,17 @@ export default class JoinSubmissionPane extends PaneBase {

const subId = this.getParam(0);
this.props.dispatch(retrieveJoinSubmission(subId));
this.props.dispatch(retrieveFieldTypesForOrganization());

if (this.props.subItem && this.props.subItem.data && !this.props.formItem) {
this.props.dispatch(retrieveJoinForm(this.props.subItem.data.form.id));
}
}

componentDidUpdate() {
if (this.props.subItem && this.props.subItem.data && !this.props.formItem) {
this.props.dispatch(retrieveJoinForm(this.props.subItem.data.form.id));
}
}

getPaneTitle() {
Expand All @@ -52,20 +90,12 @@ export default class JoinSubmissionPane extends PaneBase {
}

renderPaneContent() {
const { subItem } = this.props;
const { formItem, fieldTypes, subItem } = this.props;

if (subItem) {
if (formItem && fieldTypes && subItem) {
const state = subItem.data.state;
const person = subItem.data.person_data;

let addrFields = ADDR_FIELDS.filter(f => person[f]).map(field => (
<span key={ field } className="JoinSubmissionPane-infoValue">
{ person[field] }
</span>
));

const phoneNumbers = [ person.phone, person.alt_phone ].filter(pn => !!pn);

let actionContent = null;
let actionButton = null;
if (state == 'accepted') {
Expand Down Expand Up @@ -100,14 +130,41 @@ export default class JoinSubmissionPane extends PaneBase {
);
}

const dataSection = (state == 'pending')? (
<div key="data">
<Msg tagName="h3" id="panes.joinSubmission.data.h"/>
<ul className="JoinSubmissionPane-personData">
{this.props.formItem.data.fields.map(fieldName => {
let label;

const fieldItem = this.props.fieldTypes.items.find(item => item.data.slug == fieldName);

// Exclude JSON fields
if (fieldItem) {
if (fieldItem.data.type == 'json') {
return null;
}

label = fieldItem.data.title;
}
else if (NATIVE_FIELDS.includes(fieldName)) {
label = this.props.intl.formatMessage({ id: `misc.fields.${fieldName}` });
}

const value = person[fieldName];

return (
<li key={ fieldName }>
<span className="JoinSubmissionPane-fieldLabel">{ label }</span>
<span className="JoinSubmissionPane-fieldValue">{ value.toString() } </span>
</li>
);
})}
</ul>
</div>
) : null;

return [
<InfoList key="info"
data={[
{ name: 'email', value: person.email },
{ name: 'phone', value: phoneNumbers.join(', ') },
{ name: 'address', value: addrFields.length? addrFields : null },
]}
/>,
<div key="meta">
<Msg tagName="h3" id="panes.joinSubmission.meta.h"/>
<InfoList
Expand All @@ -121,6 +178,7 @@ export default class JoinSubmissionPane extends PaneBase {
]}
/>
</div>,
dataSection,
<ActionBox key="action"
status={ state == 'accepted'? 'done' : 'warning' }
headerMsg={ `panes.joinSubmission.action.${state}.h` }
Expand Down
32 changes: 32 additions & 0 deletions src/components/panes/JoinSubmissionPane.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,38 @@
@include inline-button($icon: $fa-var-check);
}
}

.InfoList {
.InfoListItem-form:before {
@include icon($fa-var-list);
}

.InfoListItem-submitted:before {
@include icon($fa-var-clock-o);
}

.InfoListItem-state:before {
@include icon($fa-var-check);
}
}
}

.JoinSubmissionPane-personData {
border-bottom: 1px solid darken($c-ui-bg, 10);
padding-bottom: 1em;

li {
margin-bottom: 0.5em;
}

.JoinSubmissionPane-fieldLabel {
display: block;
}

.JoinSubmissionPane-fieldValue {
font-size: 1.4em;
display: block;
}
}

.JoinSubmissionPane-person {
Expand Down

0 comments on commit fab0f45

Please sign in to comment.