Skip to content

Commit 5b29fbb

Browse files
committed
UI - add utils for global functions.
format phone numbers
1 parent a0f6db5 commit 5b29fbb

File tree

4 files changed

+44
-27
lines changed

4 files changed

+44
-27
lines changed

src/client/src/pages/Admin.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import Table from '@material-ui/core/Table';
66
import TableBody from '@material-ui/core/TableBody';
77
import TableCell from '@material-ui/core/TableCell';
88
import TableContainer from '@material-ui/core/TableContainer';
9-
import TableHead from '@material-ui/core/TableHead';
109
import TableRow from '@material-ui/core/TableRow';
1110
import { withStyles } from '@material-ui/core/styles';
1211
import LinearProgress from '@material-ui/core/LinearProgress';

src/client/src/pages/DataView360/DataView360.js

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ import {
1717
import CircularProgress from '@material-ui/core/CircularProgress';
1818
import styles from "./styles/DataView360.module.css";
1919
import _ from 'lodash';
20-
2120
import SearchBar from './components/SearchBar';
2221
import ContactInfo from './components/ContactInfo';
2322
import Volunteer from './components/Volunteer';
2423
import Donations from './components/Donations';
2524
import Adoptions from './components/Adoptions';
25+
import {formatPhoneNumber} from "../../utils/utils";
2626

2727

2828
const customStyles = theme => ({
@@ -87,8 +87,8 @@ class DataView360 extends Component {
8787
response = await response.json();
8888

8989
this.setState({
90-
participantData: response.result,
91-
isDataBusy: false,
90+
participantData: response.result,
91+
isDataBusy: false,
9292
showParticipant: true,
9393
showTable: false,
9494
showSearchBar: false
@@ -126,13 +126,13 @@ class DataView360 extends Component {
126126
_.map(participantListGrouped, (row_group, index) => {
127127
return _.map(row_group, (row, idx) => {
128128
return <TableRow key={`${row.source_id}${idx}`}
129-
className={tableRowColors[index % _.size(tableRowColors)]}
130-
onClick={() => this.handleGetParticipant(row.matching_id)}>
129+
className={tableRowColors[index % _.size(tableRowColors)]}
130+
onClick={() => this.handleGetParticipant(row.matching_id)}>
131131
<TableCell align="left">{row.matching_id}</TableCell>
132132
<TableCell align="left">{row.first_name}</TableCell>
133133
<TableCell align="left">{row.last_name}</TableCell>
134134
<TableCell align="left">{row.email}</TableCell>
135-
<TableCell align="left">{row.mobile}</TableCell>
135+
<TableCell align="left">{formatPhoneNumber(row.mobile)}</TableCell>
136136
<TableCell align="left">{row.source_type}</TableCell>
137137
<TableCell align="left">{row.source_id}</TableCell>
138138
</TableRow>
@@ -157,7 +157,7 @@ class DataView360 extends Component {
157157

158158
this.state.participantTable = this.renderParticipantsTable();
159159
this.setState({
160-
isDataBusy: false,
160+
isDataBusy: false,
161161
showParticipant: false,
162162
showTable: true
163163
});
@@ -167,33 +167,37 @@ class DataView360 extends Component {
167167
const {classes} = this.props;
168168
return (
169169
<Container>
170-
{this.state.showSearchBar &&
170+
{this.state.showSearchBar &&
171171
(<SearchBar participant={this.state.participant}
172-
handleParticipantChange={this.handleGetParticipant}
173-
handleSearchChange={this.handleSearchChange}/>
172+
handleParticipantChange={this.handleGetParticipant}
173+
handleSearchChange={this.handleSearchChange}/>
174174
)}
175-
{(_.isEmpty(this.state.participantTable) !== true &&
176-
this.state.isDataBusy !== true &&
177-
this.state.showTable === true &&
178-
this.state.showParticipant === false) && (
175+
{(_.isEmpty(this.state.participantTable) !== true &&
176+
this.state.isDataBusy !== true &&
177+
this.state.showTable === true &&
178+
this.state.showParticipant === false) && (
179179
<Container className={styles.main} elevation={1} style={{"padding": "1em"}}>
180180
{this.state.participantTable}
181181
</Container>
182182
)}
183-
{(_.isEmpty(this.state.participantData) !== true &&
184-
this.state.isDataBusy !== true &&
185-
this.state.showParticipant === true) && (
183+
{(_.isEmpty(this.state.participantData) !== true &&
184+
this.state.isDataBusy !== true &&
185+
this.state.showParticipant === true) && (
186186
<Paper className={styles.main} elevation={1} style={{"padding": "1em"}}>
187187
<ContactInfo participant={_.get(this.state, 'participantData.contact_details')}/>
188-
<Grid container direction="row" justify="center">
189-
<Grid item style={{"marginTop": "1em", "position": "fixed"}}>
190-
<Button variant="contained" color="primary"
191-
onClick={() => {
192-
this.setState({showParticipant: false, showTable: true, showSearchBar: true })
188+
<Grid container direction="row" justify="center">
189+
<Grid item style={{"marginTop": "1em", "position": "fixed"}}>
190+
<Button variant="contained" color="primary"
191+
onClick={() => {
192+
this.setState({
193+
showParticipant: false,
194+
showTable: true,
195+
showSearchBar: true
196+
})
193197
}}>Back to Results
194-
</Button>
195-
</Grid>
198+
</Button>
196199
</Grid>
200+
</Grid>
197201
<Donations donations={_.get(this.state, 'participantData.donations')}/>
198202
<Adoptions adoptions={_.get(this.state, 'participantData.adoptions')}/>
199203
<Volunteer volunteer={_.get(this.state, 'participantData.shifts')}

src/client/src/pages/DataView360/components/ContactInfo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import React, { Component } from 'react';
22
import { Paper, Typography, Container} from '@material-ui/core';
33
import { withStyles } from '@material-ui/core/styles';
44
import styles from "./styles/ContactInfo.module.css";
5-
65
import _ from 'lodash';
6+
import {formatPhoneNumber} from "../../../utils/utils";
77

88
const StyledContact = withStyles((theme)=>({
99
root:{
@@ -42,7 +42,7 @@ class ContactInfo extends Component {
4242
</Typography>
4343
<StyledContact className={styles.contact_info_phone}>
4444
<span>
45-
{phone}
45+
{formatPhoneNumber(phone)}
4646
</span>
4747
</StyledContact>
4848
<Typography className={styles.contact_info_email}>

src/client/src/utils/utils.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
export function formatPhoneNumber(phoneNumberString) {
3+
let retVal;
4+
5+
if(phoneNumberString) {
6+
const match = phoneNumberString.match(/^(\d{3})(\d{3})(\d{4})$/)
7+
8+
if (match) {
9+
retVal = '(' + match[1] + ') ' + match[2] + '-' + match[3];
10+
}
11+
}
12+
13+
return retVal;
14+
}

0 commit comments

Comments
 (0)