@@ -2,7 +2,7 @@ import Skeleton from "@mui/material/Skeleton";
2
2
import { API } from "api/api" ;
3
3
import { getErrorDetail , getErrorMessage } from "api/errors" ;
4
4
import { disabledRefetchOptions } from "api/queries/util" ;
5
- import type { Template } from "api/typesGenerated" ;
5
+ import type { Template , Workspace } from "api/typesGenerated" ;
6
6
import { ErrorAlert } from "components/Alert/ErrorAlert" ;
7
7
import { Avatar } from "components/Avatar/Avatar" ;
8
8
import { AvatarData } from "components/Avatar/AvatarData" ;
@@ -46,7 +46,7 @@ import { generateWorkspaceName } from "modules/workspaces/generateWorkspaceName"
46
46
import { type FC , type ReactNode , useState } from "react" ;
47
47
import { Helmet } from "react-helmet-async" ;
48
48
import { useMutation , useQuery , useQueryClient } from "react-query" ;
49
- import { Link as RouterLink } from "react-router-dom" ;
49
+ import { Link as RouterLink , useNavigate } from "react-router-dom" ;
50
50
import TextareaAutosize from "react-textarea-autosize" ;
51
51
import { pageTitle } from "utils/page" ;
52
52
import { relativeTime } from "utils/time" ;
@@ -157,6 +157,7 @@ const TaskFormSection: FC<{
157
157
filter : TasksFilter ;
158
158
onFilterChange : ( filter : TasksFilter ) => void ;
159
159
} > = ( { showFilter, filter, onFilterChange } ) => {
160
+ const navigate = useNavigate ( ) ;
160
161
const {
161
162
data : templates ,
162
163
error,
@@ -184,7 +185,14 @@ const TaskFormSection: FC<{
184
185
}
185
186
return (
186
187
< >
187
- < TaskForm templates = { templates } />
188
+ < TaskForm
189
+ templates = { templates }
190
+ onSuccess = { ( task ) => {
191
+ navigate (
192
+ `/tasks/${ task . workspace . owner_name } /${ task . workspace . name } ` ,
193
+ ) ;
194
+ } }
195
+ />
188
196
{ showFilter && (
189
197
< TasksFilter filter = { filter } onFilterChange = { onFilterChange } />
190
198
) }
@@ -196,9 +204,10 @@ type CreateTaskMutationFnProps = { prompt: string; templateId: string };
196
204
197
205
type TaskFormProps = {
198
206
templates : Template [ ] ;
207
+ onSuccess : ( task : Task ) => void ;
199
208
} ;
200
209
201
- const TaskForm : FC < TaskFormProps > = ( { templates } ) => {
210
+ const TaskForm : FC < TaskFormProps > = ( { templates, onSuccess } ) => {
202
211
const { user } = useAuthenticated ( ) ;
203
212
const queryClient = useQueryClient ( ) ;
204
213
@@ -220,10 +229,11 @@ const TaskForm: FC<TaskFormProps> = ({ templates }) => {
220
229
const createTaskMutation = useMutation ( {
221
230
mutationFn : async ( { prompt, templateId } : CreateTaskMutationFnProps ) =>
222
231
data . createTask ( prompt , user . id , templateId ) ,
223
- onSuccess : async ( ) => {
232
+ onSuccess : async ( task ) => {
224
233
await queryClient . invalidateQueries ( {
225
234
queryKey : [ "tasks" ] ,
226
235
} ) ;
236
+ onSuccess ( task ) ;
227
237
} ,
228
238
} ) ;
229
239
@@ -244,7 +254,6 @@ const TaskForm: FC<TaskFormProps> = ({ templates }) => {
244
254
prompt,
245
255
templateId : templateID ,
246
256
} ) ;
247
- form . reset ( ) ;
248
257
} catch ( error ) {
249
258
const message = getErrorMessage ( error , "Error creating task" ) ;
250
259
const detail = getErrorDetail ( error ) ?? "Please try again" ;
0 commit comments