54 lines
1.2 KiB
TypeScript
54 lines
1.2 KiB
TypeScript
import { Linking, Platform } from 'react-native';
|
|
|
|
export const handleEmailPress = (email?: string | null) => {
|
|
if (!email) {
|
|
console.warn('No email provided');
|
|
return;
|
|
}
|
|
|
|
Linking.openURL(`mailto:${email}`).catch(err =>
|
|
console.error('Error opening email:', err),
|
|
);
|
|
};
|
|
|
|
export const handlePhonePress = (phoneNumber?: string | null) => {
|
|
if (!phoneNumber) {
|
|
console.warn('No phone number provided');
|
|
return;
|
|
}
|
|
|
|
const phoneUrl =
|
|
Platform.OS === 'ios'
|
|
? `telprompt:${phoneNumber}`
|
|
: `tel:${phoneNumber}`;
|
|
|
|
Linking.openURL(phoneUrl).catch(err =>
|
|
console.error('Error opening phone:', err),
|
|
);
|
|
};
|
|
|
|
export const handleWebsitePress = (website?: string | null) => {
|
|
if (!website) {
|
|
console.warn('No website provided');
|
|
return;
|
|
}
|
|
|
|
const url = website.startsWith('http') ? website : `https://${website}`;
|
|
|
|
Linking.openURL(url).catch(err =>
|
|
console.error('Error opening website:', err),
|
|
);
|
|
};
|
|
|
|
export const getInitials = (name?: string | null): string => {
|
|
if (!name) return '?';
|
|
|
|
const nameParts = name.trim().split(' ');
|
|
|
|
if (nameParts.length >= 2) {
|
|
return (nameParts[0][0] + nameParts[nameParts.length - 1][0]).toUpperCase();
|
|
}
|
|
|
|
return name.substring(0, 2).toUpperCase();
|
|
};
|