-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tooltip for deactivated AddProposalButton
(#3909)
#3916
base: dev
Are you sure you want to change the base?
Changes from 7 commits
4b1ed94
c09a9f9
a7dda8f
24b9037
f7461cc
33db75f
21a8bae
8cf5534
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,46 @@ | ||
import React, { useCallback } from 'react' | ||
import React, { useCallback, useMemo } from 'react' | ||
|
||
import { useApi } from '@/api/hooks/useApi' | ||
import { TransactionButton } from '@/common/components/buttons/TransactionButton' | ||
import { PlusIcon } from '@/common/components/icons/PlusIcon' | ||
import { Tooltip } from '@/common/components/Tooltip' | ||
import { useFirstObservableValue } from '@/common/hooks/useFirstObservableValue' | ||
import { useModal } from '@/common/hooks/useModal' | ||
import { AddNewProposalModalCall } from '@/proposals/modals/AddNewProposal' | ||
|
||
export const AddProposalButton = () => { | ||
const { api } = useApi() | ||
const { showModal } = useModal() | ||
const addNewProposalModal = useCallback(() => { | ||
showModal<AddNewProposalModalCall>({ | ||
modal: 'AddNewProposalModal', | ||
}) | ||
}, []) | ||
const addProposalModal = useCallback(() => showModal<AddNewProposalModalCall>({ modal: 'AddNewProposalModal' }), []) | ||
|
||
const { api } = useApi() | ||
const maxProposals = api?.consts.proposalsEngine.maxActiveProposalLimit | ||
const currentProposals = useFirstObservableValue( | ||
() => api?.query.proposalsEngine.activeProposalCount(), | ||
[api?.isConnected] | ||
) | ||
const areProposalSlotsAvailable = api && maxProposals && currentProposals?.lt(maxProposals) | ||
const maxProposals = useMemo(() => api?.consts.proposalsEngine.maxActiveProposalLimit, [api?.isConnected]) | ||
const proposals = useFirstObservableValue(() => api?.query.proposalsEngine.activeProposalCount(), [api?.isConnected]) | ||
const availableSlots = useMemo(() => Number(maxProposals) - Number(proposals), [proposals, maxProposals]) | ||
|
||
const tooltipProps = useMemo(() => { | ||
if (!api?.isConnected) return { tooltipText: 'Connecting to api' } | ||
if (!api?.isConnected || availableSlots > 0) { | ||
return { | ||
tooltipText: 'Use the proposal engine to suggest a change to the Council.', | ||
tooltipLinkText: 'Learn about the Proposal System', | ||
tooltipLinkURL: 'https://joystream.gitbook.io/testnet-workspace/system/proposal-system', | ||
} | ||
} else { | ||
return { | ||
tooltipTitle: 'Max active proposals limit reached', | ||
tooltipText: `The creation of proposals is currently disabled because the number of deciding or gracing proposals reached the limit of ${maxProposals}.`, | ||
tooltipLinkText: 'Proposal System Constants', | ||
tooltipLinkURL: 'https://joystream.gitbook.io/testnet-workspace/system/proposal-system#constants', | ||
} | ||
} | ||
}, [api?.isConnected, availableSlots]) | ||
|
||
return ( | ||
<TransactionButton | ||
style="primary" | ||
size="medium" | ||
onClick={addNewProposalModal} | ||
disabled={!areProposalSlotsAvailable} | ||
> | ||
<PlusIcon /> | ||
Add new proposal | ||
</TransactionButton> | ||
<Tooltip placement="bottom-end" {...tooltipProps}> | ||
<TransactionButton style="primary" size="medium" onClick={addProposalModal} disabled={!availableSlots}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
WDYT ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes sense. |
||
<PlusIcon /> | ||
Add new proposal | ||
</TransactionButton> | ||
</Tooltip> | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new logic is that until connection is established and when there are slots the default tooltip is shown. Without the first condition a user would see the error "Max active proposals limit reached" during loading.