11'use client'
22
33import { DidMethod , SchemaTypes } from '@/common/enums'
4- import { IW3cSchemaDetails , SchemaListItem } from '../type/schemas-interface'
4+ import { IAttributesDetails , IW3cSchemaDetails , SchemaListItem } from '../type/schemas-interface'
55import {
66 Pagination ,
77 PaginationContent ,
@@ -36,12 +36,6 @@ import { getOrganizationById } from '@/app/api/organization'
3636import { getUserProfile } from '@/app/api/Auth'
3737import { useRouter } from 'next/navigation'
3838
39- interface IAttributesDetails {
40- attributeName : string
41- schemaDataType : string
42- displayName : string
43- isRequired : boolean
44- }
4539export interface ISchemaData {
4640 createDateTime : string
4741 name : string
@@ -185,7 +179,7 @@ const SchemaList = (props: {
185179 if ( data ?. statusCode === apiStatusCodes . API_STATUS_SUCCESS ) {
186180 const schemaData = data ?. data ?. data
187181 if ( data ?. data ?. data ) {
188- setLastPage ( data ?. data ?. lastPage )
182+ setLastPage ( data ?. data ?. lastPage - 1 )
189183 setTotalItem ( data ?. data ?. totalItems )
190184 setSchemaList ( [ ...schemaData ] )
191185 } else {
@@ -259,7 +253,11 @@ const SchemaList = (props: {
259253 if ( organizationId ) {
260254 getSchemaList ( schemaListAPIParameter , allSchemaFlag )
261255 }
262- } , [ schemaListAPIParameter . page ] )
256+ } , [
257+ schemaListAPIParameter . page ,
258+ schemaListAPIParameter . allSearch ,
259+ schemaListAPIParameter . search ,
260+ ] )
263261
264262 const onSearch = ( event : ChangeEvent < HTMLInputElement > ) : void => {
265263 const inputValue = event . target . value
@@ -426,7 +424,7 @@ const SchemaList = (props: {
426424 </ Button >
427425 </ div >
428426
429- { loading ? (
427+ { loading && (
430428 < div className = "grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-2" >
431429 { [ ...Array ( 4 ) ] . map ( ( _ , idx ) => (
432430 < div key = { idx } className = "space-y-3 rounded-lg p-4 shadow-sm" >
@@ -438,7 +436,9 @@ const SchemaList = (props: {
438436 </ div >
439437 ) ) }
440438 </ div >
441- ) : schemaList . length ? (
439+ ) }
440+
441+ { ! loading && ( schemaList . length ? (
442442 < >
443443 < div className = "grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-2" >
444444 { schemaList . map ( ( element ) => (
@@ -464,68 +464,70 @@ const SchemaList = (props: {
464464 </ div >
465465 ) ) }
466466 </ div >
467- { totalItem > itemPerPage && (
468- < div className = "mt-6 flex justify-end" >
469- < Pagination className = "m-0 w-fit" >
470- < PaginationContent >
471- { schemaListAPIParameter . page > 1 && (
472- < PaginationItem >
473- < PaginationPrevious
474- href = "#"
475- onClick = { ( ) =>
476- setSchemaListAPIParameter ( ( prev ) => ( {
477- ...prev ,
478- page : prev . page - 1 ,
479- } ) )
480- }
481- />
482- </ PaginationItem >
483- ) }
484-
485- { paginationNumbers . map ( ( page , idx ) => (
486- < PaginationItem key = { idx } >
487- { page === '...' ? (
488- < span className = "text-muted-foreground px-3 py-2" >
489- …
490- </ span >
491- ) : (
492- < PaginationLink
493- className = { `${
494- page === schemaListAPIParameter . page
495- ? 'bg-primary text-white'
496- : 'bg-background text-muted-foreground'
497- } rounded-lg px-4 py-2`}
467+ { totalItem > itemPerPage &&
468+ ( schemaList . length === itemPerPage ||
469+ schemaListAPIParameter . page === lastPage ) && (
470+ < div className = "mt-6 flex justify-end" >
471+ < Pagination className = "m-0 w-fit" >
472+ < PaginationContent >
473+ { schemaListAPIParameter . page > 1 && (
474+ < PaginationItem >
475+ < PaginationPrevious
498476 href = "#"
499477 onClick = { ( ) =>
500478 setSchemaListAPIParameter ( ( prev ) => ( {
501479 ...prev ,
502- page : page as number ,
480+ page : prev . page - 1 ,
503481 } ) )
504482 }
505- >
506- { page }
507- </ PaginationLink >
508- ) }
509- </ PaginationItem >
510- ) ) }
511-
512- { schemaListAPIParameter . page < lastPage && (
513- < PaginationItem >
514- < PaginationNext
515- href = "#"
516- onClick = { ( ) =>
517- setSchemaListAPIParameter ( ( prev ) => ( {
518- ...prev ,
519- page : prev . page + 1 ,
520- } ) )
521- }
522- />
523- </ PaginationItem >
524- ) }
525- </ PaginationContent >
526- </ Pagination >
527- </ div >
528- ) }
483+ />
484+ </ PaginationItem >
485+ ) }
486+
487+ { paginationNumbers . map ( ( page , idx ) => (
488+ < PaginationItem key = { idx } >
489+ { page === '...' ? (
490+ < span className = "text-muted-foreground px-3 py-2" >
491+ …
492+ </ span >
493+ ) : (
494+ < PaginationLink
495+ className = { `${
496+ page === schemaListAPIParameter . page
497+ ? 'bg-primary text-white'
498+ : 'bg-background text-muted-foreground'
499+ } rounded-lg px-4 py-2`}
500+ href = "#"
501+ onClick = { ( ) =>
502+ setSchemaListAPIParameter ( ( prev ) => ( {
503+ ...prev ,
504+ page : page as number ,
505+ } ) )
506+ }
507+ >
508+ { page }
509+ </ PaginationLink >
510+ ) }
511+ </ PaginationItem >
512+ ) ) }
513+
514+ { schemaListAPIParameter . page < lastPage && (
515+ < PaginationItem >
516+ < PaginationNext
517+ href = "#"
518+ onClick = { ( ) =>
519+ setSchemaListAPIParameter ( ( prev ) => ( {
520+ ...prev ,
521+ page : prev . page + 1 ,
522+ } ) )
523+ }
524+ />
525+ </ PaginationItem >
526+ ) }
527+ </ PaginationContent >
528+ </ Pagination >
529+ </ div >
530+ ) }
529531 </ >
530532 ) : (
531533 < EmptyMessage
@@ -540,7 +542,7 @@ const SchemaList = (props: {
540542 } }
541543 disabled = { orgRole !== 'admin' && orgRole !== 'owner' }
542544 />
543- ) }
545+ ) ) }
544546 </ div >
545547 </ PageContainer >
546548 )
0 commit comments