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

Refactor CreateProposalTemplateForm into generic ProposalBuilder #1524

Merged
merged 20 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2fdb0fc
Refactor CreateProposalTemplateForm into ProposalBuilder and make it …
mudrila Apr 8, 2024
9fd2565
Prettier
mudrila Apr 8, 2024
392eeea
Eliminate CreateProposal and use ProposalBuilder instead
mudrila Apr 8, 2024
2285855
Merge pull request #1527 from decentdao/hotfix/20240408-templatehash-…
adamgall Apr 8, 2024
6b0aade
Fix problem with missing bigNumberValue during prepareProposal
mudrila Apr 8, 2024
ac192ff
Explicitly set bigNumberValue to null while creating proposal templat…
mudrila Apr 8, 2024
e3ff66b
Do not type amountInputValue and value on BigNumberInput with explici…
mudrila Apr 9, 2024
520fe1d
Transform ProposalBuilderMode into enum
mudrila Apr 9, 2024
ee0d4fd
Prettier
mudrila Apr 9, 2024
4fa08c6
If signature is empty - do not call encodeFunction but simply return …
mudrila Apr 9, 2024
6886d70
Validate based on function name and not signature. If function name n…
mudrila Apr 9, 2024
43025de
Merge pull request #1529 from decentdao/feature/#1513-allow-proposal-…
mudrila Apr 9, 2024
b26a222
Rearrange order of types in useGetMultisigMetadata
mudrila Apr 9, 2024
c2b60ee
Merge pull request #1525 from decentdao/feature/#1363-use-proposal-bu…
mudrila Apr 9, 2024
537b744
Merge remote-tracking branch 'origin/feature/#1363-generic-templates-…
mudrila Apr 11, 2024
50dfaaa
Merge pull request #1528 from decentdao/hotfix/eth-value
mudrila Apr 11, 2024
278dcf9
Update src/i18n/locales/en/proposal.json
mudrila Apr 14, 2024
b2c1780
Merge branch 'develop' into feature/#1363-generic-templates-builder
mudrila Apr 14, 2024
db9e409
Fix import
mudrila Apr 14, 2024
b9514d9
Prettier
mudrila Apr 14, 2024
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
64 changes: 0 additions & 64 deletions src/components/CreateProposalTemplate/ProposalTemplateMetadata.tsx

This file was deleted.

23 changes: 0 additions & 23 deletions src/components/CreateProposalTemplate/constants.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FormikProps } from 'formik';
import { Fragment, PropsWithChildren } from 'react';
import { useTranslation } from 'react-i18next';
import { BACKGROUND_SEMI_TRANSPARENT } from '../../constants/common';
import { CreateProposalTemplateForm } from '../../types/createProposalTemplate';
import { CreateProposalForm, ProposalBuilderMode } from '../../types/proposalBuilder';
import Markdown from '../ui/proposal/Markdown';
import '../../assets/css/Markdown.css';

