diff --git a/frontend/ee b/frontend/ee index d93ee7e131..715a830c7a 160000 --- a/frontend/ee +++ b/frontend/ee @@ -1 +1 @@ -Subproject commit d93ee7e1318f044ef2327671b8b257648071453d +Subproject commit 715a830c7a8d75efc7f77106292d9e4499005b69 diff --git a/frontend/src/AppBuilder/Widgets/PhoneInput/CountrySelect.jsx b/frontend/src/AppBuilder/Widgets/PhoneCurrency/CountrySelect.jsx similarity index 100% rename from frontend/src/AppBuilder/Widgets/PhoneInput/CountrySelect.jsx rename to frontend/src/AppBuilder/Widgets/PhoneCurrency/CountrySelect.jsx diff --git a/frontend/src/AppBuilder/Widgets/PhoneInput/CustomMenuList.jsx b/frontend/src/AppBuilder/Widgets/PhoneCurrency/CustomMenuList.jsx similarity index 100% rename from frontend/src/AppBuilder/Widgets/PhoneInput/CustomMenuList.jsx rename to frontend/src/AppBuilder/Widgets/PhoneCurrency/CustomMenuList.jsx diff --git a/frontend/src/AppBuilder/Widgets/PhoneInput/CustomOption.jsx b/frontend/src/AppBuilder/Widgets/PhoneCurrency/CustomOption.jsx similarity index 100% rename from frontend/src/AppBuilder/Widgets/PhoneInput/CustomOption.jsx rename to frontend/src/AppBuilder/Widgets/PhoneCurrency/CustomOption.jsx diff --git a/frontend/src/AppBuilder/Widgets/PhoneInput/CustomValueContainer.jsx b/frontend/src/AppBuilder/Widgets/PhoneCurrency/CustomValueContainer.jsx similarity index 100% rename from frontend/src/AppBuilder/Widgets/PhoneInput/CustomValueContainer.jsx rename to frontend/src/AppBuilder/Widgets/PhoneCurrency/CustomValueContainer.jsx diff --git a/frontend/src/AppBuilder/Widgets/PhoneCurrency/PhoneInput.jsx b/frontend/src/AppBuilder/Widgets/PhoneCurrency/PhoneInput.jsx new file mode 100644 index 0000000000..ce7bc39fe8 --- /dev/null +++ b/frontend/src/AppBuilder/Widgets/PhoneCurrency/PhoneInput.jsx @@ -0,0 +1,254 @@ +import React, { useEffect, useMemo, useRef } from 'react'; +// eslint-disable-next-line import/no-unresolved +import Input, { getCountries, getCountryCallingCode } from 'react-phone-number-input/input'; +import { getCountryCallingCodeSafe } from './utils'; +// eslint-disable-next-line import/no-unresolved +import en from 'react-phone-number-input/locale/en'; +import 'react-phone-number-input/style.css'; +import { useInput } from '../BaseComponents/hooks/useInput'; +import Loader from '@/ToolJetUI/Loader/Loader'; +import Label from '@/_ui/Label'; +import { CountrySelect } from './CountrySelect'; + +const tinycolor = require('tinycolor2'); + +export const PhoneInput = (props) => { + const { properties, styles, componentName, darkMode, setExposedVariables, fireEvent } = props; + const transformedProps = { + ...props, + inputType: 'phone', + }; + const inputLogic = useInput(transformedProps); + const { + inputRef, + labelRef, + visibility, + loading, + disable, + showValidationError, + isFocused, + labelWidth, + isValid, + validationError, + isMandatory, + handleBlur, + handleFocus, + value, + handlePhoneInputChange, + country, + setCountry, + } = inputLogic; + const { label, placeholder, isCountryChangeEnabled, defaultCountry = 'US' } = properties; + + const { + textColor, + backgroundColor, + alignment, + width, + direction, + auto, + color, + borderColor, + accentColor, + errTextColor, + boxShadow, + borderRadius, + } = styles; + const _width = (width / 100) * 70; + const defaultAlignment = alignment === 'side' || alignment === 'top' ? alignment : 'side'; + const isInitialRender = useRef(true); + + const options = useMemo( + () => + getCountries() + .map((country) => ({ + label: `${en[country]} +${getCountryCallingCodeSafe(country)}`, + value: country, + })) + .sort((a, b) => a.label.localeCompare(b.label)), + [] + ); + + const onInputValueChange = (value) => { + setExposedVariables({ + country: country, + countryCode: `+${getCountryCallingCodeSafe(country)}`, + formattedValue: `+${getCountryCallingCodeSafe(country)} ${inputRef.current?.value}`, + }); + handlePhoneInputChange(value); + }; + + const handleKeyUp = (e) => { + if (e.key === 'Enter') { + fireEvent('onEnterPressed'); + } + }; + + useEffect(() => { + if (isInitialRender.current) { + setExposedVariables({ + country: country, + countryCode: `+${getCountryCallingCodeSafe(country)}`, + formattedValue: `+${getCountryCallingCodeSafe(country)} ${inputRef.current?.value}`, + value: value, + setCountryCode: (code) => { + let value = getCountryCallingCodeSafe(code); + if (value) { + setCountry(code); + } else { + value = getCountries().find((country) => `+${getCountryCallingCode(country)}` === code); + setCountry(value ? value : ''); + } + }, + }); + isInitialRender.current = false; + } + }, []); + + useEffect(() => { + if (!isInitialRender.current) { + setCountry(defaultCountry); + } + }, [defaultCountry]); + + const disabledState = disable || loading; + + const loaderStyle = { + right: + direction === 'right' && + defaultAlignment === 'side' && + ((label?.length > 0 && width > 0) || (auto && width == 0 && label && label?.length != 0)) + ? `${labelWidth + 11}px` + : '11px', + top: + defaultAlignment === 'top' + ? ((label?.length > 0 && width > 0) || (auto && width == 0 && label && label?.length != 0)) && + 'calc(50% + 10px)' + : '', + transform: + defaultAlignment === 'top' && + ((label?.length > 0 && width > 0) || (auto && width == 0 && label && label?.length != 0)) && + ' translateY(-50%)', + zIndex: 3, + }; + + const computedStyles = { + height: '100%', + borderRadius: `${borderRadius}px`, + color: !['#1B1F24', '#000', '#000000ff'].includes(textColor) + ? textColor + : disabledState + ? 'var(--text-disabled)' + : 'var(--text-primary)', + borderColor: isFocused + ? accentColor != '4368E3' + ? accentColor + : 'var(--primary-accent-strong)' + : borderColor != '#CCD1D5' + ? borderColor + : disabledState + ? '1px solid var(--borders-disabled-on-white)' + : 'var(--borders-default)', + '--tblr-input-border-color-darker': tinycolor(borderColor).darken(24).toString(), + backgroundColor: + backgroundColor != '#fff' + ? backgroundColor + : disabledState + ? darkMode + ? 'var(--surfaces-app-bg-default)' + : 'var(--surfaces-surface-03)' + : 'var(--surfaces-surface-01)', + padding: '8px 10px', + overflow: 'hidden', + textOverflow: 'ellipsis', + borderBottomLeftRadius: '0px', + borderTopLeftRadius: '0px', + borderLeft: 'none', + }; + + return ( + <> +
+
+ {showValidationError && visibility && ( +
+ {validationError} +
+ )} + + ); +}; diff --git a/frontend/src/AppBuilder/Widgets/PhoneInput/utils.js b/frontend/src/AppBuilder/Widgets/PhoneCurrency/utils.js similarity index 100% rename from frontend/src/AppBuilder/Widgets/PhoneInput/utils.js rename to frontend/src/AppBuilder/Widgets/PhoneCurrency/utils.js diff --git a/frontend/src/AppBuilder/Widgets/PhoneInput/PhoneInput.jsx b/frontend/src/AppBuilder/Widgets/PhoneInput/PhoneInput.jsx index ce7bc39fe8..6a7dafceea 100644 --- a/frontend/src/AppBuilder/Widgets/PhoneInput/PhoneInput.jsx +++ b/frontend/src/AppBuilder/Widgets/PhoneInput/PhoneInput.jsx @@ -134,7 +134,7 @@ export const PhoneInput = (props) => { const computedStyles = { height: '100%', - borderRadius: `${borderRadius}px`, + borderRadius: `0px ${borderRadius}px ${borderRadius}px 0px`, color: !['#1B1F24', '#000', '#000000ff'].includes(textColor) ? textColor : disabledState @@ -165,7 +165,8 @@ export const PhoneInput = (props) => { borderTopLeftRadius: '0px', borderLeft: 'none', }; - + const countryCode = getCountryCallingCodeSafe(country); + console.log(countryCode); return ( <>
{ />