11import { useEffect , useState } from 'react' ;
2- import { useParams } from 'next/navigation' ;
2+ import { useParams , useRouter } from 'next/navigation' ;
33import { graphql } from '@/gql' ;
44import { ResourceChartImageInput } from '@/gql/generated/graphql' ;
55import { useMutation , useQuery } from '@tanstack/react-query' ;
@@ -111,6 +111,8 @@ const ChartImageUpload = ({
111111
112112 const [ selectedDataset , setSelectedDataset ] = useState < any > ( null ) ;
113113
114+ const router = useRouter ( ) ;
115+
114116 const createResourceChartImageMutation : {
115117 mutate : any ;
116118 isLoading : boolean ;
@@ -126,8 +128,12 @@ const ChartImageUpload = ({
126128 { input : input }
127129 ) ,
128130 {
129- onSuccess : ( ) => {
131+ onSuccess : ( resp : any ) => {
130132 toast ( `Created chart image successfully` ) ;
133+ // Navigate to chart image preview page
134+ router . push (
135+ `/dashboard/${ params . entityType } /${ params . entitySlug } /charts/${ resp ?. createResourceChartImage ?. id } ?type=TypeResourceChartImage`
136+ ) ;
131137 } ,
132138 onError : ( err : any ) => {
133139 toast ( 'Error: ' + err . message . split ( ':' ) [ 0 ] ) ;
@@ -136,10 +142,9 @@ const ChartImageUpload = ({
136142 ) ;
137143
138144 const handleAddImage = ( ) => {
139- console . log ( 'Add Image :::' , selectedDataset , files ) ;
140145 if ( selectedDataset && files ) {
141146 createResourceChartImageMutation . mutate ( {
142- dataset : { set : selectedDataset } ,
147+ dataset : selectedDataset ,
143148 image : files ,
144149 } ) ;
145150 }
@@ -178,7 +183,6 @@ const ChartImageUpload = ({
178183 label = "Select Chart Image"
179184 accept = ".png,.jpg,.jpeg,.svg,.tiff"
180185 onDrop = { ( val ) => {
181- console . log ( 'drop ::' , val ) ;
182186 setFiles ( val [ 0 ] ) ;
183187 } }
184188 outline
0 commit comments