diff --git a/packages/embeds/js/package.json b/packages/embeds/js/package.json index b20dd8143..bec7703e3 100644 --- a/packages/embeds/js/package.json +++ b/packages/embeds/js/package.json @@ -1,6 +1,6 @@ { "name": "@typebot.io/js", - "version": "0.2.61", + "version": "0.2.62", "description": "Javascript library to display typebots on your website", "type": "module", "main": "dist/index.js", diff --git a/packages/embeds/js/src/features/blocks/inputs/email/components/EmailInput.tsx b/packages/embeds/js/src/features/blocks/inputs/email/components/EmailInput.tsx index fe309ba7a..7cc80f331 100644 --- a/packages/embeds/js/src/features/blocks/inputs/email/components/EmailInput.tsx +++ b/packages/embeds/js/src/features/blocks/inputs/email/components/EmailInput.tsx @@ -23,7 +23,8 @@ export const EmailInput = (props: Props) => { inputRef?.value !== '' && inputRef?.reportValidity() const submit = () => { - if (checkIfInputIsValid()) props.onSubmit({ value: inputValue() }) + if (checkIfInputIsValid()) + props.onSubmit({ value: inputRef?.value ?? inputValue() }) else inputRef?.focus() } diff --git a/packages/embeds/js/src/features/blocks/inputs/number/components/NumberInput.tsx b/packages/embeds/js/src/features/blocks/inputs/number/components/NumberInput.tsx index 7ce4c0e24..d628b5f53 100644 --- a/packages/embeds/js/src/features/blocks/inputs/number/components/NumberInput.tsx +++ b/packages/embeds/js/src/features/blocks/inputs/number/components/NumberInput.tsx @@ -27,7 +27,7 @@ export const NumberInput = (props: NumberInputProps) => { const submit = () => { if (checkIfInputIsValid()) - props.onSubmit({ value: inputValue().toString() }) + props.onSubmit({ value: inputRef?.value ?? inputValue().toString() }) else inputRef?.focus() } diff --git a/packages/embeds/js/src/features/blocks/inputs/phone/components/PhoneInput.tsx b/packages/embeds/js/src/features/blocks/inputs/phone/components/PhoneInput.tsx index 14907334b..cc27bd577 100644 --- a/packages/embeds/js/src/features/blocks/inputs/phone/components/PhoneInput.tsx +++ b/packages/embeds/js/src/features/blocks/inputs/phone/components/PhoneInput.tsx @@ -63,13 +63,14 @@ export const PhoneInput = (props: PhoneInputProps) => { const selectedCountryDialCode = phoneCountries.find( (country) => country.code === selectedCountryCode() )?.dial_code - if (checkIfInputIsValid()) + if (checkIfInputIsValid()) { + const val = inputRef?.value ?? inputValue() props.onSubmit({ - value: inputValue().startsWith('+') - ? inputValue() - : `${selectedCountryDialCode ?? ''}${inputValue()}`, + value: val.startsWith('+') + ? val + : `${selectedCountryDialCode ?? ''}${val}`, }) - else inputRef?.focus() + } else inputRef?.focus() } const submitWhenEnter = (e: KeyboardEvent) => { diff --git a/packages/embeds/js/src/features/blocks/inputs/textInput/components/TextInput.tsx b/packages/embeds/js/src/features/blocks/inputs/textInput/components/TextInput.tsx index 8aceb094b..9b661fa5c 100644 --- a/packages/embeds/js/src/features/blocks/inputs/textInput/components/TextInput.tsx +++ b/packages/embeds/js/src/features/blocks/inputs/textInput/components/TextInput.tsx @@ -23,7 +23,8 @@ export const TextInput = (props: Props) => { inputRef?.value !== '' && inputRef?.reportValidity() const submit = () => { - if (checkIfInputIsValid()) props.onSubmit({ value: inputValue() }) + if (checkIfInputIsValid()) + props.onSubmit({ value: inputRef?.value ?? inputValue() }) else inputRef?.focus() } diff --git a/packages/embeds/js/src/features/blocks/inputs/url/components/UrlInput.tsx b/packages/embeds/js/src/features/blocks/inputs/url/components/UrlInput.tsx index 97dc37dfb..e3d4d4e0a 100644 --- a/packages/embeds/js/src/features/blocks/inputs/url/components/UrlInput.tsx +++ b/packages/embeds/js/src/features/blocks/inputs/url/components/UrlInput.tsx @@ -29,7 +29,8 @@ export const UrlInput = (props: Props) => { inputRef?.value !== '' && inputRef?.reportValidity() const submit = () => { - if (checkIfInputIsValid()) props.onSubmit({ value: inputValue() }) + if (checkIfInputIsValid()) + props.onSubmit({ value: inputRef?.value ?? inputValue() }) else inputRef?.focus() } diff --git a/packages/embeds/js/src/utils/guessApiHost.ts b/packages/embeds/js/src/utils/guessApiHost.ts index b2d5f4b10..0b1e74238 100644 --- a/packages/embeds/js/src/utils/guessApiHost.ts +++ b/packages/embeds/js/src/utils/guessApiHost.ts @@ -25,8 +25,13 @@ export const guessApiHost = ( return chatApiUrl } - return ( - getRuntimeVariable('NEXT_PUBLIC_VIEWER_URL')?.split(',')[0] ?? - chatApiCloudFallbackHost + const viewerUrls = getRuntimeVariable('NEXT_PUBLIC_VIEWER_URL')?.split( + ',' + ) as string[] | undefined + + const matchedUrl = viewerUrls?.find((url) => + window.location.href.startsWith(url) ) + + return matchedUrl ?? chatApiCloudFallbackHost } diff --git a/packages/embeds/nextjs/package.json b/packages/embeds/nextjs/package.json index 366a2e2ff..598d61d10 100644 --- a/packages/embeds/nextjs/package.json +++ b/packages/embeds/nextjs/package.json @@ -1,6 +1,6 @@ { "name": "@typebot.io/nextjs", - "version": "0.2.61", + "version": "0.2.62", "description": "Convenient library to display typebots on your Next.js website", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/embeds/react/package.json b/packages/embeds/react/package.json index e8f626d08..f894d3db6 100644 --- a/packages/embeds/react/package.json +++ b/packages/embeds/react/package.json @@ -1,6 +1,6 @@ { "name": "@typebot.io/react", - "version": "0.2.61", + "version": "0.2.62", "description": "Convenient library to display typebots on your React app", "main": "dist/index.js", "types": "dist/index.d.ts",