Skip to content

Commit 251ebe0

Browse files
committed
fix optional chaining
1 parent e915062 commit 251ebe0

4 files changed

Lines changed: 89 additions & 111 deletions

File tree

src/components/Contacts/ContactDetails/ContactDetailsHeader/ContactHeaderSection/ContactHeaderAddressSection.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ export const ContactHeaderAddressSection = ({
3232
}: Props): ReactElement => {
3333
const { t } = useTranslation();
3434

35+
const greeting = contact?.greeting;
36+
const primaryAddress = contact?.primaryAddress;
37+
3538
if (loading) {
3639
return (
3740
<ContactHeaderSection icon={<LocationIcon />}>
@@ -40,13 +43,10 @@ export const ContactHeaderAddressSection = ({
4043
<TextSkeleton variant="text" />
4144
</ContactHeaderSection>
4245
);
43-
} else if (contact && contact.primaryAddress) {
44-
const {
45-
greeting,
46-
primaryAddress: { street, city, state, postalCode },
47-
} = contact;
46+
} else if (greeting && primaryAddress) {
47+
const { street, city, state, postalCode } = primaryAddress;
4848

49-
if (!!greeting && !!street && !!city && !!state && !!postalCode) {
49+
if (street && city && state && postalCode) {
5050
return (
5151
<ContactHeaderSection icon={<LocationIcon />}>
5252
<Typography variant="subtitle1">{greeting}</Typography>

src/components/Contacts/ContactDetails/ContactDetailsHeader/ContactHeaderSection/ContactHeaderEmailSection.tsx

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,20 @@ export const ContactHeaderEmailSection = ({
2929
loading,
3030
contact,
3131
}: Props): ReactElement => {
32+
const email = contact?.primaryPerson?.primaryEmailAddress?.email;
33+
3234
if (loading) {
3335
return (
3436
<ContactHeaderSection icon={<EmailIcon />}>
3537
<TextSkeleton variant="text" />
3638
</ContactHeaderSection>
3739
);
38-
} else if (
39-
contact &&
40-
contact.primaryPerson &&
41-
contact.primaryPerson.primaryEmailAddress
42-
) {
43-
const {
44-
primaryPerson: {
45-
primaryEmailAddress: { email },
46-
},
47-
} = contact;
48-
49-
if (!!email) {
50-
return (
51-
<ContactHeaderSection icon={<EmailIcon />}>
52-
<Typography variant="subtitle1">{email}</Typography>
53-
</ContactHeaderSection>
54-
);
55-
}
40+
} else if (email) {
41+
return (
42+
<ContactHeaderSection icon={<EmailIcon />}>
43+
<Typography variant="subtitle1">{email}</Typography>
44+
</ContactHeaderSection>
45+
);
5646
}
5747

5848
return <ContactHeaderSection icon={<EmailIcon />} />;

src/components/Contacts/ContactDetails/ContactDetailsHeader/ContactHeaderSection/ContactHeaderPhoneSection.tsx

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,20 @@ export const ContactHeaderPhoneSection = ({
2929
loading,
3030
contact,
3131
}: Props): ReactElement => {
32+
const number = contact?.primaryPerson?.primaryPhoneNumber?.number;
33+
3234
if (loading) {
3335
return (
3436
<ContactHeaderSection icon={<PhoneIcon />}>
3537
<TextSkeleton variant="text" />
3638
</ContactHeaderSection>
3739
);
38-
} else if (
39-
contact &&
40-
contact.primaryPerson &&
41-
contact.primaryPerson.primaryPhoneNumber
42-
) {
43-
const {
44-
primaryPerson: {
45-
primaryPhoneNumber: { number },
46-
},
47-
} = contact;
48-
49-
if (!!number) {
50-
return (
51-
<ContactHeaderSection icon={<PhoneIcon />}>
52-
<Typography variant="subtitle1">{number}</Typography>
53-
</ContactHeaderSection>
54-
);
55-
}
40+
} else if (number) {
41+
return (
42+
<ContactHeaderSection icon={<PhoneIcon />}>
43+
<Typography variant="subtitle1">{number}</Typography>
44+
</ContactHeaderSection>
45+
);
5646
}
5747

5848
return <ContactHeaderSection icon={<PhoneIcon />} />;

src/components/Contacts/ContactDetails/ContactDetailsHeader/ContactHeaderSection/ContactHeaderStatusSection.tsx

Lines changed: 67 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -25,82 +25,80 @@ export const ContactHeaderStatusSection = ({
2525
}: Props): ReactElement => {
2626
const { t } = useTranslation();
2727

28+
const status = contact?.status;
29+
2830
if (loading) {
2931
return (
3032
<ContactHeaderSection icon={<HandshakeIcon />}>
3133
<TextSkeleton variant="text" />
3234
</ContactHeaderSection>
3335
);
34-
} else if (contact) {
35-
const { status } = contact;
36-
37-
if (!!status) {
38-
let statusText = '';
39-
40-
switch (status) {
41-
case 'NEVER_CONTACTED':
42-
statusText = t('Never Contacted');
43-
break;
44-
45-
case 'ASK_IN_FUTURE':
46-
statusText = t('Ask in Future');
47-
break;
48-
49-
case 'CULTIVATE_RELATIONSHIP':
50-
statusText = t('Cultivate Relationship');
51-
break;
52-
53-
case 'CONTACT_FOR_APPOINTMENT':
54-
statusText = t('Contact for Appointment');
55-
break;
56-
57-
case 'APPOINTMENT_SCHEDULED':
58-
statusText = t('Appointment Scheduled');
59-
break;
60-
61-
case 'CALL_FOR_DECISION':
62-
statusText = t('Call for Decision');
63-
break;
64-
65-
case 'PARTNER_FINANCIAL':
66-
statusText = t('Partner - Financial');
67-
break;
68-
69-
case 'PARTNER_SPECIAL':
70-
statusText = t('Partner - Special');
71-
break;
72-
73-
case 'PARTNER_PRAY':
74-
statusText = t('Partner - Prayer');
75-
break;
76-
77-
case 'NOT_INTERESTED':
78-
statusText = t('Not Interested');
79-
break;
80-
81-
case 'UNRESPONSIVE':
82-
statusText = t('Unresponsive');
83-
break;
84-
85-
case 'NEVER_ASK':
86-
statusText = t('Never Ask');
87-
break;
88-
89-
case 'RESEARCH_ABANDONED':
90-
statusText = t('Research Abandoned');
91-
break;
92-
93-
case 'EXPIRED_REFERRAL':
94-
statusText = t('Expired Referral');
95-
break;
96-
}
97-
98-
return (
99-
<ContactHeaderSection icon={<HandshakeIcon />}>
100-
<Typography variant="subtitle1">{statusText}</Typography>
101-
</ContactHeaderSection>
102-
);
36+
} else if (status) {
37+
let statusText = '';
38+
39+
switch (status) {
40+
case 'NEVER_CONTACTED':
41+
statusText = t('Never Contacted');
42+
break;
43+
44+
case 'ASK_IN_FUTURE':
45+
statusText = t('Ask in Future');
46+
break;
47+
48+
case 'CULTIVATE_RELATIONSHIP':
49+
statusText = t('Cultivate Relationship');
50+
break;
51+
52+
case 'CONTACT_FOR_APPOINTMENT':
53+
statusText = t('Contact for Appointment');
54+
break;
55+
56+
case 'APPOINTMENT_SCHEDULED':
57+
statusText = t('Appointment Scheduled');
58+
break;
59+
60+
case 'CALL_FOR_DECISION':
61+
statusText = t('Call for Decision');
62+
break;
63+
64+
case 'PARTNER_FINANCIAL':
65+
statusText = t('Partner - Financial');
66+
break;
67+
68+
case 'PARTNER_SPECIAL':
69+
statusText = t('Partner - Special');
70+
break;
71+
72+
case 'PARTNER_PRAY':
73+
statusText = t('Partner - Prayer');
74+
break;
75+
76+
case 'NOT_INTERESTED':
77+
statusText = t('Not Interested');
78+
break;
79+
80+
case 'UNRESPONSIVE':
81+
statusText = t('Unresponsive');
82+
break;
83+
84+
case 'NEVER_ASK':
85+
statusText = t('Never Ask');
86+
break;
87+
88+
case 'RESEARCH_ABANDONED':
89+
statusText = t('Research Abandoned');
90+
break;
91+
92+
case 'EXPIRED_REFERRAL':
93+
statusText = t('Expired Referral');
94+
break;
10395
}
96+
97+
return (
98+
<ContactHeaderSection icon={<HandshakeIcon />}>
99+
<Typography variant="subtitle1">{statusText}</Typography>
100+
</ContactHeaderSection>
101+
);
104102
}
105103

106104
return <ContactHeaderSection icon={<HandshakeIcon />} />;

0 commit comments

Comments
 (0)