Skip to content
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

🧮 Sort application answers before submitting them #4382

Merged
merged 2 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const ApplicationStep = ({ questions }: ApplicationStepProps) => {
question={question.question}
index={question.index}
key={question.index}
name={`form.question${index}`}
name={`form.${index}`}
/>
))}
</RowGapBlock>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,14 @@ export const ApplyForRoleModal = () => {
const transactionService = state.children.transaction

if (state.matches('transaction') && signer && api && transactionService) {
const { stake, form: formFields } = form.getValues()
const { stake, form: answers } = form.getValues()

const applyOnOpeningTransaction = api.tx[opening.groupId].applyOnOpening({
memberId: activeMember?.id,
openingId: opening.runtimeId,
roleAccountId: stake.roleAccount.address,
rewardAccountId: stake.rewardAccount.address,
description: metadataToBytes(ApplicationMetadata, { answers: Object.values(formFields ?? {}) as string[] }),
description: metadataToBytes(ApplicationMetadata, { answers }),
stakeParameters: {
stake: stake.amount,
stakingAccountId: stake.account?.address,
Expand Down
15 changes: 3 additions & 12 deletions packages/ui/src/working-groups/modals/ApplyForRoleModal/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,8 @@ import { BNSchema, validStakingAmount } from '@/common/utils/validation'
import { AccountSchema, StakingAccountSchema } from '@/memberships/model/validation'
import { ApplicationQuestion } from '@/working-groups/types'

export const validationSchemaFromQuestions = (questions: ApplicationQuestion[]) => {
const shapeDefinition = questions.reduce(
(schema, question, index) => ({
[`question${index}`]: Yup.string().required(),
...schema,
}),
{}
)

return Yup.object().shape(shapeDefinition)
}
export const validationSchemaFromQuestions = (questions: ApplicationQuestion[]) =>
Yup.array().of(Yup.string().required()).length(questions.length)

export const baseSchema = Yup.object().shape({
stake: Yup.object().shape({
Expand All @@ -23,5 +14,5 @@ export const baseSchema = Yup.object().shape({
rewardAccount: AccountSchema.required(),
amount: BNSchema.test(validStakingAmount()).required('Amount is required'),
}),
form: Yup.object().shape({}),
form: Yup.array().of(Yup.string().required()).min(1),
})