Skip to content

Commit 22ea9f5

Browse files
committed
chore: update version to 1.9.5-beta-3 in package.json and package-lock.json; refactor error handling in PhoneInput and FormFieldInfo components
1 parent fb44f92 commit 22ea9f5

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "1.9.5-beta-2",
3+
"version": "1.9.5-beta-3",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",

src/Shared/Components/FormFieldWrapper/FormFieldInfo.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ const FormInfoItem = ({ id, text, icon, textClass }: FormInfoItemProps) => (
2727

2828
const FormFieldInfo = ({ error, helperText, warningText, inputId }: FormFieldInfoProps) => (
2929
<div className="flex left column dc__gap-4">
30-
{!!error && <FormInfoItem text={error} icon="ic-error" textClass="cr-5" id={getFormErrorElementId(inputId)} />}
30+
{((typeof error === 'string' && !!error.trim()) || !!error) && (
31+
<FormInfoItem text={error} icon="ic-error" textClass="cr-5" id={getFormErrorElementId(inputId)} />
32+
)}
3133
{!!helperText && (
3234
<FormInfoItem text={helperText} icon="ic-info-filled" textClass="cn-7" id={`${inputId}-helper-text`} />
3335
)}

src/Shared/Components/PhoneInput/PhoneInput.component.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { usePhoneInput } from 'react-international-phone'
22
import { CountryISO2Type } from '@Shared/index'
3+
import { useRef } from 'react'
34
import { PhoneInputProps } from './types'
45
import { CountrySelect } from '../CountrySelect'
56
import { CustomInput } from '../CustomInput'
6-
import { Icon } from '../Icon'
7+
import FormFieldInfo from '../FormFieldWrapper/FormFieldInfo'
78

89
const PhoneInput = ({
910
error,
@@ -14,11 +15,18 @@ const PhoneInput = ({
1415
phoneValue,
1516
countryCodeSelectSize,
1617
}: PhoneInputProps) => {
18+
const hasValueInitialized = useRef(false)
19+
1720
// TODO: There are some issues with argentina country code, need to fix it
1821
const { inputValue, handlePhoneValueChange, inputRef, country, setCountry } = usePhoneInput({
1922
value: phoneValue,
2023
forceDialCode: true,
2124
onChange: (data) => {
25+
// So initially this will format the phone or set the dial code to us if no phone is there, but since we expect user to enter phone number, we will ignore the first call
26+
if (!hasValueInitialized.current) {
27+
hasValueInitialized.current = true
28+
return
29+
}
2230
onChange(data.phone)
2331
},
2432
})
@@ -51,16 +59,13 @@ const PhoneInput = ({
5159
value={inputValue}
5260
onChange={handlePhoneValueChange}
5361
inputRef={inputRef}
62+
// Since we are showing error below but want css of errors here
63+
error={error ? ' ' : null}
5464
fullWidth
5565
/>
5666
</div>
5767

58-
{error && (
59-
<div className="flexbox dc__gap-4 fs-11 lh-16 fw-4">
60-
<Icon name="ic-error" size={16} color={null} />
61-
<span className="dc__ellipsis-right__2nd-line cr-5">{error}</span>
62-
</div>
63-
)}
68+
{error && <FormFieldInfo error={error} inputId={phoneNumberInputName} />}
6469
</div>
6570
</div>
6671
)

0 commit comments

Comments
 (0)