Skip to content

Commit 232ac09

Browse files
Merge pull request #243 from IntersectMBO/fix/-“Save-Draft”-Button-Disabled-When-Valid-Guardrails-Script-is-Provided-in-Constitution-Proposal-(#3531)
fix: “Save Draft” Button Disabled When Valid Guardrails Script is Pro…
2 parents fec7c6a + 7e7a258 commit 232ac09

File tree

1 file changed

+81
-56
lines changed
  • pdf-ui/src/components/CreationGoveranceAction

1 file changed

+81
-56
lines changed

pdf-ui/src/components/CreationGoveranceAction/Step2.jsx

Lines changed: 81 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
import {Box, Button, Card, CardContent, MenuItem, TextField, Typography } from '@mui/material';
1+
import {
2+
Box,
3+
Button,
4+
Card,
5+
CardContent,
6+
MenuItem,
7+
TextField,
8+
Typography,
9+
} from '@mui/material';
210
import { useEffect, useState } from 'react';
3-
import { LinkManager, WithdrawalsManager, ConstitutionManager} from '.';
11+
import { LinkManager, WithdrawalsManager, ConstitutionManager } from '.';
412
import { useAppContext } from '../../context/context';
513
import { getGovernanceActionTypes } from '../../lib/api';
614
import { containsString, maxLengthCheck } from '../../lib/utils';
@@ -22,7 +30,7 @@ const Step2 = ({
2230
withdrawalsErrors,
2331
setWithdrawalsErrors,
2432
constitutionErrors,
25-
setConstitutionErrors
33+
setConstitutionErrors,
2634
}) => {
2735
const titleMaxLength = 80;
2836
const abstractMaxLength = 2500;
@@ -34,9 +42,10 @@ const Step2 = ({
3442
)?.label || ''
3543
);
3644
const [selectedGovActionId, setSelectedGovActionId] = useState(
37-
proposalData?.attributes?.content?.attributes?.gov_action_type?.id || null
45+
proposalData?.attributes?.content?.attributes?.gov_action_type?.id ||
46+
null
3847
);
39-
const [isDraftDisabled,setIsDraftDisabled] = useState(true);
48+
const [isDraftDisabled, setIsDraftDisabled] = useState(true);
4049
const handleChange = (e) => {
4150
const selectedValue = e.target.value;
4251
const selectedLabel = governanceActionTypes.find(
@@ -46,15 +55,16 @@ const Step2 = ({
4655
setProposalData((prev) => ({
4756
...prev,
4857
gov_action_type_id: selectedValue,
49-
proposal_withdrawals:[{ prop_receiving_address: null, prop_amount: null }]
58+
proposal_withdrawals: [
59+
{ prop_receiving_address: null, prop_amount: null },
60+
],
5061
}));
51-
if(selectedValue != 3)
52-
{ //cleanup fields co
62+
if (selectedValue != 3) {
63+
//cleanup fields co
5364
setProposalData((prev) => ({
5465
...prev,
55-
proposal_constitution_content:{}
66+
proposal_constitution_content: {},
5667
}));
57-
5868
}
5969
setSelectedGovActionId(selectedValue);
6070
setSelectedGovActionName(selectedLabel);
@@ -104,7 +114,7 @@ const Step2 = ({
104114
}
105115

106116
setHelperText((prev) => ({
107-
...prev,
117+
...prev,
108118
[errorField]: errorMessage === true ? '' : errorMessage,
109119
}));
110120

@@ -118,30 +128,39 @@ const Step2 = ({
118128
fetchGovernanceActionTypes();
119129
}, []);
120130

121-
useEffect(()=>{
122-
setSelectedGovActionName(governanceActionTypes.find(
123-
(option) => option?.value === +proposalData?.gov_action_type_id
124-
)?.label || '')
125-
setSelectedGovActionId(+proposalData?.gov_action_type_id)
131+
useEffect(() => {
132+
setSelectedGovActionName(
133+
governanceActionTypes.find(
134+
(option) => option?.value === +proposalData?.gov_action_type_id
135+
)?.label || ''
136+
);
137+
setSelectedGovActionId(+proposalData?.gov_action_type_id);
138+
}, [governanceActionTypes]);
126139

127-
},[governanceActionTypes])
128140
useEffect(() => {
129-
if(proposalData?.gov_action_type_id && proposalData?.prop_name?.length !== 0)
130-
{
131-
setIsDraftDisabled(false)
132-
}
133-
else
134-
{
135-
setIsDraftDisabled(true)
141+
if (
142+
proposalData?.gov_action_type_id &&
143+
proposalData?.prop_name?.length !== 0
144+
) {
145+
setIsDraftDisabled(false);
146+
} else {
147+
setIsDraftDisabled(true);
136148
}
137-
if(proposalData?.proposal_constitution_content?.prop_have_guardrails_script)
138-
{
139-
if(!proposalData.proposal_constitution_content.prop_guardrails_script_url && !proposalData.proposal_constitution_content.prop_guardrails_script_hash)
140-
setIsDraftDisabled(false)
141-
else
142-
setIsDraftDisabled(true)
149+
if (
150+
proposalData?.proposal_constitution_content
151+
?.prop_have_guardrails_script
152+
) {
153+
if (
154+
proposalData.proposal_constitution_content
155+
.prop_guardrails_script_url &&
156+
proposalData.proposal_constitution_content
157+
.prop_guardrails_script_hash
158+
) {
159+
setIsDraftDisabled(false);
160+
} else setIsDraftDisabled(true);
143161
}
144-
},[proposalData])
162+
}, [proposalData]);
163+
145164
return (
146165
<Card>
147166
<CardContent
@@ -387,34 +406,40 @@ const Step2 = ({
387406
: 'rationale-helper',
388407
}}
389408
/>
390-
{ /// Treasury
409+
{
410+
/// Treasury
391411
selectedGovActionId == 2 ? (
392-
<>
393-
<Box
394-
sx={{
395-
align: 'center',
396-
textAlign: 'center',
397-
mt: 2,
398-
}}
399-
>
400-
<WithdrawalsManager
412+
<>
413+
<Box
414+
sx={{
415+
align: 'center',
416+
textAlign: 'center',
417+
mt: 2,
418+
}}
419+
>
420+
<WithdrawalsManager
421+
proposalData={proposalData}
422+
setProposalData={setProposalData}
423+
withdrawalsErrors={withdrawalsErrors}
424+
setWithdrawalsErrors={
425+
setWithdrawalsErrors
426+
}
427+
/>
428+
</Box>
429+
</>
430+
) : null
431+
}
432+
{
433+
/// 'Constitution'
434+
selectedGovActionId === 3 ? (
435+
<ConstitutionManager
401436
proposalData={proposalData}
402437
setProposalData={setProposalData}
403-
withdrawalsErrors={withdrawalsErrors}
404-
setWithdrawalsErrors={setWithdrawalsErrors}
405-
/>
406-
</Box>
407-
</>
408-
409-
) : null}
410-
{ /// 'Constitution'
411-
selectedGovActionId === 3 ? (
412-
<ConstitutionManager
413-
proposalData={proposalData}
414-
setProposalData={setProposalData}
415-
constitutionManagerErrors={constitutionErrors}
416-
setConstitutionManagerErrors={setConstitutionErrors}
417-
></ConstitutionManager>
438+
constitutionManagerErrors={constitutionErrors}
439+
setConstitutionManagerErrors={
440+
setConstitutionErrors
441+
}
442+
></ConstitutionManager>
418443
) : null
419444
}
420445
<Box

0 commit comments

Comments
 (0)