@@ -35,6 +35,7 @@ import { Props, PAGE_SIZE } from './ThirdPartyCollectionDetailPage.types'
35
35
import { CollectionItemHeader } from './CollectionItemHeader'
36
36
import { CollectionItemHeaderV2 } from './CollectionItemHeaderV2'
37
37
import styles from './ThirdPartyCollectionDetailPage.module.css'
38
+ import { ItemMappingStatus } from 'lib/api/builder'
38
39
39
40
const Info = ( { children, title, info } : { children : React . ReactNode ; title : string ; info ?: string } ) => (
40
41
< div className = { styles . info } >
@@ -45,6 +46,14 @@ const Info = ({ children, title, info }: { children: React.ReactNode; title: str
45
46
</ div >
46
47
)
47
48
49
+ enum ItemStatus {
50
+ ALL = 'ALL' ,
51
+ SYNCED = 'SYNCED' ,
52
+ UNSYNCED = 'UNSYNCED' ,
53
+ MIGRATION_REQUIRED = 'MIGRATION_REQUIRED' ,
54
+ MAPPING_PENDING = 'MAPPING_PENDING'
55
+ }
56
+
48
57
export default function ThirdPartyCollectionDetailPage ( {
49
58
currentPage,
50
59
wallet,
@@ -62,7 +71,7 @@ export default function ThirdPartyCollectionDetailPage({
62
71
const [ page , setPage ] = useState ( currentPage )
63
72
const [ showSelectAllPages , setShowSelectAllPages ] = useState ( false )
64
73
const [ shouldFetchAllPages , setShouldFetchAllPages ] = useState ( false )
65
- const [ filters , setFilters ] = useState < Record < string , any > > ( { } )
74
+ const [ itemStatus , setItemStatus ] = useState < ItemStatus > ( ItemStatus . ALL )
66
75
const history = useHistory ( )
67
76
68
77
useEffect ( ( ) => {
@@ -72,9 +81,6 @@ export default function ThirdPartyCollectionDetailPage({
72
81
} , [ ] )
73
82
74
83
useEffect ( ( ) => {
75
- if ( thirdParty && thirdParty . availableSlots === undefined && ! isLoadingAvailableSlots ) {
76
- onFetchAvailableSlots ( thirdParty . id )
77
- }
78
84
// update the state if the page query param changes
79
85
if ( currentPage !== page ) {
80
86
setPage ( currentPage )
@@ -89,7 +95,7 @@ export default function ThirdPartyCollectionDetailPage({
89
95
setSelectedItems ( selectedItems )
90
96
setShowSelectAllPages ( false )
91
97
}
92
- } , [ page , shouldFetchAllPages , items , thirdParty , isLoadingAvailableSlots , onFetchAvailableSlots , currentPage ] )
98
+ } , [ page , shouldFetchAllPages , items , thirdParty , currentPage ] )
93
99
94
100
const handleNewItems = useCallback ( ( ) => {
95
101
onOpenModal ( 'CreateItemsModal' , { collectionId : collection ! . id } )
@@ -173,11 +179,38 @@ export default function ThirdPartyCollectionDetailPage({
173
179
174
180
const handleChangeStatus = useCallback (
175
181
( _event : React . SyntheticEvent < HTMLElement , Event > , { value } : DropdownProps ) => {
176
- setFilters ( { synced : value as boolean } )
182
+ setItemStatus ( value as ItemStatus )
177
183
} ,
178
- [ setFilters ]
184
+ [ setItemStatus ]
179
185
)
180
186
187
+ const itemStatusOptions = [
188
+ { value : ItemStatus . ALL , text : t ( 'third_party_collection_detail_page.synced_filter.all' ) } ,
189
+ { value : ItemStatus . SYNCED , text : t ( 'item_status.synced' ) } ,
190
+ { value : ItemStatus . UNSYNCED , text : t ( 'item_status.unsynced' ) } ,
191
+ ...( ! collection ?. isMappingComplete
192
+ ? [
193
+ { value : ItemStatus . MIGRATION_REQUIRED , text : t ( 'item_status.pending_migration' ) } ,
194
+ { value : ItemStatus . MAPPING_PENDING , text : t ( 'item_status.pending_mapping' ) }
195
+ ]
196
+ : [ ] )
197
+ ]
198
+
199
+ const itemFilters = useMemo ( ( ) => {
200
+ switch ( itemStatus ) {
201
+ case ItemStatus . SYNCED :
202
+ return { synced : true }
203
+ case ItemStatus . UNSYNCED :
204
+ return { synced : false }
205
+ case ItemStatus . MIGRATION_REQUIRED :
206
+ return { mappingStatus : ItemMappingStatus . UNPUBLISHED_MAPPING }
207
+ case ItemStatus . MAPPING_PENDING :
208
+ return { mappingStatus : ItemMappingStatus . MISSING_MAPPING }
209
+ default :
210
+ return { }
211
+ }
212
+ } , [ itemStatus ] )
213
+
181
214
const renderPage = useCallback (
182
215
( thirdParty : ThirdParty , allItems : Item [ ] , paginatedItems : Item [ ] , onFetchCollectionItemsPages : typeof fetchCollectionItemsRequest ) => {
183
216
const allSelectedItems = allItems . filter ( item => selectedItems [ item . id ] )
@@ -257,13 +290,8 @@ export default function ThirdPartyCollectionDetailPage({
257
290
< Dropdown
258
291
className = { styles . syncedStatusList }
259
292
direction = "left"
260
- value = { filters . synced }
261
- placeholder = { t ( 'third_party_collection_detail_page.synced_filter.all' ) }
262
- options = { [
263
- { value : undefined , text : t ( 'third_party_collection_detail_page.synced_filter.all' ) } ,
264
- { value : true , text : t ( 'third_party_collection_detail_page.synced_filter.synced' ) } ,
265
- { value : false , text : t ( 'third_party_collection_detail_page.synced_filter.unsynced' ) }
266
- ] }
293
+ value = { itemStatus }
294
+ options = { itemStatusOptions }
267
295
onChange = { handleChangeStatus }
268
296
/>
269
297
</ div >
@@ -365,13 +393,13 @@ export default function ThirdPartyCollectionDetailPage({
365
393
areAllSelected ,
366
394
handleChangeStatus ,
367
395
handleClearSelection ,
368
- filters
396
+ itemStatus
369
397
]
370
398
)
371
399
372
400
const shouldRender = hasAccess && collection
373
401
return (
374
- < CollectionProvider id = { collection ?. id } itemsPage = { page } itemsPageSize = { PAGE_SIZE } fetchOptions = { filters } >
402
+ < CollectionProvider id = { collection ?. id } itemsPage = { page } itemsPageSize = { PAGE_SIZE } fetchCollectionItemsOptions = { itemFilters } >
375
403
{ ( { isLoading : isLoadingCollectionData , items, paginatedItems, onFetchCollectionItemsPages } ) => (
376
404
< LoggedInDetailPage
377
405
className = { styles . main }
0 commit comments