Skip to content

Commit

Permalink
Show new invitation quota on ProposalDetails (#3902) (#3926)
Browse files Browse the repository at this point in the history
* Show new invitation quota on `ProposalDetails` (#3902)

* Generate SetMembershipLeadInvitationQuotaProposalDetails

* fix amount -> count type in `ProposalDetails`

* Do not use currency for setMembershipLeadInvitationQuota

* lint

* fix field and test

Co-authored-by: Joystream Stats <[email protected]>
Co-authored-by: Oleksandr Korniienko <[email protected]>
  • Loading branch information
3 people authored Dec 12, 2022
1 parent f3345e6 commit 1b163bc
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useEffect } from 'react'
import { useFormContext } from 'react-hook-form'

import { CurrencyName } from '@/app/constants/currency'
import { InputComponent, InputNumber } from '@/common/components/forms'
import { Row } from '@/common/components/Modal'
import { RowGapBlock } from '@/common/components/page/PageContent'
Expand Down Expand Up @@ -29,22 +28,20 @@ export const SetMembershipLeadInvitationQuota = () => {
<Row>
<RowGapBlock gap={20}>
<InputComponent
label="Lead Invitation Quota Amount"
label="Lead Invitation Quota"
tight
units={CurrencyName.integerValue}
required
disabled={isLoading || !group?.leadId}
name="setMembershipLeadInvitationQuota.amount"
name="setMembershipLeadInvitationQuota.count"
message={
!group?.leadId
? "Proposal can't be created because there's no working group lead"
: 'Amount must be greater than zero'
: 'Quota must be greater than zero'
}
>
<InputNumber
id="amount-input"
name="setMembershipLeadInvitationQuota.amount"
isInBN
name="setMembershipLeadInvitationQuota.count"
placeholder="0"
maxAllowedValue={Math.pow(2, 32) - 1}
disabled={isLoading || !group?.leadId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export const getSpecificParameters = (
}
case 'setMembershipLeadInvitationQuota': {
return createType('PalletProposalsCodexProposalDetails', {
SetMembershipLeadInvitationQuota: specifics?.setMembershipLeadInvitationQuota?.amount ?? BN_ZERO,
SetMembershipLeadInvitationQuota: specifics?.setMembershipLeadInvitationQuota?.count ?? 0,
})
}
case 'setReferralCut': {
Expand All @@ -164,7 +164,7 @@ export const getSpecificParameters = (
}
case 'setInitialInvitationCount': {
return createType('PalletProposalsCodexProposalDetails', {
SetInitialInvitationCount: specifics?.setInitialInvitationCount?.invitationCount ?? BN_ZERO,
SetInitialInvitationCount: specifics?.setInitialInvitationCount?.invitationCount ?? 0,
})
}
case 'setMaxValidatorCount': {
Expand Down
6 changes: 3 additions & 3 deletions packages/ui/src/proposals/modals/AddNewProposal/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ export interface AddNewProposalForm {
groupId?: GroupIdName
}
setInitialInvitationCount: {
invitationCount?: BN
invitationCount?: number
}
setReferralCut: {
referralCut?: number
}
setMembershipLeadInvitationQuota: {
amount?: BN
count?: number
leadId?: string
}
setInitialInvitationBalance: {
Expand Down Expand Up @@ -296,7 +296,7 @@ export const schemaFactory = (api?: ProxyApi) => {
.required('Field is required'),
}),
setMembershipLeadInvitationQuota: Yup.object().shape({
amount: BNSchema.test(moreThanMixed(0, 'Amount must be greater than zero')).required('Field is required'),
count: BNSchema.test(moreThanMixed(0, 'Quota must be greater than zero')).required('Field is required'),
leadId: Yup.string().test('execution', (value) => !!value),
}),
setInitialInvitationBalance: Yup.object().shape({
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/ui/src/proposals/queries/proposals.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ fragment ProposalWithDetailsFields on Proposal {
... on SetCouncilBudgetIncrementProposalDetails {
newAmount
}
... on SetMembershipLeadInvitationQuotaProposalDetails {
newLeadInvitationQuota
}
... on SignalProposalDetails {
text
}
Expand Down
17 changes: 14 additions & 3 deletions packages/ui/src/proposals/types/ProposalDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export type GroupNameDetail = {
}

export type CountDetail = {
count: BN
count: number
}

export type ProposalDetail = {
Expand Down Expand Up @@ -110,6 +110,8 @@ export type SignalDetails = ProposalDetailsNew<'signal', SignalTextDetail>

export type SetMembershipPriceDetails = ProposalDetailsNew<'setMembershipPrice', AmountDetail>

export type SetMembershipLeadInvitationQuota = ProposalDetailsNew<'setMembershipLeadInvitationQuota', CountDetail>

export type SetCouncilBudgetIncrementDetails = ProposalDetailsNew<'setCouncilBudgetIncrement', AmountDetail>

export type CancelWorkingGroupLeadOpeningDetails = ProposalDetailsNew<
Expand Down Expand Up @@ -140,6 +142,7 @@ export type ProposalDetails =
| SetWorkingGroupLeadRewardDetails
| TerminateWorkingGroupLeadDetails
| SetMembershipPriceDetails
| SetMembershipLeadInvitationQuota
| SetCouncilBudgetIncrementDetails
| SignalDetails
| CancelWorkingGroupLeadOpeningDetails
Expand Down Expand Up @@ -230,7 +233,7 @@ const asSetMaxValidatorCount: DetailsCast<'SetMaxValidatorCountProposalDetails'>
fragment
): MaxValidatorCountDetails => ({
type: 'setMaxValidatorCount',
count: new BN(fragment.newMaxValidatorCount),
count: fragment.newMaxValidatorCount,
})

const asFillGroupLeadOpening: DetailsCast<'FillWorkingGroupLeadOpeningProposalDetails'> = (
Expand Down Expand Up @@ -295,6 +298,13 @@ const asSetReferralCut: DetailsCast<'SetReferralCutProposalDetails'> = (fragment
amount: new BN(fragment.newReferralCut),
})

const asSetMembershipLeadInvitationQuota: DetailsCast<'SetMembershipLeadInvitationQuotaProposalDetails'> = (
fragment
): SetMembershipLeadInvitationQuota => ({
type: 'setMembershipLeadInvitationQuota',
count: fragment.newLeadInvitationQuota,
})

const asSetInitialInvitationBalance: DetailsCast<'SetInitialInvitationBalanceProposalDetails'> = (
fragment
): SetInitialInvitationBalanceDetails => ({
Expand All @@ -306,7 +316,7 @@ const asSetInitialInvitationCount: DetailsCast<'SetInitialInvitationCountProposa
fragment
): SetInitialInvitationCountDetails => ({
type: 'setInitialInvitationCount',
count: new BN(fragment.newInitialInvitationsCount),
count: fragment.newInitialInvitationsCount,
})

const asSetCouncilorReward: DetailsCast<'SetCouncilorRewardProposalDetails'> = (
Expand Down Expand Up @@ -345,6 +355,7 @@ const detailsCasts: Partial<Record<ProposalDetailsTypename, DetailsCast<any>>> =
SetInitialInvitationCountProposalDetails: asSetInitialInvitationCount,
SetCouncilorRewardProposalDetails: asSetCouncilorReward,
VetoProposalDetails: asVeto,
SetMembershipLeadInvitationQuotaProposalDetails: asSetMembershipLeadInvitationQuota,
}

export const asProposalDetails = (fragment: DetailsFragment): ProposalDetails => {
Expand Down

2 comments on commit 1b163bc

@vercel
Copy link

@vercel vercel bot commented on 1b163bc Dec 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 1b163bc Dec 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

pioneer-2 – ./

pioneer-2.vercel.app
pioneer-2-joystream.vercel.app
pioneer-2-git-dev-joystream.vercel.app

Please sign in to comment.