-
Notifications
You must be signed in to change notification settings - Fork 125
/
SearchResult.jsx
229 lines (216 loc) · 6.72 KB
/
SearchResult.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
import React, { useState, useEffect, useRef } from 'react';
import PropTypes from 'prop-types';
import {
focusElement,
scrollTo,
} from '@department-of-veterans-affairs/platform-utilities/ui';
import ReportModal from './ReportModal';
import { parsePhoneNumber } from '../../utils/phoneNumbers';
const SearchResult = ({
officer,
addressLine1,
addressLine2,
addressLine3,
city,
stateCode,
zipCode,
phone,
distance,
email,
associatedOrgs,
submitRepresentativeReport,
reports,
representativeId,
query,
setReportModalTester,
}) => {
const [reportModalIsShowing, setReportModalIsShowing] = useState(false);
const prevReportCount = useRef(reports?.length || 0);
const { contact, extension } = parsePhoneNumber(phone);
const addressExists = addressLine1 || city || stateCode || zipCode;
// concatenating address for ReportModal
const address =
[
(addressLine1 || '').trim(),
(addressLine2 || '').trim(),
(addressLine3 || '').trim(),
]
.filter(Boolean)
.join(' ') +
(city ? ` ${city},` : '') +
(stateCode ? ` ${stateCode}` : '') +
(zipCode ? ` ${zipCode}` : '');
const closeReportModal = () => {
setReportModalIsShowing(false);
scrollTo(`#report-button-${representativeId}`);
focusElement(`#report-button-${representativeId}`);
};
useEffect(
() => {
if (reports?.length > prevReportCount) {
scrollTo(`#thank-you-alert-${representativeId}`);
focusElement(`#thank-you-alert-${representativeId}`);
}
},
[reports],
);
return (
<div className="report-outdated-information-modal">
{/* Trigger methods for unit testing - temporary workaround for shadow root issues */}
{setReportModalTester ? (
<button
id="open-modal-test-button"
type="button"
onClick={() => setReportModalIsShowing(true)}
/>
) : null}
{reportModalIsShowing && (
<ReportModal
representativeName={officer}
representativeId={representativeId}
address={address}
phone={phone}
email={email}
existingReports={reports}
onCloseModal={closeReportModal}
submitRepresentativeReport={submitRepresentativeReport}
/>
)}
<div className="vads-u-padding--4 representative-result-card">
<div className="representative-result-card-content">
<div className="representative-info-heading">
{distance && (
<div className="vads-u-font-weight--bold vads-u-font-family--serif">
{parseFloat(JSON.parse(distance).toFixed(2))} Mi
</div>
)}
{officer && (
<>
<div
className="vads-u-font-family--serif vads-u-margin-top--2p5"
id={`result-${representativeId}`}
>
<h3>{officer}</h3>
</div>
{associatedOrgs?.length === 1 && (
<p style={{ marginTop: 0 }}>{associatedOrgs[0]}</p>
)}
</>
)}
</div>
{associatedOrgs?.length > 1 && (
<div className="associated-organizations-info vads-u-margin-top--1p5">
<va-additional-info
trigger="See associated organizations"
disable-border
uswds
>
{associatedOrgs?.map((org, index) => {
return (
<>
<p>{org}</p>
{index < associatedOrgs.length - 1 ? (
<br style={{ lineHeight: '1rem' }} />
) : null}
</>
);
})}
</va-additional-info>
</div>
)}
<div className="representative-contact-section vads-u-margin-top--3">
{addressExists && (
<div className="address-link">
<a
href={`https://maps.google.com?saddr=${
query?.context?.location
}&daddr=${address}`}
tabIndex="0"
target="_blank"
rel="noreferrer"
>
{addressLine1}{' '}
{addressLine2 ? (
<>
<br /> {addressLine2}
</>
) : null}{' '}
<br />
{city}, {stateCode} {zipCode}
</a>
</div>
)}
{phone && (
<div className="vads-u-margin-top--1p5">
<va-telephone contact={contact} extension={extension} />
</div>
)}
{email && (
<div className="vads-u-margin-top--1p5">
<a href={`mailto:${email}`}>{email}</a>
</div>
)}
</div>
{reports && (
<div className="report-thank-you-alert">
<va-alert
class="thank-you-alert vads-u-margin-bottom--2"
close-btn-aria-label="Close notification"
disable-analytics="false"
tabIndex={-1}
full-width="false"
slim
status="info"
uswds
visible="true"
>
<p
id={`thank-you-alert-${representativeId}`}
className="vads-u-margin-y--0"
>
Thanks for reporting outdated information.
</p>
</va-alert>
</div>
)}
<div className="report-outdated-information-button">
<va-button
onClick={() => {
setReportModalIsShowing(true);
}}
tabIndex={-1}
id={`report-button-${representativeId}`}
secondary
text="Report outdated information"
uswds
/>
</div>
</div>
</div>
</div>
);
};
SearchResult.propTypes = {
addressLine1: PropTypes.string,
addressLine2: PropTypes.string,
addressLine3: PropTypes.string,
associatedOrgs: PropTypes.array,
city: PropTypes.string,
distance: PropTypes.string,
email: PropTypes.string,
officer: PropTypes.string,
phone: PropTypes.string,
query: PropTypes.object,
reports: PropTypes.shape({
phone: PropTypes.string,
email: PropTypes.string,
address: PropTypes.string,
other: PropTypes.string,
}),
representativeId: PropTypes.string,
stateCode: PropTypes.string,
submitRepresentativeReport: PropTypes.func,
type: PropTypes.string,
zipCode: PropTypes.string,
};
export default SearchResult;