Skip to content

Commit

Permalink
🐛 (phoneInput) Fix phone country prefix not changing when already set (
Browse files Browse the repository at this point in the history
…#1895)

Co-authored-by: Baptiste Arnaud <[email protected]>
  • Loading branch information
basuabhirup and baptisteArno authored Nov 23, 2024
1 parent 4dc636d commit 676fe94
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/embeds/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/js",
"version": "0.3.30",
"version": "0.3.31",
"description": "Javascript library to display typebots on your website",
"license": "FSL-1.1-ALv2",
"type": "module",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,21 @@ export const PhoneInput = (props: PhoneInputProps) => {
const selectNewCountryCode = (
event: Event & { currentTarget: { value: string } },
) => {
const code = event.currentTarget.value;
setSelectedCountryCode(code);
const dial_code = phoneCountries.find(
(country) => country.code === code,
)?.dial_code;
if (inputValue() === "" && dial_code) setInputValue(dial_code);
const selectedCountry = phoneCountries.find(
(country) => country.code === event.currentTarget.value,
);
if (!selectedCountry) return;

const currentCountry = phoneCountries.find(
(country) => country.code === selectedCountryCode(),
);
if (
inputValue() === "" ||
(currentCountry && inputValue() === currentCountry.dial_code)
)
setInputValue(selectedCountry.dial_code);

setSelectedCountryCode(selectedCountry.code);
inputRef?.focus();
};

Expand Down
2 changes: 1 addition & 1 deletion packages/embeds/nextjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/nextjs",
"version": "0.3.30",
"version": "0.3.31",
"license": "FSL-1.1-ALv2",
"description": "Convenient library to display typebots on your Next.js website",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion packages/embeds/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/react",
"version": "0.3.30",
"version": "0.3.31",
"description": "Convenient library to display typebots on your React app",
"license": "FSL-1.1-ALv2",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/src/phoneCountries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export const phoneCountries = [
name: "International",
flag: "🌐",
code: "INT",
dial_code: null,
dial_code: "",
},
{
name: "Afghanistan",
Expand Down

0 comments on commit 676fe94

Please sign in to comment.