Skip to content

Commit

Permalink
#35 Add interactive text and website links for hotlines (#51)
Browse files Browse the repository at this point in the history
* Issue #35: Add SMS text field to display for each hotline

* Issue #35: Refactor data structure of text contact info so that texting can be interactive in the future

* Issue #35: Add IconGroup component to display icons for each method of contacting hotlines and link icons to SMS and website URLS

* No linked issue: replace en dash with hyphen in phone number hotline constants

Co-authored-by: jaqarrick <[email protected]>
  • Loading branch information
lizzthabet and jaqarrick authored Dec 28, 2020
1 parent aa34d7d commit 8e4adc2
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 35 deletions.
106 changes: 106 additions & 0 deletions components/IconGroup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import * as Linking from 'expo-linking';
import * as React from 'react';
import { StyleSheet, TouchableOpacity } from 'react-native';

import { View } from './Themed';
import { Styles } from '../constants';
import { Phone, TextMessage, WebLink } from '../svgs';

interface IconGroupProps {
crisis?: boolean;
tel?: string;
text?: { content?: string; number: string; }
website?: string;
}

export const IconGroup:React.FC<IconGroupProps> = ({crisis, tel, text, website}) => {

const LETTER_TO_TELEPHONE_NUMBER: { [key: string]: string } = {
'ABC': '2',
'DEF': '3',
'GHI': '4',
'JKL': '5',
'MNO': '6',
'PQRS': '7',
'TUV': '8',
'WXYZ': '9'
};

const formatTextNumber = (textNumber: string) => {
const letterExp = /[A-Za-z]/g;
const digitExp = /\d/g;
let textNumberWithoutLetters: string = '';

for (let i = 0; i < textNumber.length; i++) {
const character = textNumber[i];
if (character.match(letterExp)) {
// Replace the letter with corresponding number
const [ matchingTelephoneLetters ] =
Object.keys(LETTER_TO_TELEPHONE_NUMBER)
.filter(letterGroups => letterGroups.includes(character.toUpperCase()))
textNumberWithoutLetters += LETTER_TO_TELEPHONE_NUMBER[matchingTelephoneLetters];
} else if (character.match(digitExp)) {
// If not a letter, don't replace with a number
textNumberWithoutLetters += character;
}
}

return textNumberWithoutLetters;
}

return (
<View
darkColor={Styles.black}
lightColor={Styles.white}
style={styles.iconGroup}
>
{tel && <TouchableOpacity
style={[
styles.phoneWrap,
crisis && {backgroundColor: Styles.orange},
]}
onPress={() => Linking.openURL(`tel://${tel}`) }>
<Phone color={Styles.white} />
</TouchableOpacity>}
{text && <TouchableOpacity
style={[
styles.phoneWrap,
crisis && {backgroundColor: Styles.orange},
]}
onPress={() => Linking.openURL(`sms:${formatTextNumber(text.number)}?&body=${encodeURI(text.content || "")}`) }>
<TextMessage color={Styles.white} />
</TouchableOpacity>}
{website && <TouchableOpacity
style={[
styles.phoneWrap,
crisis && {backgroundColor: Styles.orange},
]}
onPress={() => Linking.openURL(website) }>
<WebLink color={Styles.white} />
</TouchableOpacity>}
</View>
)
}

