Safely parse phone numbers before display (#7186)
Timeline activity properties are stored as string rather than array. Adding a safe parsing in front. Would be better to also update in backend but doing this as a quick fix
This commit is contained in:
@ -8,6 +8,7 @@ import { RoundedLink } from '@/ui/navigation/link/components/RoundedLink';
|
||||
|
||||
import { parsePhoneNumber } from 'libphonenumber-js';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
import { logError } from '~/utils/logError';
|
||||
|
||||
type PhonesDisplayProps = {
|
||||
value?: FieldPhonesValue;
|
||||
@ -39,7 +40,7 @@ export const PhonesDisplay = ({ value, isFocused }: PhonesDisplayProps) => {
|
||||
countryCode: value.primaryPhoneCountryCode,
|
||||
}
|
||||
: null,
|
||||
...(value?.additionalPhones ?? []),
|
||||
...parseAdditionalPhones(value?.additionalPhones),
|
||||
]
|
||||
.filter(isDefined)
|
||||
.map(({ number, countryCode }) => {
|
||||
@ -85,3 +86,23 @@ export const PhonesDisplay = ({ value, isFocused }: PhonesDisplayProps) => {
|
||||
</StyledContainer>
|
||||
);
|
||||
};
|
||||
|
||||
const parseAdditionalPhones = (additionalPhones?: any) => {
|
||||
if (!additionalPhones) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (typeof additionalPhones === 'object') {
|
||||
return additionalPhones;
|
||||
}
|
||||
|
||||
if (typeof additionalPhones === 'string') {
|
||||
try {
|
||||
return JSON.parse(additionalPhones);
|
||||
} catch (error) {
|
||||
logError(`Error parsing additional phones' : ` + error);
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user