Remove duplicate plus sign for phone numbers (#8871)
Fixes #8838
1. Summary
It seems [this PR](https://github.com/twentyhq/twenty/pull/8614) caused
the issue. We added a plus sign on front-end when the
[callingCode](c735026f6c/packages/twenty-front/src/modules/ui/field/display/components/PhonesDisplay.tsx (L70))
retrieved from back-end already has a plus sign.
2. Solution
@guillim Please let me know if I missed a case where the plus sign is
not there for the `callingCode`. If so, I think we should check whether
or not `callingCode` has a leading plus sign on front-end before adding
it. For now, I just removed the code that appends a plus sign on
front-end.
3. Screenshots

---------
Co-authored-by: guillim <guigloo@msn.com>
Co-authored-by: Guillim <guillim@users.noreply.github.com>
Co-authored-by: Weiko <deniaud.corentin@gmail.com>
This commit is contained in:
@ -111,7 +111,7 @@ export const MultiItemFieldInput = <T,>({
|
|||||||
break;
|
break;
|
||||||
case FieldMetadataType.Phones:
|
case FieldMetadataType.Phones:
|
||||||
item = items[index] as PhoneRecord;
|
item = items[index] as PhoneRecord;
|
||||||
setInputValue(`+${item.callingCode}` + item.number);
|
setInputValue(item.callingCode + item.number);
|
||||||
break;
|
break;
|
||||||
case FieldMetadataType.Emails:
|
case FieldMetadataType.Emails:
|
||||||
item = items[index] as string;
|
item = items[index] as string;
|
||||||
|
|||||||
@ -14,6 +14,8 @@ import { PhoneCountryPickerDropdownButton } from '@/ui/input/components/internal
|
|||||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||||
import { stripSimpleQuotesFromString } from '~/utils/string/stripSimpleQuotesFromString';
|
import { stripSimpleQuotesFromString } from '~/utils/string/stripSimpleQuotesFromString';
|
||||||
|
|
||||||
|
export const DEFAULT_PHONE_COUNTRY_CODE = '1';
|
||||||
|
|
||||||
const StyledCustomPhoneInput = styled(ReactPhoneNumberInput)`
|
const StyledCustomPhoneInput = styled(ReactPhoneNumberInput)`
|
||||||
font-family: ${({ theme }) => theme.font.family};
|
font-family: ${({ theme }) => theme.font.family};
|
||||||
height: 32px;
|
height: 32px;
|
||||||
@ -71,11 +73,10 @@ export const PhonesFieldInput = ({ onCancel }: PhonesFieldInputProps) => {
|
|||||||
const defaultCallingCode =
|
const defaultCallingCode =
|
||||||
stripSimpleQuotesFromString(
|
stripSimpleQuotesFromString(
|
||||||
fieldDefinition?.defaultValue?.primaryPhoneCountryCode,
|
fieldDefinition?.defaultValue?.primaryPhoneCountryCode,
|
||||||
) ?? '+1';
|
) ?? DEFAULT_PHONE_COUNTRY_CODE;
|
||||||
|
|
||||||
// TODO : improve once we store the real country code
|
// TODO : improve once we store the real country code
|
||||||
const defaultCountry = useCountries().find(
|
const defaultCountry = useCountries().find(
|
||||||
(obj) => obj.callingCode === defaultCallingCode,
|
(obj) => `+${obj.callingCode}` === defaultCallingCode,
|
||||||
)?.countryCode;
|
)?.countryCode;
|
||||||
|
|
||||||
const handlePersistPhones = (
|
const handlePersistPhones = (
|
||||||
@ -103,7 +104,7 @@ export const PhonesFieldInput = ({ onCancel }: PhonesFieldInputProps) => {
|
|||||||
if (phone !== undefined) {
|
if (phone !== undefined) {
|
||||||
return {
|
return {
|
||||||
number: phone.nationalNumber,
|
number: phone.nationalNumber,
|
||||||
callingCode: `${phone.countryCallingCode}`,
|
callingCode: `+${phone.countryCallingCode}`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -37,7 +37,7 @@ export const SettingsDataModelFieldPhonesForm = ({
|
|||||||
.sort((a, b) => a.countryName.localeCompare(b.countryName))
|
.sort((a, b) => a.countryName.localeCompare(b.countryName))
|
||||||
.map((country) => ({
|
.map((country) => ({
|
||||||
label: `${country.countryName} (+${country.callingCode})`,
|
label: `${country.countryName} (+${country.callingCode})`,
|
||||||
value: `${country.callingCode}`,
|
value: `+${country.callingCode}`,
|
||||||
}));
|
}));
|
||||||
countries.unshift({ label: 'No country', value: '' });
|
countries.unshift({ label: 'No country', value: '' });
|
||||||
const defaultDefaultValue = {
|
const defaultDefaultValue = {
|
||||||
|
|||||||
@ -22,9 +22,9 @@ export const getPhonesFieldPreviewValue = ({
|
|||||||
const primaryPhoneCountryCode =
|
const primaryPhoneCountryCode =
|
||||||
fieldMetadataItem.defaultValue?.primaryPhoneCountryCode &&
|
fieldMetadataItem.defaultValue?.primaryPhoneCountryCode &&
|
||||||
fieldMetadataItem.defaultValue.primaryPhoneCountryCode !== ''
|
fieldMetadataItem.defaultValue.primaryPhoneCountryCode !== ''
|
||||||
? `+${stripSimpleQuotesFromString(
|
? stripSimpleQuotesFromString(
|
||||||
fieldMetadataItem.defaultValue?.primaryPhoneCountryCode,
|
fieldMetadataItem.defaultValue?.primaryPhoneCountryCode,
|
||||||
)}`
|
)
|
||||||
: null;
|
: null;
|
||||||
return {
|
return {
|
||||||
...placeholderDefaultValue,
|
...placeholderDefaultValue,
|
||||||
|
|||||||
@ -67,7 +67,7 @@ export const PhonesDisplay = ({ value, isFocused }: PhonesDisplayProps) => {
|
|||||||
<ExpandableList isChipCountDisplayed>
|
<ExpandableList isChipCountDisplayed>
|
||||||
{phones.map(({ number, callingCode }, index) => {
|
{phones.map(({ number, callingCode }, index) => {
|
||||||
const { parsedPhone, invalidPhone } =
|
const { parsedPhone, invalidPhone } =
|
||||||
parsePhoneNumberOrReturnInvalidValue(`+${callingCode}` + number);
|
parsePhoneNumberOrReturnInvalidValue(callingCode + number);
|
||||||
const URI = parsedPhone?.getURI();
|
const URI = parsedPhone?.getURI();
|
||||||
return (
|
return (
|
||||||
<RoundedLink
|
<RoundedLink
|
||||||
@ -84,7 +84,7 @@ export const PhonesDisplay = ({ value, isFocused }: PhonesDisplayProps) => {
|
|||||||
<StyledContainer>
|
<StyledContainer>
|
||||||
{phones.map(({ number, callingCode }, index) => {
|
{phones.map(({ number, callingCode }, index) => {
|
||||||
const { parsedPhone, invalidPhone } =
|
const { parsedPhone, invalidPhone } =
|
||||||
parsePhoneNumberOrReturnInvalidValue(`+${callingCode}` + number);
|
parsePhoneNumberOrReturnInvalidValue(callingCode + number);
|
||||||
const URI = parsedPhone?.getURI();
|
const URI = parsedPhone?.getURI();
|
||||||
return (
|
return (
|
||||||
<RoundedLink
|
<RoundedLink
|
||||||
|
|||||||
Reference in New Issue
Block a user