const styles = StyleSheet.create({
iconGroup: {
display:'flex',
flexDirection: 'row',
justifyContent: 'center'
},
phoneWrap: {
alignItems: 'center',
alignSelf: 'center',
backgroundColor: Styles.blue,
borderRadius: 1000,
flex: 1,
flexGrow: 0,
flexBasis: 70,
height: 70,
justifyContent: 'center',
marginLeft: 5,
marginRight: 5,
padding: 20,
width: 70
},
});
1 change: 1 addition & 0 deletions components/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { AddToHomeScreen } from './AddToHomeScreen';
export { IconGroup } from './IconGroup';
export { RowLink } from './RowLink';
export { Text, View } from './Themed';
16 changes: 8 additions & 8 deletions constants/PhoneNumbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type Props = {
is24Hr?: true,
tags?: string[],
tel?: string,
text?: string,
text?: { content?: string; number: string; },
website?: string,
voicemail?: true,
}[];
Expand All @@ -23,7 +23,7 @@ export const PhoneNumbers: Props = {
'Counseling',
'Multilingual',
],
tel: '1-800-6214673',
tel: '1-800-621-4673',
hours: '24 Hour Access',
}, {
display: 'Safe Horizons Citywide General Helpline',
Expand All @@ -50,7 +50,7 @@ export const PhoneNumbers: Props = {
crisis: true,
display: 'National Domestic Violence Hotline',
tel: '1-800-799-7233',
text: 'or text LOVEIS to 1-866-331-9474',
text: { content: 'LOVEIS', number: '1-866-331-9474' },
hours: '24 Hour Access',
}],

Expand All @@ -71,7 +71,7 @@ export const PhoneNumbers: Props = {
'Outpatient Detox',
],
tel: '1-888-692-9355',
text: 'or text WELL to 65173',
text: { content: 'WELL', number: '65173' },
}, {
display: 'NY State Emotional Support Helpline',
tags: ['Anxiety', 'Counseling', 'COVID-19'],
Expand All @@ -81,14 +81,14 @@ export const PhoneNumbers: Props = {
// display: 'NYS/Crisis Text Line Partnership',
// hours: '24 Hour Access',
// tags: ['Crisis', 'Counseling', 'COVID-19'],
// text: 'Text GOT5 to 741741',
// text: { content: 'GOT5', number: '741741' },
// },
{
display: 'SAMHSA Disaster Distress National Helpline',
hours: '24 Hour Access',
tags: ['Post-Disaster', 'Crisis', 'Emotional Distress', 'Trauma', 'COVID-19', 'Unrest', 'Spanish'],
tel: '1-800-985-5990',
text: 'or text TalkWithUs or Hablanos to 66746',
text: {content: 'TalkWithUs or Hablanos', number: '66746'},
website: 'https://www.samhsa.gov/find-help/disaster-distress-helpline',
}],

Expand Down Expand Up @@ -197,7 +197,7 @@ export const PhoneNumbers: Props = {
'Outpatient Detox',
],
tel: '1-888-692-9355',
text: 'or text WELL to 65173',
text: {content: 'WELL', number: '65173'},
}, {
display: 'New York State Office of Addiction Services and Supports HOPEline',
hours: '24 Hour Access',
Expand All @@ -209,6 +209,6 @@ export const PhoneNumbers: Props = {
'Multilingual support',
],
tel: '1-877-846-7369',
text: 'or text HOPENY',
text: {number: 'HOPENY'}, // TODO (JC): Make sure that this letter phone number format works properly
}],
};
52 changes: 25 additions & 27 deletions screens/PhoneNumberListScreen/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import * as Linking from 'expo-linking';
import * as React from 'react';
import { ScrollView, StyleSheet, TouchableOpacity } from 'react-native';
import { ScrollView, StyleSheet } from 'react-native';

import { Text, View } from '../../components';
import { Text, View, IconGroup } from '../../components';
import { PhoneNumbers } from '../../constants';
import { Styles } from '../../constants';
import { Caret, Phone } from '../../svgs';
import { Caret } from '../../svgs';
import { Props } from './types';

