@@ -11,13 +11,15 @@ import { CreateTemplateForm } from "./CreateTemplateForm";
11
11
import { ErrorAlert } from "components/Alert/ErrorAlert" ;
12
12
import { useMutation , useQuery } from "@tanstack/react-query" ;
13
13
import {
14
+ JobError ,
14
15
createTemplate ,
15
16
templateByName ,
16
17
templateVersion ,
17
18
templateVersionVariables ,
18
19
} from "api/queries/templates" ;
19
20
import { ProvisionerType } from "api/typesGenerated" ;
20
21
import { calculateAutostopRequirementDaysValue } from "utils/schedule" ;
22
+ import { templateVersionLogs } from "api/queries/templateVersions" ;
21
23
22
24
const provisioner : ProvisionerType =
23
25
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Playwright needs to use a different provisioner type!
@@ -122,17 +124,15 @@ const DuplicateTemplateView = () => {
122
124
const templateByNameQuery = useQuery (
123
125
templateByName ( organizationId , searchParams . get ( "fromTemplate" ) ! ) ,
124
126
) ;
127
+ const activeVersionId =
128
+ templateByNameQuery . data ?. template . active_version_id ?? "" ;
125
129
const templateVersionQuery = useQuery ( {
126
- ...templateVersion (
127
- templateByNameQuery . data ?. template . active_version_id ?? "" ,
128
- ) ,
129
- enabled : templateByNameQuery . data !== undefined ,
130
+ ...templateVersion ( activeVersionId ) ,
131
+ enabled : templateByNameQuery . isSuccess ,
130
132
} ) ;
131
133
const templateVersionVariablesQuery = useQuery ( {
132
- ...templateVersionVariables (
133
- templateByNameQuery . data ?. template . active_version_id ?? "" ,
134
- ) ,
135
- enabled : templateByNameQuery . data !== undefined ,
134
+ ...templateVersionVariables ( activeVersionId ) ,
135
+ enabled : templateByNameQuery . isSuccess ,
136
136
} ) ;
137
137
const isLoading =
138
138
templateByNameQuery . isLoading ||
@@ -146,6 +146,12 @@ const DuplicateTemplateView = () => {
146
146
const formEntitlements = useFormEntitlements ( ) ;
147
147
148
148
const createTemplateMutation = useMutation ( createTemplate ( ) ) ;
149
+ const createError = createTemplateMutation . error ;
150
+ const isJobError = createError instanceof JobError ;
151
+ const templateVersionLogsQuery = useQuery ( {
152
+ ...templateVersionLogs ( isJobError ? createError . version . id : "" ) ,
153
+ enabled : isJobError ,
154
+ } ) ;
149
155
150
156
if ( isLoading ) {
151
157
return < Loader /> ;
@@ -176,13 +182,20 @@ const DuplicateTemplateView = () => {
176
182
} ) ;
177
183
navigate ( `/templates/${ template . name } ` ) ;
178
184
} }
179
-
180
- // jobError={jobError}
181
- // logs={jobLogs}
185
+ jobError = { isJobError ? createError . job . error : undefined }
186
+ logs = { templateVersionLogsQuery . data }
182
187
/>
183
188
) ;
184
189
} ;
185
190
191
+ const ImportStaterTemplateView = ( ) => {
192
+ return < div > Import</ div > ;
193
+ } ;
194
+
195
+ const UploadTemplateView = ( ) => {
196
+ return < div > Upload</ div > ;
197
+ } ;
198
+
186
199
const useFormEntitlements = ( ) => {
187
200
const { entitlements } = useDashboard ( ) ;
188
201
const allowAdvancedScheduling =
@@ -201,14 +214,6 @@ const useFormEntitlements = () => {
201
214
} ;
202
215
} ;
203
216
204
- const ImportStaterTemplateView = ( ) => {
205
- return < div > Import</ div > ;
206
- } ;
207
-
208
- const UploadTemplateView = ( ) => {
209
- return < div > Upload</ div > ;
210
- } ;
211
-
212
217
const prepareData = ( formData : CreateTemplateData ) => {
213
218
const {
214
219
default_ttl_hours,
0 commit comments