Skip to content

Commit

Permalink
Refactor Proposal Creation Pages to Standardize Step Button Handling
Browse files Browse the repository at this point in the history
- Updated the `metadataStepButtons` function in multiple proposal creation pages to a unified `stepButtons` function, enhancing clarity and consistency in button state management.
- Refactored the `ProposalBuilder` component to align with the new step button handling approach, ensuring a more modular and maintainable code structure.
- Improved the user experience by ensuring that button states are derived from clear and standardized props across different proposal types.

These changes aim to enhance the organization and readability of the proposal creation process, particularly in managing step button states.
  • Loading branch information
adamgall committed Jan 22, 2025
1 parent ca5fb8c commit 3bdb460
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 43 deletions.
23 changes: 6 additions & 17 deletions src/components/ProposalBuilder/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { Crumb } from '../ui/page/Header/Breadcrumbs';
import PageHeader from '../ui/page/Header/PageHeader';
import ProposalDetails from './ProposalDetails';
import ProposalMetadata, { ProposalMetadataTypeProps } from './ProposalMetadata';
import StepButtons, { CreateProposalButton, PreviousButton } from './StepButtons';

export function ShowNonceInputOnMultisig({
nonce,
Expand Down Expand Up @@ -67,7 +66,7 @@ interface ProposalBuilderProps {
pageHeaderButtonClickHandler: () => void;
proposalMetadataTypeProps: ProposalMetadataTypeProps;
actionsExperience: JSX.Element | null;
metadataStepButtons: ({
stepButtons: ({
formErrors,
createProposalBlocked,
}: {
Expand All @@ -79,7 +78,6 @@ interface ProposalBuilderProps {
| null;
templateDetails: ((title: string) => JSX.Element) | null;
streamsDetails: ((streams: Stream[]) => JSX.Element) | null;
prevStepUrl: string;
prepareProposalData: (values: CreateProposalForm) => Promise<ProposalExecuteData | undefined>;
initialValues: CreateProposalForm;
contentRoute: (
Expand All @@ -95,11 +93,10 @@ export function ProposalBuilder({
pageHeaderButtonClickHandler,
proposalMetadataTypeProps,
actionsExperience,
metadataStepButtons,
stepButtons,
transactionsDetails,
templateDetails,
streamsDetails,
prevStepUrl,
initialValues,
prepareProposalData,
contentRoute,
Expand Down Expand Up @@ -238,18 +235,10 @@ export function ProposalBuilder({
</Routes>
</Box>
{actionsExperience}
<StepButtons
metadataStepButtons={metadataStepButtons({
formErrors: !!formikProps.errors.proposalMetadata,
createProposalBlocked: createProposalButtonDisabled,
})}
transactionsStepButtons={
<>
<PreviousButton prevStepUrl={prevStepUrl} />
<CreateProposalButton isDisabled={createProposalButtonDisabled} />
</>
}
/>
{stepButtons({
formErrors: !!formikProps.errors.proposalMetadata,
createProposalBlocked: createProposalButtonDisabled,
})}
</Flex>
</GridItem>
<GridItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import {
} from '../../../../components/ProposalBuilder/ProposalDetails';
import { TEMPLATE_PROPOSAL_METADATA_TYPE_PROPS } from '../../../../components/ProposalBuilder/ProposalMetadata';
import ProposalTransactionsForm from '../../../../components/ProposalBuilder/ProposalTransactionsForm';
import { NextButton } from '../../../../components/ProposalBuilder/StepButtons';
import StepButtons, {
CreateProposalButton,
NextButton,
PreviousButton,
} from '../../../../components/ProposalBuilder/StepButtons';
import { DEFAULT_PROPOSAL } from '../../../../components/ProposalBuilder/constants';
import { DAO_ROUTES } from '../../../../constants/routes';
import { logError } from '../../../../helpers/errorLogging';
Expand Down Expand Up @@ -93,11 +97,27 @@ export function SafeCreateProposalTemplatePage() {
navigate(DAO_ROUTES.proposalTemplates.relative(addressPrefix, safe?.address ?? ''));
};

const metadataStepButtons = ({ formErrors }: { formErrors: boolean }) => {
const stepButtons = ({
formErrors,
createProposalBlocked,
}: {
formErrors: boolean;
createProposalBlocked: boolean;
}) => {
return (
<NextButton
nextStepUrl={nextStepUrl}
isDisabled={formErrors}
<StepButtons
metadataStepButtons={
<NextButton
nextStepUrl={nextStepUrl}
isDisabled={formErrors}
/>
}
transactionsStepButtons={
<>
<PreviousButton prevStepUrl={prevStepUrl} />
<CreateProposalButton isDisabled={createProposalBlocked} />
</>
}
/>
);
};
Expand All @@ -109,11 +129,10 @@ export function SafeCreateProposalTemplatePage() {
pageHeaderButtonClickHandler={pageHeaderButtonClickHandler}
proposalMetadataTypeProps={TEMPLATE_PROPOSAL_METADATA_TYPE_PROPS(t)}
actionsExperience={null}
metadataStepButtons={metadataStepButtons}
stepButtons={stepButtons}
transactionsDetails={transactions => <TransactionsDetails transactions={transactions} />}
templateDetails={title => <TemplateDetails title={title} />}
streamsDetails={null}
prevStepUrl={prevStepUrl}
initialValues={initialProposalTemplate}
prepareProposalData={prepareProposalTemplateProposal}
contentRoute={(formikProps, pendingCreateTx, nonce) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import { ProposalActionCard } from '../../../../../components/ProposalBuilder/Pr
import { TransactionsDetails } from '../../../../../components/ProposalBuilder/ProposalDetails';
import { DEFAULT_PROPOSAL_METADATA_TYPE_PROPS } from '../../../../../components/ProposalBuilder/ProposalMetadata';
import ProposalTransactionsForm from '../../../../../components/ProposalBuilder/ProposalTransactionsForm';
import { CreateProposalButton } from '../../../../../components/ProposalBuilder/StepButtons';
import StepButtons, {
CreateProposalButton,
PreviousButton,
} from '../../../../../components/ProposalBuilder/StepButtons';
import { DEFAULT_PROPOSAL } from '../../../../../components/ProposalBuilder/constants';
import { BarLoader } from '../../../../../components/ui/loaders/BarLoader';
import { AddActions } from '../../../../../components/ui/modals/AddActions';
Expand Down Expand Up @@ -130,8 +133,18 @@ export function SafeProposalWithActionsCreatePage() {
navigate(DAO_ROUTES.proposals.relative(addressPrefix, safe.address));
};

const metadataStepButtons = ({ createProposalBlocked }: { createProposalBlocked: boolean }) => {
return <CreateProposalButton isDisabled={createProposalBlocked} />;
const stepButtons = ({ createProposalBlocked }: { createProposalBlocked: boolean }) => {
return (
<StepButtons
metadataStepButtons={<CreateProposalButton isDisabled={createProposalBlocked} />}
transactionsStepButtons={
<>
<PreviousButton prevStepUrl={prevStepUrl} />
<CreateProposalButton isDisabled={createProposalBlocked} />
</>
}
/>
);
};

return (
Expand All @@ -145,12 +158,11 @@ export function SafeProposalWithActionsCreatePage() {
pageHeaderBreadcrumbs={pageHeaderBreadcrumbs}
pageHeaderButtonClickHandler={pageHeaderButtonClickHandler}
actionsExperience={<ActionsExperience />}
metadataStepButtons={metadataStepButtons}
stepButtons={stepButtons}
transactionsDetails={transactions => <TransactionsDetails transactions={transactions} />}
templateDetails={null}
streamsDetails={null}
proposalMetadataTypeProps={DEFAULT_PROPOSAL_METADATA_TYPE_PROPS(t)}
prevStepUrl={prevStepUrl}
prepareProposalData={prepareProposal}
contentRoute={(formikProps, pendingCreateTx, nonce) => {
return (
Expand Down
33 changes: 26 additions & 7 deletions src/pages/dao/proposals/new/SafeProposalCreatePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { ProposalBuilder, ShowNonceInputOnMultisig } from '../../../../component
import { TransactionsDetails } from '../../../../components/ProposalBuilder/ProposalDetails';
import { DEFAULT_PROPOSAL_METADATA_TYPE_PROPS } from '../../../../components/ProposalBuilder/ProposalMetadata';
import ProposalTransactionsForm from '../../../../components/ProposalBuilder/ProposalTransactionsForm';
import { NextButton } from '../../../../components/ProposalBuilder/StepButtons';
import StepButtons, {
CreateProposalButton,
NextButton,
PreviousButton,
} from '../../../../components/ProposalBuilder/StepButtons';
import { DEFAULT_PROPOSAL } from '../../../../components/ProposalBuilder/constants';
import { BarLoader } from '../../../../components/ui/loaders/BarLoader';
import { useHeaderHeight } from '../../../../constants/common';
Expand Down Expand Up @@ -62,11 +66,27 @@ export function SafeProposalCreatePage() {
navigate(DAO_ROUTES.proposals.relative(addressPrefix, safe.address));
};

const metadataStepButtons = ({ formErrors }: { formErrors: boolean }) => {
const stepButtons = ({
formErrors,
createProposalBlocked,
}: {
formErrors: boolean;
createProposalBlocked: boolean;
}) => {
return (
<NextButton
nextStepUrl={nextStepUrl}
isDisabled={formErrors}
<StepButtons
metadataStepButtons={
<NextButton
nextStepUrl={nextStepUrl}
isDisabled={formErrors}
/>
}
transactionsStepButtons={
<>
<PreviousButton prevStepUrl={prevStepUrl} />
<CreateProposalButton isDisabled={createProposalBlocked} />
</>
}
/>
);
};
Expand All @@ -79,11 +99,10 @@ export function SafeProposalCreatePage() {
pageHeaderButtonClickHandler={pageHeaderButtonClickHandler}
proposalMetadataTypeProps={DEFAULT_PROPOSAL_METADATA_TYPE_PROPS(t)}
actionsExperience={null}
metadataStepButtons={metadataStepButtons}
stepButtons={stepButtons}
transactionsDetails={transactions => <TransactionsDetails transactions={transactions} />}
templateDetails={null}
streamsDetails={null}
prevStepUrl={prevStepUrl}
prepareProposalData={prepareProposal}
contentRoute={(formikProps, pendingCreateTx, nonce) => {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import {
import { StreamsDetails } from '../../../../../components/ProposalBuilder/ProposalDetails';
import { DEFAULT_PROPOSAL_METADATA_TYPE_PROPS } from '../../../../../components/ProposalBuilder/ProposalMetadata';
import { ProposalStreams } from '../../../../../components/ProposalBuilder/ProposalStreams';
import { NextButton } from '../../../../../components/ProposalBuilder/StepButtons';
import StepButtons, {
CreateProposalButton,
NextButton,
PreviousButton,
} from '../../../../../components/ProposalBuilder/StepButtons';
import { DEFAULT_SABLIER_PROPOSAL } from '../../../../../components/ProposalBuilder/constants';
import { BarLoader } from '../../../../../components/ui/loaders/BarLoader';
import { useHeaderHeight } from '../../../../../constants/common';
Expand Down Expand Up @@ -142,11 +146,27 @@ export function SafeSablierProposalCreatePage() {
navigate(DAO_ROUTES.proposals.relative(addressPrefix, safe.address));
};

const metadataStepButtons = ({ formErrors }: { formErrors: boolean }) => {
const stepButtons = ({
formErrors,
createProposalBlocked,
}: {
formErrors: boolean;
createProposalBlocked: boolean;
}) => {
return (
<NextButton
nextStepUrl={nextStepUrl}
isDisabled={formErrors}
<StepButtons
metadataStepButtons={
<NextButton
nextStepUrl={nextStepUrl}
isDisabled={formErrors}
/>
}
transactionsStepButtons={
<>
<PreviousButton prevStepUrl={prevStepUrl} />
<CreateProposalButton isDisabled={createProposalBlocked} />
</>
}
/>
);
};
Expand All @@ -159,11 +179,10 @@ export function SafeSablierProposalCreatePage() {
pageHeaderButtonClickHandler={pageHeaderButtonClickHandler}
proposalMetadataTypeProps={DEFAULT_PROPOSAL_METADATA_TYPE_PROPS(t)}
actionsExperience={null}
metadataStepButtons={metadataStepButtons}
stepButtons={stepButtons}
transactionsDetails={null}
templateDetails={null}
streamsDetails={streams => <StreamsDetails streams={streams} />}
prevStepUrl={prevStepUrl}
prepareProposalData={prepareProposalData}
contentRoute={(formikProps, pendingCreateTx, nonce) => {
return (
Expand Down

0 comments on commit 3bdb460

Please sign in to comment.