/**
* @description This component renders the PhoneNumber Screen
* ie, any phone number list we pass into it basically
Expand All @@ -26,6 +24,22 @@ export const PhoneNumberListScreen = (props: Props) => {
return 1;
});

const formatTextInfo = (textInfo: { content?: string; number: string }) => {
if (textInfo === undefined) {
return '';
}

let displayInfo: string = 'or text';

if (textInfo.content) {
displayInfo += ` ${textInfo.content} to`;
}

displayInfo += ` ${textInfo.number}`;

return displayInfo;
}

return (
<View
darkColor={Styles.black}
Expand Down Expand Up @@ -71,18 +85,13 @@ export const PhoneNumberListScreen = (props: Props) => {
<Text
darkColor={Styles.white}
style={[styles.centerTxt, styles.tel]}>
{entry.tel}
{entry.tel} {formatTextInfo(entry.text)}
</Text>
<TouchableOpacity
style={[
styles.phoneWrap,
entry.crisis && {backgroundColor: Styles.orange},
]}
onPress={() => {
Linking.openURL(`tel://${entry.tel}`);
}}>
<Phone color={Styles.white} />
</TouchableOpacity>
<IconGroup
crisis={entry.crisis}
tel={entry.tel}
text={entry.text}
website={entry.website} />
</View>
))}
</ScrollView>
Expand Down Expand Up @@ -134,17 +143,6 @@ const styles = StyleSheet.create({
fontSize: 18,
paddingBottom: 5,
},
phoneWrap: {
alignItems: 'center',
alignSelf: 'center',
backgroundColor: Styles.blue,
borderRadius: 1000,
flex: 1,
height: 70,
justifyContent: 'center',
padding: 20,
width: 70,
},
tel: {
marginBottom: 15,
},
Expand Down
10 changes: 10 additions & 0 deletions svgs/TextMessage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React, { memo } from 'react';
import Svg, { Path } from 'react-native-svg';

export const TextMessage = memo((props: React.SVGProps<SVGSVGElement>) => (
// @ts-ignore
<Svg width={32} height={31} viewBox="0 0 16 16" fill={props.color} {...props}>
<Path fillRule="evenodd" d="M2 1h12a1 1 0 0 1 1 1v11.586l-2-2A2 2 0 0 0 11.586 11H2a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1zm12-1a2 2 0 0 1 2 2v12.793a.5.5 0 0 1-.854.353l-2.853-2.853a1 1 0 0 0-.707-.293H2a2 2 0 0 1-2-2V2a2 2 0 0 1 2-2h12z"/>
<Path fillRule="evenodd" d="M3 3.5a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9a.5.5 0 0 1-.5-.5zM3 6a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9A.5.5 0 0 1 3 6zm0 2.5a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5z"/>
</Svg>
));
11 changes: 11 additions & 0 deletions svgs/WebLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React, { memo } from 'react';
import Svg, { Path } from 'react-native-svg';

export const WebLink = memo((props: React.SVGProps<SVGSVGElement>) => (
// @ts-ignore
<Svg width={32} height={31} viewBox="0 0 16 16" fill={props.color} {...props}>
<Path d="M4.715 6.542L3.343 7.914a3 3 0 1 0 4.243 4.243l1.828-1.829A3 3 0 0 0 8.586 5.5L8 6.086a1.001 1.001 0 0 0-.154.199 2 2 0 0 1 .861 3.337L6.88 11.45a2 2 0 1 1-2.83-2.83l.793-.792a4.018 4.018 0 0 1-.128-1.287z"/>
<Path d="M6.586 4.672A3 3 0 0 0 7.414 9.5l.775-.776a2 2 0 0 1-.896-3.346L9.12 3.55a2 2 0 0 1 2.83 2.83l-.793.792c.112.42.155.855.128 1.287l1.372-1.372a3 3 0 0 0-4.243-4.243L6.586 4.672z"/>
</Svg>
));

2 changes: 2 additions & 0 deletions svgs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ export { Hand } from './Hand';
export { Homelessness } from './Homelessness';
export { Home } from './Home';
export { Legal } from './Legal';
export { WebLink } from './WebLink';
export { Logo } from './Logo';
export { MentalHealth } from './MentalHealth';
export { Noise } from './Noise';
export { Not911 } from './Not911';
export { Phone } from './Phone';
export { Poison } from './Poison';
export { Settings } from './Settings';
export { TextMessage } from './TextMessage';
export { Violence } from './Violence';

0 comments on commit 8e4adc2

Please sign in to comment.