1- import React from 'react' ;
2- import Link from 'next/link' ;
3- import { useParams } from 'next/navigation' ;
4- import { graphql } from '@/gql' ;
51import { CreateFileResourceInput } from '@/gql/generated/graphql' ;
6- import { useMutation , useQuery } from '@tanstack/react-query' ;
7- import {
8- parseAsBoolean ,
9- parseAsString ,
10- useQueryState ,
11- } from 'next-usequerystate' ;
2+ import { useMutation } from '@tanstack/react-query' ;
3+ import { parseAsString , useQueryState } from 'next-usequerystate' ;
4+ import { useParams , useRouter } from 'next/navigation' ;
125import {
136 Button ,
147 DataTable ,
158 Dialog ,
169 DropZone ,
17- Icon ,
1810 IconButton ,
1911 SearchInput ,
20- Spinner ,
2112 Text ,
22- TextField ,
2313 toast ,
2414} from 'opub-ui' ;
15+ import React from 'react' ;
2516
17+ import { Icons } from '@/components/icons' ;
18+ import { Loading } from '@/components/loading' ;
2619import { GraphQL } from '@/lib/api' ;
2720import { formatDate } from '@/lib/utils' ;
28- import { Icons } from '@/components/icons' ;
29- import { createResourceFilesDoc , updateResourceList } from './query' ;
21+ import { createResourceFilesDoc , updateResourceList } from './query' ;
3022
3123type FilteredRow = {
3224 name_of_resource : string ;
@@ -36,13 +28,16 @@ type FilteredRow = {
3628} ;
3729
3830type ResourceListProps = {
39- data : any [ ] ;
31+ data : any [ ] ;
4032 refetch : ( ) => void ;
41- }
33+ } ;
4234
4335export const ResourceListView = ( { data, refetch } : ResourceListProps ) => {
44-
4536 const [ resourceId , setResourceId ] = useQueryState ( 'id' , parseAsString ) ;
37+ const [ file , setFile ] = React . useState < File [ ] > ( [ ] ) ;
38+
39+ const router = useRouter ( ) ;
40+ const params = useParams ( ) ;
4641
4742 const updateResourceMutation = useMutation (
4843 ( data : { resourceId : string } ) => GraphQL ( updateResourceList , data ) ,
@@ -84,21 +79,24 @@ export const ResourceListView = ({ data, refetch }: ResourceListProps) => {
8479 ] ) ;
8580
8681 refetch ( ) ;
82+
8783 toast ( 'Resource Added Successfully' , {
8884 action : {
8985 label : 'Dismiss' ,
9086 onClick : ( ) => { } ,
9187 } ,
9288 } ) ;
89+
90+ router . push (
91+ `/dashboard/organization/${ params . organizationId } /dataset/${ params . id } /edit/resources?id=${ data . createFileResources [ 0 ] ?. id } `
92+ ) ;
9393 } ,
9494 onError : ( err : any ) => {
9595 console . log ( 'Error ::: ' , err ) ;
9696 } ,
9797 }
9898 ) ;
9999
100- const params = useParams ( ) ;
101-
102100 const deleteRow = ( row : any ) => {
103101 updateResourceMutation . mutate ( {
104102 resourceId : row . id ,
@@ -154,11 +152,11 @@ export const ResourceListView = ({ data, refetch }: ResourceListProps) => {
154152
155153 rows :
156154 data . map ( ( item : any ) => ( {
157- name_of_resource : item . name ,
158- type : item . type ,
159- date_added : formatDate ( item . created ) ,
160- id : item . id ,
161- } ) ) || [ ] ,
155+ name_of_resource : item . name ,
156+ type : item . type ,
157+ date_added : formatDate ( item . created ) ,
158+ id : item . id ,
159+ } ) ) || [ ] ,
162160 } ;
163161
164162 const [ filteredRows , setFilteredRows ] = React . useState < FilteredRow [ ] > (
@@ -177,8 +175,6 @@ export const ResourceListView = ({ data, refetch }: ResourceListProps) => {
177175 ( column ) => column . accessorKey !== 'id'
178176 ) ;
179177
180- const [ file , setFile ] = React . useState < File [ ] > ( [ ] ) ;
181-
182178 const dropZone = React . useCallback (
183179 ( _dropFiles : File [ ] , acceptedFiles : File [ ] ) => {
184180 createResourceMutation . mutate ( {
@@ -220,10 +216,18 @@ export const ResourceListView = ({ data, refetch }: ResourceListProps) => {
220216 </ Button >
221217 </ Dialog . Trigger >
222218 < Dialog . Content title = { 'Add New Resource' } >
223- < DropZone name = "file_upload" allowMultiple = { true } onDrop = { dropZone } >
224- { uploadedFile }
225- { file . length === 0 && < DropZone . FileUpload /> }
226- </ DropZone >
219+ { createResourceMutation . isLoading ? (
220+ < Loading />
221+ ) : (
222+ < DropZone
223+ name = "file_upload"
224+ allowMultiple = { true }
225+ onDrop = { dropZone }
226+ >
227+ { uploadedFile }
228+ { file . length === 0 && < DropZone . FileUpload /> }
229+ </ DropZone >
230+ ) }
227231 </ Dialog . Content >
228232 </ Dialog >
229233 </ div >
0 commit comments