Skip to content

Commit

Permalink
fix: validate the proposal creation form (#524)
Browse files Browse the repository at this point in the history
* fix: add limits to proposal's title, choices, and discussion

* fix: validate and show error on proposal body

* fix: revert changes, moved to later PR

* fix: style composer textarea like s-box

* fix: improve CSS

* fix: remove unused class

* fix(ui): add some padding

* fix(ui): add min height

* fix(ui): make offset emulate border

* fix: add maxLength/items validation to proposals fields

* fix: always show form error

* fix: always show composer error

* fix: add validation to statement

* revert: reverting unrelated changes

* feat: use different proposal body limit for trubo space

* refactor: use camel case variable name

* fix: revert changes, will be extracted to another dedicated PR

* refactor: rename regular to default
  • Loading branch information
wa0x6e authored Aug 2, 2024
1 parent 6bb2385 commit ad1cf8e
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions apps/ui/src/views/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,31 @@ type StrategyWithTreasury = SelectedStrategy & {
treasury: RequiredProperty<SpaceMetadataTreasury>;
};
const MAX_BODY_LENGTH = {
default: 10000,
turbo: 40000
} as const;
const TITLE_DEFINITION = {
type: 'string',
title: 'Title',
minLength: 1
minLength: 1,
maxLength: 256
};
const DISCUSSION_DEFINITION = {
type: 'string',
format: 'uri',
title: 'Discussion',
maxLength: 256,
examples: ['e.g. https://forum.balancer.fi/t/proposal…']
};
const BODY_DEFINITION = {
type: 'string',
format: 'long',
title: 'Body',
maxLength: 9600
};
const CHOICES_DEFINITION = {
type: 'array',
title: 'Choices',
minItems: 1,
maxItems: 500,
items: [{ type: 'string', minLength: 1, maxLength: 32 }],
additionalItems: { type: 'string', maxLength: 32 }
};
Expand Down Expand Up @@ -192,6 +193,12 @@ const extraContacts = computed(() => {
return space.value.treasuries as Contact[];
});
const bodyDefinition = computed(() => ({
type: 'string',
format: 'long',
title: 'Body',
maxLength: MAX_BODY_LENGTH[space.value?.turbo ? 'turbo' : 'default']
}));
const formErrors = computed(() => {
if (!proposal.value) return {};
Expand All @@ -203,7 +210,7 @@ const formErrors = computed(() => {
required: ['title', 'choices'],
properties: {
title: TITLE_DEFINITION,
body: BODY_DEFINITION,
body: bodyDefinition.value,
discussion: DISCUSSION_DEFINITION,
choices: CHOICES_DEFINITION
}
Expand Down Expand Up @@ -470,7 +477,7 @@ export default defineComponent({
<UiComposer
v-else
v-model="proposal.body"
:definition="BODY_DEFINITION"
:definition="bodyDefinition"
:error="formErrors.body"
/>
<div class="s-base mb-5">
Expand Down

0 comments on commit ad1cf8e

Please sign in to comment.