Fall back on givenName/familyName if no displayName/organization

This commit is contained in:
Scott Nonnenberg 2018-05-08 16:53:18 -07:00
parent eafa038ba4
commit 8cb1f1f532
3 changed files with 111 additions and 2 deletions

View file

@ -17,7 +17,7 @@ interface Name {
prefix?: string;
suffix?: string;
middleName?: string;
displayName: string;
displayName?: string;
}
export enum ContactType {
@ -101,5 +101,11 @@ export function contactSelector(
export function getName(contact: Contact): string | null {
const { name, organization } = contact;
return (name && name.displayName) || organization || null;
const displayName = (name && name.displayName) || null;
const givenName = (name && name.givenName) || null;
const familyName = (name && name.familyName) || null;
const backupName =
(givenName && familyName && `${givenName} ${familyName}`) || null;
return displayName || organization || backupName || givenName || familyName;
}