Skip to content

Commit

Permalink
fix: Fix CollectionItem state
Browse files Browse the repository at this point in the history
  • Loading branch information
fzavalia committed Sep 30, 2021
1 parent 6c96412 commit 3e4a227
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const mapState = (state: RootState, ownProps: OwnProps): MapStateProps => {
items: getCollectionItems(state, collectionId),
authorizations: getAuthorizations(state),
status: statusByCollectionId[collectionId],
isAwaitingCuration: getHasPendingCuration(state, collectionId)
hasPendingCuration: getHasPendingCuration(state, collectionId)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import { AuthorizationType } from 'decentraland-dapps/dist/modules/authorization
import { hasAuthorization } from 'decentraland-dapps/dist/modules/authorization/utils'
import { ContractName, getContract } from 'decentraland-transactions'
import { AuthorizationModal } from 'components/AuthorizationModal'
import { SyncStatus } from 'modules/item/types'
import { isComplete } from 'modules/item/utils'
import { Props } from './CollectionAction.types'
import { SyncStatus } from 'modules/item/types'

const CollectionAction = ({ wallet, collection, items, authorizations, status, isAwaitingCuration, onPublish, onPush, onInit }: Props) => {
const CollectionAction = ({ wallet, collection, items, authorizations, status, hasPendingCuration, onPublish, onPush, onInit }: Props) => {
const [isAuthModalOpen, setIsAuthModalOpen] = useState(false)

useEffect(() => {
Expand Down Expand Up @@ -49,30 +49,28 @@ const CollectionAction = ({ wallet, collection, items, authorizations, status, i
setIsAuthModalOpen(false)
}

const isPublishUnderReview = collection.isPublished && !collection.isApproved
const isPublishedAndApproved = collection.isPublished && collection.isApproved
const isCollectionUnsynced = isPublishedAndApproved && status === SyncStatus.UNSYNCED
const areChangesUnderReview = isCollectionUnsynced && isAwaitingCuration
const canChangesBePushed = isCollectionUnsynced && !isAwaitingCuration

let button: ReactNode

if (areChangesUnderReview) {
button = <UnderReview type="push" />
} else if (canChangesBePushed) {
button = (
<Button primary compact onClick={onPush}>
{t('collection_detail_page.push_changes')}
</Button>
)
} else if (isPublishedAndApproved) {
button = (
<Button secondary compact disabled={true}>
{t('global.published')}
</Button>
)
} else if (isPublishUnderReview) {
button = <UnderReview type="publish" />
if (collection.isPublished) {
if (collection.isApproved) {
if (hasPendingCuration) {
button = <UnderReview type="push" />
} else if (status === SyncStatus.UNSYNCED) {
button = (
<Button primary compact onClick={onPush}>
{t('collection_detail_page.push_changes')}
</Button>
)
} else {
button = (
<Button secondary compact disabled={true}>
{t('global.published')}
</Button>
)
}
} else {
button = <UnderReview type="publish" />
}
} else {
button = (
<ChainButton disabled={isPublishDisabled()} primary compact onClick={handlePublish} chainId={getChainIdByNetwork(Network.MATIC)}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ export type Props = {
items: Item[]
authorizations: Authorization[]
status: SyncStatus
isAwaitingCuration: boolean
hasPendingCuration: boolean
onPublish: () => void
onPush: () => void
onInit: () => void
}

export type OwnProps = Pick<Props, 'collection'>
export type MapStateProps = Pick<Props, 'wallet' | 'items' | 'authorizations' | 'status' | 'isAwaitingCuration'>
export type MapStateProps = Pick<Props, 'wallet' | 'items' | 'authorizations' | 'status' | 'hasPendingCuration'>
export type MapDispatchProps = Pick<Props, 'onPublish' | 'onPush' | 'onInit'>
export type MapDispatch = Dispatch<OpenModalAction | FetchCurationRequestAction>

0 comments on commit 3e4a227

Please sign in to comment.