Expand All @@ -29,10 +29,11 @@ export function TransactionValueContainer({
}

export default function ProposalTemplateDetails({
values: { proposalTemplateMetadata, transactions },
}: FormikProps<CreateProposalTemplateForm>) {
values: { proposalMetadata, transactions },
mode,
}: FormikProps<CreateProposalForm> & { mode: ProposalBuilderMode }) {
const { t } = useTranslation(['proposalTemplate', 'proposal']);
const trimmedTitle = proposalTemplateMetadata.title?.trim();
const trimmedTitle = proposalMetadata.title?.trim();

return (
<Box
Expand All @@ -51,23 +52,25 @@ export default function ProposalTemplateDetails({
<Text color="grayscale.500">{t('previewTitle')}</Text>
<Text textAlign="right">{trimmedTitle}</Text>
</HStack>
<HStack justifyContent="space-between">
<Text color="grayscale.500">{t('previewThumnbail')}</Text>
{trimmedTitle && (
<Avatar
size="sm"
w="28px"
h="28px"
name={trimmedTitle}
borderRadius="4px"
getInitials={(title: string) => title.slice(0, 2)}
/>
)}
</HStack>
{mode === ProposalBuilderMode.TEMPLATE && (
<HStack justifyContent="space-between">
<Text color="grayscale.500">{t('previewThumnbail')}</Text>
{trimmedTitle && (
<Avatar
size="sm"
w="28px"
h="28px"
name={trimmedTitle}
borderRadius="4px"
getInitials={(title: string) => title.slice(0, 2)}
/>
)}
</HStack>
)}
<HStack justifyContent="space-between">
<Text color="grayscale.500">{t('proposalTemplateDescription')}</Text>
<Markdown
content={proposalTemplateMetadata.description}
content={proposalMetadata.description}
collapsedLines={2}
/>
</HStack>
Expand Down
79 changes: 79 additions & 0 deletions src/components/ProposalBuilder/ProposalMetadata.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { Button, Divider, VStack } from '@chakra-ui/react';
import { FormikProps } from 'formik';
import { useTranslation } from 'react-i18next';
import { CreateProposalState } from '../../types';
import { CreateProposalForm, ProposalBuilderMode } from '../../types/proposalBuilder';
import { InputComponent, TextareaComponent } from '../ui/forms/InputComponent';

export interface ProposalMetadataProps extends FormikProps<CreateProposalForm> {
setFormState: (state: CreateProposalState) => void;
mode: ProposalBuilderMode;
}

export default function ProposalMetadata({
values: { proposalMetadata },
setFieldValue,
errors: { proposalMetadata: proposalMetadataError },
setFormState,
mode,
}: ProposalMetadataProps) {
const { t } = useTranslation(['proposalTemplate', 'proposal', 'common']);
const isProposalMode = mode === ProposalBuilderMode.PROPOSAL;

return (
<>
<VStack
align="left"
spacing={4}
mt={4}
>
<InputComponent
label={
isProposalMode ? t('proposalTitle', { ns: 'proposal' }) : t('proposalTemplateTitle')
}
helper={
isProposalMode
? t('proposalTitleHelper', { ns: 'proposal' })
: t('proposalTemplateTitleHelperText')
}
isRequired
value={proposalMetadata.title}
onChange={e => setFieldValue('proposalMetadata.title', e.target.value)}
disabled={false}
testId="metadata.title"
maxLength={50}
/>
<TextareaComponent
label={
isProposalMode
? t('proposalDescription', { ns: 'proposal' })
: t('proposalTemplateDescription')
}
subLabel={t('')}
helper={
isProposalMode
? t('proposalDescriptionHelper', { ns: 'proposal' })
: t('proposalTemplateDescriptionHelperText')
}
isRequired={false}
value={proposalMetadata.description}
onChange={e => setFieldValue('proposalMetadata.description', e.target.value)}
disabled={false}
rows={12}
/>
</VStack>
<Divider
color="chocolate.700"
mt={8}
mb={6}
/>
<Button
w="100%"
onClick={() => setFormState(CreateProposalState.TRANSACTIONS_FORM)}
isDisabled={!!proposalMetadataError || !proposalMetadata.title}
>
{t('next', { ns: 'common' })}
</Button>
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,32 @@ import { VStack, HStack, Text, Box, Flex, IconButton } from '@chakra-ui/react';
import { AddPlus, Minus } from '@decent-org/fractal-ui';
import { useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { CreateProposalTemplateTransaction } from '../../types/createProposalTemplate';
import { CreateProposalTransaction, ProposalBuilderMode } from '../../types/proposalBuilder';
import ABISelector, { ABIElement } from '../ui/forms/ABISelector';
import ExampleLabel from '../ui/forms/ExampleLabel';
import { BigNumberComponent, InputComponent } from '../ui/forms/InputComponent';
import { DEFAULT_PROPOSAL_TEMPLATE_TRANSACTION } from './constants';
import { DEFAULT_PROPOSAL_TRANSACTION } from './constants';

interface ProposalTemplateTransactionProps {
transaction: CreateProposalTemplateTransaction;
interface ProposalTransactionProps {
transaction: CreateProposalTransaction;
transactionIndex: number;
transactionPending: boolean;
txAddressError?: string;
txFunctionError?: string;
setFieldValue: (field: string, value: any, shouldValidate?: boolean | undefined) => void;
mode: ProposalBuilderMode;
}

export default function ProposalTemplateTransaction({
export default function ProposalTransaction({
transaction,
transactionIndex,
transactionPending,
txAddressError,
txFunctionError,
setFieldValue,
}: ProposalTemplateTransactionProps) {
mode,
}: ProposalTransactionProps) {
const isProposalMode = mode === ProposalBuilderMode.PROPOSAL;
const { t } = useTranslation(['proposal', 'proposalTemplate', 'common']);
const handleABISelectorChange = useCallback(
(value: ABIElement) => {
Expand Down Expand Up @@ -123,7 +126,7 @@ export default function ProposalTemplateTransaction({
onClick={() =>
setFieldValue(`transactions.${transactionIndex}.parameters`, [
...transaction.parameters,
DEFAULT_PROPOSAL_TEMPLATE_TRANSACTION,
DEFAULT_PROPOSAL_TRANSACTION,
])
}
>
Expand Down Expand Up @@ -170,34 +173,38 @@ export default function ProposalTemplateTransaction({
alignItems="center"
mt={4}
>
<InputComponent
label={t('labelParameterLabel', { ns: 'proposalTemplate' })}
helper=""
isRequired={!parameter.value}
value={parameter.label || ''}
onChange={e =>
setFieldValue(
`transactions.${transactionIndex}.parameters.${i}.label`,
e.target.value,
)
}
disabled={transactionPending || !!parameter.value}
testId={`transactions.${transactionIndex}.parameters.${i}.label`}
subLabel={
<HStack>
<Text>{t('helperParameterLabel', { ns: 'proposalTemplate' })}</Text>
</HStack>
}
gridContainerProps={{
display: 'inline-flex',
flexWrap: 'wrap',
width: '30%',
}}
inputContainerProps={{
width: '100%',
}}
/>
<Text>{t('or', { ns: 'common' })}</Text>
{!isProposalMode && (
<>
<InputComponent
label={t('labelParameterLabel', { ns: 'proposalTemplate' })}
helper=""
isRequired={!parameter.value}
value={parameter.label || ''}
onChange={e =>
setFieldValue(
`transactions.${transactionIndex}.parameters.${i}.label`,
e.target.value,
)
}
disabled={transactionPending || !!parameter.value}
testId={`transactions.${transactionIndex}.parameters.${i}.label`}
subLabel={
<HStack>
<Text>{t('helperParameterLabel', { ns: 'proposalTemplate' })}</Text>
</HStack>
}
gridContainerProps={{
display: 'inline-flex',
flexWrap: 'wrap',
width: '30%',
}}
inputContainerProps={{
width: '100%',
}}
/>
<Text>{t('or', { ns: 'common' })}</Text>
</>
)}
<InputComponent
label={t('labelParameterValue', { ns: 'proposalTemplate' })}
helper=""
Expand All @@ -214,9 +221,11 @@ export default function ProposalTemplateTransaction({
<HStack wordBreak="break-all">
<Text>
{t('example', { ns: 'common' })}: <ExampleLabel>value</ExampleLabel>
<Text as="span">
{t('proposalTemplateLeaveBlank', { ns: 'proposalTemplate' })}
</Text>
{!isProposalMode && (
<Text as="span">
{t('proposalTemplateLeaveBlank', { ns: 'proposalTemplate' })}
</Text>
)}
</Text>
</HStack>
}
Expand Down Expand Up @@ -282,7 +291,9 @@ export default function ProposalTemplateTransaction({
<Text>{`${t('example', { ns: 'common' })}:`}</Text>
<ExampleLabel>{'1.2'}</ExampleLabel>
</HStack>
<Text>{t('ethParemeterHelper', { ns: 'proposalTemplate' })}</Text>
{!isProposalMode && (
<Text>{t('ethParemeterHelper', { ns: 'proposalTemplate' })}</Text>
)}
</VStack>
}
errorMessage={undefined}
Expand Down
Loading