Skip to content

Commit

Permalink
Handle summary and banner step for announce candidacy
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-olizarenko committed Oct 7, 2021
1 parent ef2b0dd commit 608c9c3
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useCouncilConstants } from '@/council/hooks/useCouncilConstants'
import { AnnounceCandidacyConstantsWrapper } from '@/council/modals/AnnounceCandidacy/components/AnnounceCandidacyConstantsWrapper'
import { RewardAccountStep } from '@/council/modals/AnnounceCandidacy/components/RewardAccountStep'
import { StakingStep } from '@/council/modals/AnnounceCandidacy/components/StakingStep'
import { SummaryAndBannerStep } from '@/council/modals/AnnounceCandidacy/components/SummaryAndBannerStep'
import { TitleAndBulletPointsStep } from '@/council/modals/AnnounceCandidacy/components/TitleAndBulletPointsStep'
import { announceCandidacyMachine } from '@/council/modals/AnnounceCandidacy/machine'
import { useMyMemberships } from '@/memberships/hooks/useMyMemberships'
Expand Down Expand Up @@ -81,6 +82,8 @@ export const AnnounceCandidacyModal = () => {
state.context.bulletPoints.length
) {
setValidNext(true)
} else if (state.matches('candidateProfile.summaryAndBanner') && state.context.summary) {
setValidNext(true)
} else {
setValidNext(false)
}
Expand Down Expand Up @@ -147,6 +150,14 @@ export const AnnounceCandidacyModal = () => {
setBulletPoints={(bulletPoints) => send('SET_BULLET_POINTS', { bulletPoints })}
/>
)}
{state.matches('candidateProfile.summaryAndBanner') && (
<SummaryAndBannerStep
summary={state.context.summary}
setSummary={(summary) => send('SET_SUMMARY', { summary })}
banner={state.context.banner}
setBanner={(banner) => send('SET_BANNER', { banner })}
/>
)}
</StepperBody>
</StepperProposalWrapper>
</StepperModalBody>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react'

import { CKEditor } from '@/common/components/CKEditor'
import { InputComponent, InputText } from '@/common/components/forms'
import { Row } from '@/common/components/Modal'
import { RowGapBlock } from '@/common/components/page/PageContent'

interface SummaryAndBannerStepProps {
summary?: string
banner?: string
setSummary: (summary?: string) => void
setBanner: (banner?: string) => void
}

