11'use client' ;
22
3+ import { useParams , useRouter } from 'next/navigation' ;
34import { graphql } from '@/gql' ;
45import { useMutation , useQuery } from '@tanstack/react-query' ;
5- import { useParams , useRouter } from 'next/navigation' ;
66import {
7- Accordion ,
8- AccordionContent ,
9- AccordionItem ,
10- AccordionTrigger ,
11- Button ,
12- Icon ,
13- Spinner ,
14- Table ,
15- Tag ,
16- Text ,
17- toast ,
7+ Accordion ,
8+ AccordionContent ,
9+ AccordionItem ,
10+ AccordionTrigger ,
11+ Button ,
12+ Icon ,
13+ Spinner ,
14+ Table ,
15+ Tag ,
16+ Text ,
17+ toast ,
1818} from 'opub-ui' ;
1919
20+ import { GraphQL } from '@/lib/api' ;
2021import { Icons } from '@/components/icons' ;
2122import { RichTextRenderer } from '@/components/RichTextRenderer' ;
22- import { GraphQL } from '@/lib/api' ;
2323import { useEditStatus } from '../../context' ;
2424
2525const FetchAIModelForPublish : any = graphql ( `
@@ -173,6 +173,8 @@ export default function PublishPage() {
173173 const versions = model ?. versions || [ ] ;
174174 const primaryVersion = versions . find ( ( v : any ) => v . isLatest ) || versions [ 0 ] ;
175175 const hasProviders = versions . some ( ( v : any ) => v . providers ?. length > 0 ) ;
176+ const PUBLISH_SUCCESS_TOAST_ID = 'publish-ai-model-success' ;
177+ const PUBLISH_ERROR_TOAST_ID = 'publish-ai-model-error' ;
176178
177179 const { mutate, isLoading : updateLoading } = useMutation (
178180 ( mutationData : any ) =>
@@ -188,17 +190,7 @@ export default function PublishPage() {
188190 } ,
189191 }
190192 ) ,
191- {
192- onSuccess : ( ) => {
193- toast ( 'Model status updated successfully' ) ;
194- setStatus ( 'saved' ) ;
195- refetch ( ) ;
196- } ,
197- onError : ( error : any ) => {
198- toast ( `Error: ${ error . message } ` ) ;
199- setStatus ( 'unsaved' ) ;
200- } ,
201- }
193+ { }
202194 ) ;
203195
204196 const handlePublish = ( ) => {
@@ -211,8 +203,22 @@ export default function PublishPage() {
211203 } ,
212204 {
213205 onSuccess : ( ) => {
214- toast ( 'Model published successfully' ) ;
215- router . push ( `/dashboard/${ params . entityType } /${ params . entitySlug } /aimodels` ) ;
206+ toast ( 'Model published successfully' , {
207+ id : PUBLISH_SUCCESS_TOAST_ID ,
208+ } ) ;
209+ setStatus ( 'saved' ) ;
210+ refetch ( ) ;
211+ router . push (
212+ `/dashboard/${ params . entityType } /${ params . entitySlug } /aimodels`
213+ ) ;
214+ } ,
215+ onError : ( error : any ) => {
216+ const errorMessage =
217+ typeof error ?. message === 'string' && error . message . trim ( )
218+ ? error . message . trim ( )
219+ : 'Unable to publish model right now. Please try again.' ;
220+ toast ( `Error: ${ errorMessage } ` , { id : PUBLISH_ERROR_TOAST_ID } ) ;
221+ setStatus ( 'unsaved' ) ;
216222 } ,
217223 }
218224 ) ;
@@ -224,14 +230,15 @@ export default function PublishPage() {
224230 if ( ! model ?. tags ?. length ) metadataErrors . push ( 'Tags' ) ;
225231 if ( ! model ?. sectors ?. length ) metadataErrors . push ( 'Sectors' ) ;
226232 if ( ! model ?. geographies ?. length ) metadataErrors . push ( 'Geographies' ) ;
227-
233+
228234 // Check required fields from metadata
229235 const metadata = model ?. metadata || { } ;
230236 if ( ! metadata . targetUsers ) metadataErrors . push ( 'Target Users' ) ;
231237 if ( ! metadata . intendedUse ) metadataErrors . push ( 'Intended Use' ) ;
232238 if ( ! metadata . modelWebsite ) metadataErrors . push ( 'Model Website' ) ;
233239 if ( ! model ?. maxTokens ) metadataErrors . push ( 'Maximum Tokens' ) ;
234- if ( ! model ?. supportedLanguages ?. length ) metadataErrors . push ( 'Supported Languages' ) ;
240+ if ( ! model ?. supportedLanguages ?. length )
241+ metadataErrors . push ( 'Supported Languages' ) ;
235242 if ( ! model ?. modelType ) metadataErrors . push ( 'Model Type' ) ;
236243
237244 const versionErrors = [ ] ;
@@ -271,7 +278,9 @@ export default function PublishPage() {
271278 version : v . version ,
272279 lifecycleStage : lifecycleLabels [ v . lifecycleStage ] || v . lifecycleStage ,
273280 providers : v . providers ?. length
274- ? v . providers . map ( ( p : any ) => providerLabels [ p . provider ] || p . provider ) . join ( ', ' )
281+ ? v . providers
282+ . map ( ( p : any ) => providerLabels [ p . provider ] || p . provider )
283+ . join ( ', ' )
275284 : 'None' ,
276285 primary : v . isLatest ? 'Yes' : 'No' ,
277286 } ) ) ;
@@ -288,7 +297,7 @@ export default function PublishPage() {
288297 } ,
289298 {
290299 label : 'Domain' ,
291- value : model ?. domain ? ( domainLabels [ model . domain ] || model . domain ) : '' ,
300+ value : model ?. domain ? domainLabels [ model . domain ] || model . domain : '' ,
292301 } ,
293302 {
294303 label : 'Target Users' ,
@@ -308,7 +317,9 @@ export default function PublishPage() {
308317 } ,
309318 {
310319 label : 'Supported Languages' ,
311- value : model ?. supportedLanguages ?. length ? model . supportedLanguages . join ( ', ' ) : '' ,
320+ value : model ?. supportedLanguages ?. length
321+ ? model . supportedLanguages . join ( ', ' )
322+ : '' ,
312323 } ,
313324 ] ;
314325
@@ -391,10 +402,7 @@ export default function PublishPage() {
391402
392403 { model ?. description && (
393404 < div className = "flex flex-wrap gap-2" >
394- < Text
395- className = "lg:basis-1/6"
396- variant = "bodyMd"
397- >
405+ < Text className = "lg:basis-1/6" variant = "bodyMd" >
398406 Description:
399407 </ Text >
400408 < div className = "lg:basis-4/5" >
@@ -411,11 +419,9 @@ export default function PublishPage() {
411419 </ Text >
412420 < div className = "flex gap-2 lg:basis-4/5" >
413421 { model ?. sectors ?. length > 0 ? (
414- model . sectors . map (
415- ( s : any , idx : number ) => (
416- < Tag key = { idx } > { s . name } </ Tag >
417- )
418- )
422+ model . sectors . map ( ( s : any , idx : number ) => (
423+ < Tag key = { idx } > { s . name } </ Tag >
424+ ) )
419425 ) : (
420426 < Text variant = "bodyMd" color = "subdued" >
421427 None
@@ -430,11 +436,9 @@ export default function PublishPage() {
430436 </ Text >
431437 < div className = "flex gap-2 lg:basis-4/5" >
432438 { model ?. tags ?. length > 0 ? (
433- model . tags . map (
434- ( t : any , idx : number ) => (
435- < Tag key = { idx } > { t . value } </ Tag >
436- )
437- )
439+ model . tags . map ( ( t : any , idx : number ) => (
440+ < Tag key = { idx } > { t . value } </ Tag >
441+ ) )
438442 ) : (
439443 < Text variant = "bodyMd" color = "subdued" >
440444 None
@@ -472,7 +476,11 @@ export default function PublishPage() {
472476 hideFooter
473477 />
474478 ) : (
475- < Text variant = "bodyMd" color = "subdued" className = "px-4 py-2" >
479+ < Text
480+ variant = "bodyMd"
481+ color = "subdued"
482+ className = "px-4 py-2"
483+ >
476484 No versions found
477485 </ Text >
478486 ) }
@@ -486,27 +494,27 @@ export default function PublishPage() {
486494
487495 { /* Publication Status */ }
488496 { isPublished ? (
489- < div className = "rounded-1 border border-tertiaryAccent bg-tertiaryAccent/10 p-4" >
497+ < div className = "border bg-tertiaryAccent/10 rounded-1 border-tertiaryAccent p-4" >
490498 < div className = "flex items-center gap-2" >
491499 < Icon source = { Icons . check } color = "success" size = { 24 } />
492500 < Text variant = "headingSm" className = "text-primaryText" >
493501 Model is Published and Active
494502 </ Text >
495503 </ div >
496- < Text variant = "bodySm" className = "mt-2 text-primaryText/80" >
504+ < Text variant = "bodySm" className = "text-primaryText/80 mt-2 " >
497505 Your AI model is now publicly accessible and can be
498506 discovered by other users.
499507 </ Text >
500508 </ div >
501509 ) : (
502- < div className = "rounded-1 border border-secondaryOrange bg-secondaryOrange/10 p-4" >
510+ < div className = "border bg-secondaryOrange/10 rounded-1 border-secondaryOrange p-4" >
503511 < div className = "flex items-center gap-2" >
504512 < Icon source = { Icons . alert } color = "warning" size = { 24 } />
505513 < Text variant = "headingSm" className = "text-secondaryText" >
506514 Model is not published
507515 </ Text >
508516 </ div >
509- < Text variant = "bodySm" className = "mt-2 text-secondaryText/80" >
517+ < Text variant = "bodySm" className = "text-secondaryText/80 mt-2 " >
510518 { ! isPublishDisabled
511519 ? 'All checklist items are complete. You can now publish your model.'
512520 : 'Complete all required fields before publishing your model.' }
0 commit comments