Skip to content

Commit 8d859d0

Browse files
authored
Merge pull request #288 from l3vels/fix/textarea
Fix/textarea
2 parents 77bd1c1 + c9c0a82 commit 8d859d0

File tree

3 files changed

+42
-11
lines changed

3 files changed

+42
-11
lines changed

apps/server/typings/chat.py

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class ChatMessageOutput(BaseModel):
7070
sender_name: Optional[str]
7171
chat_id: Optional[UUID]
7272
run_id: Optional[UUID] = None
73+
audio_url: Optional[str]
7374

7475

7576
class NegotiateOutput(BaseModel):

apps/ui/src/components/TextareaFormik/TextareaFormik.tsx

+17-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,17 @@ type TextareaProps = {
1010
label: string
1111
value: string
1212
fieldName: string
13+
triggerResize?: number
1314
}
1415

15-
const TextareaFormik = ({ setFieldValue, label, value, fieldName, ...props }: TextareaProps) => {
16+
const TextareaFormik = ({
17+
setFieldValue,
18+
label,
19+
value,
20+
fieldName,
21+
triggerResize,
22+
...props
23+
}: TextareaProps) => {
1624
const textareaRef = useRef(null as any)
1725

1826
const onTextareaChange = (field: string, value: string) => {
@@ -22,10 +30,15 @@ const TextareaFormik = ({ setFieldValue, label, value, fieldName, ...props }: Te
2230
useEffect(() => {
2331
const textarea = textareaRef.current
2432
if (textarea) {
25-
textarea.style.height = 'auto' // Reset the height to auto to recalculate the height
26-
textarea.style.height = `${textarea.scrollHeight}px` // Set the height to the scroll height of the content
33+
// console.log('SHOULD RESIZE')
34+
// textarea.style.height = 'auto' // Reset the height to auto to recalculate the height
35+
// textarea.style.height = `${textarea.scrollHeight}px` // Set the height to the scroll height of the content
36+
setTimeout(function () {
37+
textarea.style.height = 'auto' // Reset the height to auto to recalculate the height
38+
textarea.style.height = `${textarea.scrollHeight}px`
39+
}, 100)
2740
}
28-
}, [value])
41+
}, [value, triggerResize])
2942

3043
return (
3144
<StyledTextareaWrapper>

apps/ui/src/pages/Agents/AgentForm/AgentForm.tsx

+24-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useEffect } from 'react'
1+
import { useState, useEffect, useRef } from 'react'
22
import styled, { css } from 'styled-components'
33
import { useTranslation } from 'react-i18next'
44
import Typography from '@l3-lib/ui-core/dist/Typography'
@@ -94,12 +94,25 @@ const AgentForm = ({ formik, isVoice = true }: AgentFormProps) => {
9494

9595
const [activeTab, setActiveTab] = useState(0)
9696

97+
const topRef = useRef(null as any)
98+
99+
const scrollToTop = () => {
100+
if (topRef.current) {
101+
topRef.current.scrollIntoView({})
102+
}
103+
}
104+
105+
const handleTabClick = (id: number) => {
106+
setActiveTab(id)
107+
scrollToTop()
108+
}
109+
97110
return (
98111
<StyledFormRoot>
99112
<StyledFormTabsWrapper>
100113
<StyledFormTabList size='small'>
101114
<StyledTab
102-
onClick={() => setActiveTab(0)}
115+
onClick={() => handleTabClick(0)}
103116
isError={validationError?.agent_name && activeTab !== 0}
104117
>
105118
<StyledSpan
@@ -109,24 +122,25 @@ const AgentForm = ({ formik, isVoice = true }: AgentFormProps) => {
109122
General
110123
</StyledSpan>
111124
</StyledTab>
112-
<StyledTab onClick={() => setActiveTab(1)}>
125+
<StyledTab onClick={() => handleTabClick(1)}>
113126
<StyledSpan isActive={activeTab === 1}>Configuration</StyledSpan>
114127
</StyledTab>
115-
<StyledTab onClick={() => setActiveTab(2)}>
128+
<StyledTab onClick={() => handleTabClick(2)}>
116129
<StyledSpan isActive={activeTab === 2}>Training Details</StyledSpan>
117130
</StyledTab>
118-
<StyledTab onClick={() => setActiveTab(3)}>
131+
<StyledTab onClick={() => handleTabClick(3)}>
119132
<StyledSpan isActive={activeTab === 3}>Onboarding</StyledSpan>
120133
</StyledTab>
121-
<StyledTab onClick={() => setActiveTab(4)} isDisabled={!isVoice}>
134+
<StyledTab onClick={() => handleTabClick(4)} isDisabled={!isVoice}>
122135
<StyledSpan isActive={activeTab === 4}>Voice Preferences</StyledSpan>
123136
</StyledTab>
124-
<StyledTab onClick={() => setActiveTab(5)}>
137+
<StyledTab onClick={() => handleTabClick(5)}>
125138
<StyledSpan isActive={activeTab === 5}>Integrations</StyledSpan>
126139
</StyledTab>
127140
</StyledFormTabList>
128141
</StyledFormTabsWrapper>
129142
<StyledForm>
143+
<div ref={topRef} />
130144
<StyledInputWrapper>
131145
<TabsContext activeTabId={activeTab}>
132146
<TabPanels noAnimation>
@@ -141,6 +155,7 @@ const AgentForm = ({ formik, isVoice = true }: AgentFormProps) => {
141155
label={t('description')}
142156
value={agent_description}
143157
fieldName={'agent_description'}
158+
triggerResize={activeTab}
144159
/>
145160

146161
<StyledCheckboxWrapper>
@@ -259,6 +274,7 @@ const AgentForm = ({ formik, isVoice = true }: AgentFormProps) => {
259274
label={t('base-system-message')}
260275
value={agent_text}
261276
fieldName={'agent_text'}
277+
triggerResize={activeTab}
262278
/>
263279
</StyledTabPanelInnerWrapper>
264280
</TabPanel>
@@ -276,6 +292,7 @@ const AgentForm = ({ formik, isVoice = true }: AgentFormProps) => {
276292
label={t('greeting')}
277293
value={agent_greeting}
278294
fieldName={'agent_greeting'}
295+
triggerResize={activeTab}
279296
/>
280297
</StyledTabPanelInnerWrapper>
281298
</TabPanel>

0 commit comments

Comments
 (0)