export const SummaryAndBannerStep = ({ summary, banner, setSummary, setBanner }: SummaryAndBannerStepProps) => {
return (
<RowGapBlock gap={24}>
<Row>
<RowGapBlock gap={8}>
<h4>Candidate profile</h4>
</RowGapBlock>
</Row>
<Row>
<RowGapBlock gap={20}>
<InputComponent label="Summary" required inputSize="auto" id="field-summary">
<CKEditor
id="field-summary"
onChange={(event, editor) => setSummary(editor.getData())}
onReady={(editor) => editor.setData(summary || '')}
/>
</InputComponent>
<InputComponent label="Banner" disabled inputSize="s">
<InputText
disabled
placeholder="Image URL"
value={banner}
onChange={(event) => setBanner(event.target.value)}
/>
</InputComponent>
</RowGapBlock>
</Row>
</RowGapBlock>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const TitleAndBulletPointsStep = ({
setBulletPoints,
}: TitleAndBulletPointsStepProps) => {
const formInitializer: FormFields = {
title,
title: title || '',
bulletPoint1: bulletPoints[0] || '',
bulletPoint2: bulletPoints[1] || '',
bulletPoint3: bulletPoints[2] || '',
Expand Down
30 changes: 25 additions & 5 deletions packages/ui/src/council/modals/AnnounceCandidacy/machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ interface TitleAndBulletPointsContext extends Required<RewardAccountContext> {
bulletPoints: string[]
}

export type AnnounceCandidacyContext = Partial<StakingContext & RewardAccountContext & TitleAndBulletPointsContext>
interface SummaryAndBannerContext extends Required<TitleAndBulletPointsContext> {
summary?: string
banner?: string
}

export type AnnounceCandidacyContext = Partial<
StakingContext & RewardAccountContext & TitleAndBulletPointsContext & SummaryAndBannerContext
>

export type AnnounceCandidacyState =
| { value: 'requirementsVerification'; context: EmptyObject }
Expand All @@ -29,15 +36,17 @@ export type AnnounceCandidacyState =
| { value: 'rewardAccount'; context: Required<RewardAccountContext> }
| { value: 'candidateProfile'; context: Required<RewardAccountContext> }
| { value: 'candidateProfile.titleAndBulletPoints'; context: Required<TitleAndBulletPointsContext> }
| { value: 'candidateProfile.summaryAndBanner'; context: Required<TitleAndBulletPointsContext> }
| { value: 'candidateProfile.finishCandidateProfile'; context: Required<TitleAndBulletPointsContext> }
| { value: 'success'; context: Required<TitleAndBulletPointsContext> }
| { value: 'candidateProfile.summaryAndBanner'; context: Required<SummaryAndBannerContext> }
| { value: 'candidateProfile.finishCandidateProfile'; context: Required<SummaryAndBannerContext> }
| { value: 'success'; context: Required<SummaryAndBannerContext> }
| { value: 'error'; context: AnnounceCandidacyContext }

type SetAccountEvent = { type: 'SET_ACCOUNT'; account: Account }
type SetAmountEvent = { type: 'SET_AMOUNT'; amount: BN }
type SetTitleEvent = { type: 'SET_TITLE'; title: string }
type SetBulletPointsEvent = { type: 'SET_BULLET_POINTS'; bulletPoints: string[] }
type SetSummaryEvent = { type: 'SET_SUMMARY'; summary: string }
type SetBannerEvent = { type: 'SET_BANNER'; banner: string }

type AnnounceCandidacyEvent =
| { type: 'FAIL' }
Expand All @@ -47,6 +56,8 @@ type AnnounceCandidacyEvent =
| SetAmountEvent
| SetTitleEvent
| SetBulletPointsEvent
| SetSummaryEvent
| SetBannerEvent

export const announceCandidacyMachine = createMachine<
AnnounceCandidacyContext,
Expand All @@ -55,7 +66,6 @@ export const announceCandidacyMachine = createMachine<
>({
initial: 'requirementsVerification',
context: {
title: '',
bulletPoints: [],
},
states: {
Expand Down Expand Up @@ -139,6 +149,16 @@ export const announceCandidacyMachine = createMachine<
NEXT: {
target: 'finishCandidateProfile',
},
SET_SUMMARY: {
actions: assign({
summary: (context, event) => event.summary,
}),
},
SET_BANNER: {
actions: assign({
banner: (context, event) => event.banner,
}),
},
},
},
finishCandidateProfile: {
Expand Down
39 changes: 38 additions & 1 deletion packages/ui/test/council/modals/AnnounceCandidacyModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { interpret } from 'xstate'

import { AccountsContext } from '@/accounts/providers/accounts/context'
import { UseAccounts } from '@/accounts/providers/accounts/provider'
import { CKEditorProps } from '@/common/components/CKEditor'
import { BalancesContextProvider } from '@/accounts/providers/balances/provider'
import { getSteps } from '@/common/model/machines/getSteps'
import { ApiContext } from '@/common/providers/api/context'
Expand All @@ -21,6 +22,7 @@ import { seedMembers } from '@/mocks/data'
import { getButton } from '../../_helpers/getButton'
import { includesTextWithMarkup } from '../../_helpers/includesTextWithMarkup'
import { selectFromDropdown } from '../../_helpers/selectFromDropdown'
import { mockCKEditor } from '../../_mocks/components/CKEditor'
import { alice, bob } from '../../_mocks/keyring'
import { getMember } from '../../_mocks/members'
import { MockKeyringProvider, MockQueryNodeProviders } from '../../_mocks/providers'
Expand All @@ -35,6 +37,10 @@ import {

configure({ testIdAttribute: 'id' })

jest.mock('@/common/components/CKEditor', () => ({
CKEditor: (props: CKEditorProps) => mockCKEditor(props),
}))

describe('UI: Announce Candidacy Modal', () => {
const api = stubApi()
const useModal: UseModal<any> = {
Expand Down Expand Up @@ -233,6 +239,25 @@ describe('UI: Announce Candidacy Modal', () => {
})
})

describe('Summary and Banner', () => {
beforeEach(async () => {
renderModal()
await fillStakingStep('alice', 15, true)
await fillRewardAccountStep('alice', true)
await fillTitleAndBulletPointsStep('Some title', 'Some bullet point', true)
})

it('Default', async () => {
expect(await getNextStepButton()).toBeDisabled()
})

it('Summary filled', async () => {
await fillSummary()

expect(await getNextStepButton()).not.toBeDisabled()
})
})

async function fillStakingAmount(value: number) {
const amountInput = await screen.getByTestId('stakingAmount')

Expand Down Expand Up @@ -286,8 +311,20 @@ describe('UI: Announce Candidacy Modal', () => {
}
}

async function fillSummary(goNext?: boolean) {
const summaryInput = await screen.findByLabelText(/Summary/i)

act(() => {
fireEvent.change(summaryInput, { target: { value: 'Some summary' } })
})

if (goNext) {
await clickNextButton()
}
}

async function getNextStepButton() {
return getButton(/Next step/i)
return getButton(/(Next step|Announce candidacy)/i)
}

async function clickNextButton() {
Expand Down

0 comments on commit 608c9c3

Please sign in to comment.