1
- import { useState , useEffect } from 'react'
1
+ import { useState , useEffect , useRef } from 'react'
2
2
import styled , { css } from 'styled-components'
3
3
import { useTranslation } from 'react-i18next'
4
4
import Typography from '@l3-lib/ui-core/dist/Typography'
@@ -94,12 +94,25 @@ const AgentForm = ({ formik, isVoice = true }: AgentFormProps) => {
94
94
95
95
const [ activeTab , setActiveTab ] = useState ( 0 )
96
96
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
+
97
110
return (
98
111
< StyledFormRoot >
99
112
< StyledFormTabsWrapper >
100
113
< StyledFormTabList size = 'small' >
101
114
< StyledTab
102
- onClick = { ( ) => setActiveTab ( 0 ) }
115
+ onClick = { ( ) => handleTabClick ( 0 ) }
103
116
isError = { validationError ?. agent_name && activeTab !== 0 }
104
117
>
105
118
< StyledSpan
@@ -109,24 +122,25 @@ const AgentForm = ({ formik, isVoice = true }: AgentFormProps) => {
109
122
General
110
123
</ StyledSpan >
111
124
</ StyledTab >
112
- < StyledTab onClick = { ( ) => setActiveTab ( 1 ) } >
125
+ < StyledTab onClick = { ( ) => handleTabClick ( 1 ) } >
113
126
< StyledSpan isActive = { activeTab === 1 } > Configuration</ StyledSpan >
114
127
</ StyledTab >
115
- < StyledTab onClick = { ( ) => setActiveTab ( 2 ) } >
128
+ < StyledTab onClick = { ( ) => handleTabClick ( 2 ) } >
116
129
< StyledSpan isActive = { activeTab === 2 } > Training Details</ StyledSpan >
117
130
</ StyledTab >
118
- < StyledTab onClick = { ( ) => setActiveTab ( 3 ) } >
131
+ < StyledTab onClick = { ( ) => handleTabClick ( 3 ) } >
119
132
< StyledSpan isActive = { activeTab === 3 } > Onboarding</ StyledSpan >
120
133
</ StyledTab >
121
- < StyledTab onClick = { ( ) => setActiveTab ( 4 ) } isDisabled = { ! isVoice } >
134
+ < StyledTab onClick = { ( ) => handleTabClick ( 4 ) } isDisabled = { ! isVoice } >
122
135
< StyledSpan isActive = { activeTab === 4 } > Voice Preferences</ StyledSpan >
123
136
</ StyledTab >
124
- < StyledTab onClick = { ( ) => setActiveTab ( 5 ) } >
137
+ < StyledTab onClick = { ( ) => handleTabClick ( 5 ) } >
125
138
< StyledSpan isActive = { activeTab === 5 } > Integrations</ StyledSpan >
126
139
</ StyledTab >
127
140
</ StyledFormTabList >
128
141
</ StyledFormTabsWrapper >
129
142
< StyledForm >
143
+ < div ref = { topRef } />
130
144
< StyledInputWrapper >
131
145
< TabsContext activeTabId = { activeTab } >
132
146
< TabPanels noAnimation >
@@ -141,6 +155,7 @@ const AgentForm = ({ formik, isVoice = true }: AgentFormProps) => {
141
155
label = { t ( 'description' ) }
142
156
value = { agent_description }
143
157
fieldName = { 'agent_description' }
158
+ triggerResize = { activeTab }
144
159
/>
145
160
146
161
< StyledCheckboxWrapper >
@@ -259,6 +274,7 @@ const AgentForm = ({ formik, isVoice = true }: AgentFormProps) => {
259
274
label = { t ( 'base-system-message' ) }
260
275
value = { agent_text }
261
276
fieldName = { 'agent_text' }
277
+ triggerResize = { activeTab }
262
278
/>
263
279
</ StyledTabPanelInnerWrapper >
264
280
</ TabPanel >
@@ -276,6 +292,7 @@ const AgentForm = ({ formik, isVoice = true }: AgentFormProps) => {
276
292
label = { t ( 'greeting' ) }
277
293
value = { agent_greeting }
278
294
fieldName = { 'agent_greeting' }
295
+ triggerResize = { activeTab }
279
296
/>
280
297
</ StyledTabPanelInnerWrapper >
281
298
</ TabPanel >
0 commit comments