Skip to content

Commit

Permalink
fix: prevent navigation on submit
Browse files Browse the repository at this point in the history
  • Loading branch information
andyesp committed Apr 25, 2024
1 parent f3de8cc commit ce3e6c5
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/components/Proposal/Submit/ProposalSubmitCatalystPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ export default function ProposalSubmitCatalystPage({ catalystType }: Props) {
const setCoAuthors = (addresses?: string[]) => setValue('coAuthors', addresses)

useEffect(() => {
preventNavigation.current = isDirty
}, [isDirty])
preventNavigation.current = isDirty && !isSubmitting
}, [isDirty, isSubmitting])

const onSubmit: SubmitHandler<NewProposalCatalyst> = async (data) => {
const errors = [isErrorOnContentStatus, isErrorOnLambdasStatus].filter(Boolean)
Expand Down
4 changes: 2 additions & 2 deletions src/components/Proposal/Submit/ProposalSubmitHiringPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ export default function ProposalSubmitHiringPage({ type, committees, isCommittee
}, [committees, setValue, type])

useEffect(() => {
preventNavigation.current = isDirty
}, [isDirty])
preventNavigation.current = isDirty && !isSubmitting
}, [isDirty, isSubmitting])

const onSubmit: SubmitHandler<HiringState> = async (data) => {
setFormDisabled(true)
Expand Down
6 changes: 3 additions & 3 deletions src/components/Proposal/Submit/ProposalSubmitPoiPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default function ProposalSubmitPoiPage({ poiType }: Props) {

const {
handleSubmit,
formState: { isDirty, errors },
formState: { isDirty, errors, isSubmitting },
control,
setValue,
watch,
Expand Down Expand Up @@ -138,8 +138,8 @@ export default function ProposalSubmitPoiPage({ poiType }: Props) {
const setCoAuthors = (addresses?: string[]) => setValue('coAuthors', addresses)

useEffect(() => {
preventNavigation.current = isDirty
}, [isDirty])
preventNavigation.current = isDirty && !isSubmitting
}, [isDirty, isSubmitting])

if (accountState.loading) {
return <LoadingView />
Expand Down
4 changes: 2 additions & 2 deletions src/pages/submit/ban-name.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export default function SubmitBanName() {
const setCoAuthors = (addresses?: string[]) => setValue('coAuthors', addresses)

useEffect(() => {
preventNavigation.current = isDirty
}, [isDirty])
preventNavigation.current = isDirty && !isSubmitting
}, [isDirty, isSubmitting])

const onSubmit: SubmitHandler<NewProposalBanName> = async (data) => {
setFormDisabled(true)
Expand Down
2 changes: 2 additions & 0 deletions src/pages/submit/bid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export default function SubmitBid() {

const submit = useCallback(async () => {
if (allSectionsValid) {
preventNavigation.current = false
setIsFormDisabled(true)
setIsLoading(true)
const bidRequestParsed = parseStringsAsNumbers(bidRequest as BidRequest)
Expand All @@ -141,6 +142,7 @@ export default function SubmitBid() {
setSubmitError(error.body?.error || error.message)
setIsLoading(false)
setIsFormDisabled(false)
preventNavigation.current = true
}
}
}, [allSectionsValid, bidRequest, navigate])
Expand Down
4 changes: 2 additions & 2 deletions src/pages/submit/draft.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export default function SubmitDraftProposal() {
const setCoAuthors = (addresses?: string[]) => setValue('coAuthors', addresses)

useEffect(() => {
preventNavigation.current = isDirty
}, [isDirty])
preventNavigation.current = isDirty && !isSubmitting
}, [isDirty, isSubmitting])

useEffect(() => {
if (preselectedLinkedProposalId) {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/submit/governance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ export default function SubmitGovernanceProposal() {
const setCoAuthors = (addresses?: string[]) => setValue('coAuthors', addresses)

useEffect(() => {
preventNavigation.current = isDirty
}, [isDirty])
preventNavigation.current = isDirty && !isSubmitting
}, [isDirty, isSubmitting])

useEffect(() => {
if (preselectedLinkedProposalId) {
Expand Down
2 changes: 2 additions & 0 deletions src/pages/submit/grant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export default function SubmitGrant() {

const submit = useCallback(() => {
if (allSectionsValid) {
preventNavigation.current = false
setIsFormDisabled(true)
Promise.resolve()
.then(async () => {
Expand All @@ -163,6 +164,7 @@ export default function SubmitGrant() {
console.error(err, { ...err })
setSubmitError(err.body?.error || err.message)
setIsFormDisabled(false)
preventNavigation.current = true
})
}
}, [allSectionsValid, grantRequest, navigate])
Expand Down
4 changes: 2 additions & 2 deletions src/pages/submit/linked-wearables.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ export default function SubmitLinkedWearables() {
const setCoAuthors = (addresses?: string[]) => setValue('coAuthors', addresses)

useEffect(() => {
preventNavigation.current = isDirty
}, [isDirty])
preventNavigation.current = isDirty && !isSubmitting
}, [isDirty, isSubmitting])

const handleAddOption = (e: React.MouseEvent<HTMLButtonElement>, field: ListSectionType['section']) => {
e.preventDefault()
Expand Down
6 changes: 3 additions & 3 deletions src/pages/submit/pitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default function SubmitPitchProposal() {

const {
handleSubmit,
formState: { isDirty, errors },
formState: { isDirty, isSubmitting, errors },
control,
setValue,
watch,
Expand All @@ -62,8 +62,8 @@ export default function SubmitPitchProposal() {
const setCoAuthors = (addresses?: string[]) => setValue('coAuthors', addresses)

useEffect(() => {
preventNavigation.current = isDirty
}, [isDirty])
preventNavigation.current = isDirty && !isSubmitting
}, [isDirty, isSubmitting])

const onSubmit: SubmitHandler<NewProposalPitch> = async (data) => {
setFormDisabled(true)
Expand Down
4 changes: 2 additions & 2 deletions src/pages/submit/poll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ export default function SubmitPoll() {
}

useEffect(() => {
preventNavigation.current = isDirty
}, [isDirty])
preventNavigation.current = isDirty && !isSubmitting
}, [isDirty, isSubmitting])

const isValidChoices = useCallback(
(choices: Record<string, string>) => {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/submit/tender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ export default function SubmitTenderProposal() {
const setCoAuthors = (addresses?: string[]) => setValue('coAuthors', addresses)

useEffect(() => {
preventNavigation.current = isDirty
}, [isDirty])
preventNavigation.current = isDirty && !isSubmitting
}, [isDirty, isSubmitting])

useEffect(() => {
if (preselectedLinkedProposalId) {
Expand Down

0 comments on commit ce3e6c5

Please sign in to comment.