Skip to content

Commit

Permalink
set stable rarimo client package, strict proposal desc length, add pr…
Browse files Browse the repository at this point in the history
…eview modal
  • Loading branch information
lukachi committed Mar 22, 2024
1 parent 3084e01 commit 451efc2
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 124 deletions.
18 changes: 2 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@hookform/resolvers": "^3.3.1",
"@mui/icons-material": "^5.14.3",
"@mui/material": "^5.14.3",
"@rarimo/client": "^2.2.0",
"@rarimo/client": "^2.3.0",
"graphql": "^16.7.1",
"graphql-tag": "^2.12.6",
"lodash-es": "^4.17.21",
Expand Down Expand Up @@ -74,19 +74,5 @@
"stylelint-scss": "^5.0.1",
"yorkie": "^2.0.0"
},
"packageManager": "[email protected]",
"resolutions": {
"rarimo-js-sdk-monorepo-root": "portal:/Users/lukachisama/Documents/RARIMO/js-sdk",
"@rarimo/bridge": "portal:/Users/lukachisama/Documents/RARIMO/js-sdk/packages/bridge",
"@rarimo/client": "portal:/Users/lukachisama/Documents/RARIMO/js-sdk/packages/client",
"@rarimo/nft-checkout": "portal:/Users/lukachisama/Documents/RARIMO/js-sdk/packages/nft-checkout",
"@rarimo/provider": "portal:/Users/lukachisama/Documents/RARIMO/js-sdk/packages/provider",
"@rarimo/providers-evm": "portal:/Users/lukachisama/Documents/RARIMO/js-sdk/packages/providers-evm",
"@rarimo/providers-near": "portal:/Users/lukachisama/Documents/RARIMO/js-sdk/packages/providers-near",
"@rarimo/providers-solana": "portal:/Users/lukachisama/Documents/RARIMO/js-sdk/packages/providers-solana",
"@rarimo/react-nft-checkout": "portal:/Users/lukachisama/Documents/RARIMO/js-sdk/packages/react-nft-checkout",
"@rarimo/react-provider": "portal:/Users/lukachisama/Documents/RARIMO/js-sdk/packages/react-provider",
"@rarimo/shared": "portal:/Users/lukachisama/Documents/RARIMO/js-sdk/packages/shared",
"@rarimo/swap": "portal:/Users/lukachisama/Documents/RARIMO/js-sdk/packages/swap"
}
"packageManager": "[email protected]"
}
38 changes: 32 additions & 6 deletions src/components/Forms/SubmitTextProposalForm.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import {
Button,
FormControl,
FormHelperText,
TextareaAutosize as BaseTextareaAutosize,
TextField,
Typography,
} from '@mui/material'
import { styled } from '@mui/system'
import { useMemo } from 'react'
import { useMemo, useState } from 'react'
import { Controller } from 'react-hook-form'

import { getClient } from '@/client'
import { Dialog } from '@/components/Dialog'
import FormWrapper from '@/components/Forms/FormWrapper'
import MarkdownViewer from '@/components/MarkdownViewer'
import { ErrorHandler } from '@/helpers'
import { useForm, useWeb3 } from '@/hooks'
import { useI18n } from '@/locales/client'
Expand All @@ -21,16 +24,21 @@ enum FieldNames {
Description = 'description',
}

const PROPOSAL_MAX_DESC_LENGTH = 10_000

export default function SubmitTextProposalForm({ id, onSubmit, setIsDialogDisabled }: FormProps) {
const t = useI18n()
const { address } = useWeb3()

const [isPreviewDialogOpen, setIsPreviewDialogOpen] = useState(false)

const DEFAULT_VALUES = {
[FieldNames.Title]: '',
[FieldNames.Description]: '',
}

const {
formState,
handleSubmit,
control,
isFormDisabled,
Expand All @@ -41,7 +49,7 @@ export default function SubmitTextProposalForm({ id, onSubmit, setIsDialogDisabl
} = useForm(DEFAULT_VALUES, yup =>
yup.object({
[FieldNames.Title]: yup.string().required(),
[FieldNames.Description]: yup.string().required(),
[FieldNames.Description]: yup.string().max(PROPOSAL_MAX_DESC_LENGTH).required(),
}),
)

Expand All @@ -64,7 +72,7 @@ export default function SubmitTextProposalForm({ id, onSubmit, setIsDialogDisabl

const amount = await getMinAmount()

const receipt = await client.tx.submitTextProposal(
await client.tx.submitTextProposal(
address,
[
{
Expand All @@ -76,8 +84,6 @@ export default function SubmitTextProposalForm({ id, onSubmit, setIsDialogDisabl
formData[FieldNames.Description],
)

console.log(receipt)

onSubmit({
message: t('submit-text-proposal-form.submitted-msg'),
})
Expand Down Expand Up @@ -120,7 +126,8 @@ export default function SubmitTextProposalForm({ id, onSubmit, setIsDialogDisabl
<TextareaAutosize
{...field}
minRows={5}
aria-label='empty textarea'
maxRows={10}
aria-label={`${FieldNames.Description}-textarea`}
placeholder={t('submit-text-proposal-form.description-lbl')}
/>

Expand All @@ -132,6 +139,21 @@ export default function SubmitTextProposalForm({ id, onSubmit, setIsDialogDisabl
</FormControl>
)}
/>

{formState[FieldNames.Description] && (
<Button onClick={() => setIsPreviewDialogOpen(true)}>
{t('submit-text-proposal-form.desc-preview-btn')}
</Button>
)}

<Dialog
action={<></>}
onClose={() => setIsPreviewDialogOpen(false)}
isOpened={isPreviewDialogOpen}
title={t('submit-text-proposal-form.desc-preview-title')}
>
<MarkdownViewer>{formState[FieldNames.Description]}</MarkdownViewer>
</Dialog>
</FormWrapper>
)
}
Expand All @@ -141,5 +163,9 @@ const TextareaAutosize = styled(BaseTextareaAutosize)(
box-sizing: border-box;
background: none;
padding: ${theme.spacing(2)} ${theme.spacing(1.75)};
&:focus {
outline: none;
}
`,
)
4 changes: 1 addition & 3 deletions src/components/Proposal/ProposalsSubmit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function ProposalsSubmit() {

const actions = useMemo(
() => {
const result = [
return [
{
label: t('proposals.submit-proposal-action'),
handler: () => {
Expand All @@ -36,8 +36,6 @@ export default function ProposalsSubmit() {
isDisabled: false,
},
]

return result
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[t],
Expand Down
2 changes: 2 additions & 0 deletions src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ export default {
"helper-text": "Please fill out the form below to create a new text proposal.",
"title-lbl": "Title",
"description-lbl": "Description",
"desc-preview-btn": "Preview",
"desc-preview-title": "Description preview",
},
"proposal-deposits": {
"title-lbl": "Deposits",
Expand Down
Loading

0 comments on commit 451efc2

Please sign in to comment.