Wire up all contact behaviors, refactor Contact type/selector

This commit is contained in:
Scott Nonnenberg 2018-05-04 18:19:54 -07:00
parent 41be7f126b
commit 37821e5a1b
13 changed files with 198 additions and 192 deletions

View file

@ -1,5 +1,13 @@
import React from 'react';
import {
Contact,
ContactType,
AddressType,
Phone,
Email,
PostalAddress,
} from '../../types/Contact';
import { missingCaseError } from '../../util/missingCaseError';
type Localizer = (key: string, values?: Array<string>) => string;
@ -11,70 +19,6 @@ interface Props {
onSendMessage: () => void;
}
interface Contact {
name: Name;
number?: Array<Phone>;
email?: Array<Email>;
address?: Array<PostalAddress>;
avatar?: Avatar;
organization?: string;
}
interface Name {
givenName?: string;
familyName?: string;
prefix?: string;
suffix?: string;
middleName?: string;
displayName: string;
}
enum ContactType {
HOME = 1,
MOBILE = 2,
WORK = 3,
CUSTOM = 4,
}
enum AddressType {
HOME = 1,
WORK = 2,
CUSTOM = 3,
}
interface Phone {
value: string;
type: ContactType;
label?: string;
}
interface Email {
value: string;
type: ContactType;
label?: string;
}
interface PostalAddress {
type: AddressType;
label?: string;
street?: string;
pobox?: string;
neighborhood?: string;
city?: string;
region?: string;
postcode?: string;
country?: string;
}
interface Avatar {
avatar: Attachment;
isProfile: boolean;
}
interface Attachment {
path: string;
}
function getLabelForContactMethod(method: Phone | Email, i18n: Localizer) {
switch (method.type) {
case ContactType.CUSTOM:

View file

@ -1,4 +1,5 @@
import React from 'react';
import { Contact } from '../../types/Contact';
interface Props {
contact: Contact;
@ -8,70 +9,6 @@ interface Props {
onOpenContact: () => void;
}
interface Contact {
name: Name;
number?: Array<Phone>;
email?: Array<Email>;
address?: Array<PostalAddress>;
avatar?: Avatar;
organization?: string;
}
interface Name {
givenName?: string;
familyName?: string;
prefix?: string;
suffix?: string;
middleName?: string;
displayName: string;
}
enum ContactType {
HOME = 1,
MOBILE = 2,
WORK = 3,
CUSTOM = 4,
}
enum AddressType {
HOME = 1,
WORK = 2,
CUSTOM = 3,
}
interface Phone {
value: string;
type: ContactType;
label?: string;
}
interface Email {
value: string;
type: ContactType;
label?: string;
}
interface PostalAddress {
type: AddressType;
label?: string;
street?: string;
pobox?: string;
neighborhood?: string;
city?: string;
region?: string;
postcode?: string;
country?: string;
}
interface Avatar {
avatar: Attachment;
isProfile: boolean;
}
interface Attachment {
path: string;
}
function getInitials(name: string): string {
return name.trim()[0] || '#';
}