Skip to content

Commit

Permalink
Merge pull request #204 from MinaFoundation/fix/create_proposal_form_…
Browse files Browse the repository at this point in the history
…improvements

form wider + create/save changes spinner on saving
  • Loading branch information
leomanza authored Mar 9, 2025
2 parents 4c53e99 + 3227e80 commit 3c1e973
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pgt-web-app",
"version": "0.1.105",
"version": "0.1.106",
"private": true,
"type": "module",
"scripts": {
Expand Down
9 changes: 6 additions & 3 deletions src/components/CreateProposal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export default function CreateProposal({ mode = 'create', proposalId }: Props) {
otherLinks: '',
})
const [errors, setErrors] = useState<ValidationErrors>({})
const [isSaving, setIsSaving] = useState<boolean>(false)

useEffect(() => {
const fetchProposal = async () => {
Expand Down Expand Up @@ -274,7 +275,7 @@ export default function CreateProposal({ mode = 'create', proposalId }: Props) {

const onSubmit = async (e: React.FormEvent) => {
e.preventDefault()

setIsSaving(true)
// Validate all fields before submission
let hasErrors = false
Object.entries(formData).forEach(([key, value]) => {
Expand All @@ -299,6 +300,7 @@ export default function CreateProposal({ mode = 'create', proposalId }: Props) {
description: 'Please fix the errors before submitting.',
variant: 'destructive',
})
setIsSaving(false)
return
}

Expand Down Expand Up @@ -343,6 +345,7 @@ export default function CreateProposal({ mode = 'create', proposalId }: Props) {
variant: 'destructive',
})
}
setIsSaving(false)
}

const getRemainingChars = (field: string, maxLength: number) => {
Expand Down Expand Up @@ -415,7 +418,7 @@ export default function CreateProposal({ mode = 'create', proposalId }: Props) {
}

return (
<div className="mx-auto max-w-4xl rounded-lg bg-white p-4 shadow-md">
<div className="mx-auto w-full max-w-6xl rounded-lg bg-white p-6 shadow-md">
<h1 className="mb-6 text-2xl font-bold">
{mode === 'create' ? 'Create New Proposal' : 'Edit Proposal'}
</h1>
Expand Down Expand Up @@ -930,7 +933,7 @@ export default function CreateProposal({ mode = 'create', proposalId }: Props) {
>
Cancel
</Button>
<Button type="submit">
<Button type="submit" loading={isSaving}>
{mode === 'create' ? 'Create Draft' : 'Save Changes'}
</Button>
</div>
Expand Down

0 comments on commit 3c1e973

Please sign in to comment.