Skip to content

Commit

Permalink
Fix the "?" redirection on Chrome (#1020)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpierre authored and luisivan committed Sep 10, 2019
1 parent 7831186 commit 84116fb
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 49 deletions.
3 changes: 2 additions & 1 deletion src/templates/company/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export default {
`,
// longdesc: '',
// caseStudyUrl: 'https://aragon.org/case-study/company',
userGuide: 'https://help.aragon.org/article/30-create-a-new-company-organization',
userGuide:
'https://help.aragon.org/article/30-create-a-new-company-organization',
sourceCodeUrl:
'https://github.com/aragon/dao-templates/tree/templates-company-v1.0.0/templates/company',
registry: 'aragonpm.eth',
Expand Down
18 changes: 11 additions & 7 deletions src/templates/kit/ClaimDomain.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ function ClaimDomain({
setDisplayError(false)
}, [])

const handleNext = useCallback(() => {
setDisplayError(domainCheckStatus === DOMAIN_ERROR)
if (domainCheckStatus === DOMAIN_CHECK) {
next({ ...data, domain })
}
}, [domain, next, data, domainCheckStatus])
const handleSubmit = useCallback(
event => {
event.preventDefault()
setDisplayError(domainCheckStatus === DOMAIN_ERROR)
if (domainCheckStatus === DOMAIN_CHECK) {
next({ ...data, domain })
}
},
[domain, next, data, domainCheckStatus]
)

// focus on mount
const handleDomainFieldRef = useCallback(ref => {
Expand Down Expand Up @@ -75,7 +79,7 @@ function ClaimDomain({
nextEnabled={Boolean(domain.trim())}
nextLabel={`Next: ${screens[screenIndex + 1][0]}`}
onBack={back}
onNext={handleNext}
onNext={handleSubmit}
/>
</form>
)
Expand Down
38 changes: 21 additions & 17 deletions src/templates/kit/Tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,26 @@ function Tokens({
)
}, [])

const handleNext = useCallback(() => {
const error = validationError(tokenName, tokenSymbol, members)
setFormError(error)
if (!error) {
next({
...data,
tokens: {
tokenName,
tokenSymbol,
members: members.filter(
([account, stake]) => isAddress(account) && stake > 0
),
},
})
}
}, [data, next, tokenName, tokenSymbol, members])
const handleSubmit = useCallback(
event => {
event.preventDefault()
const error = validationError(tokenName, tokenSymbol, members)
setFormError(error)
if (!error) {
next({
...data,
tokens: {
tokenName,
tokenSymbol,
members: members.filter(
([account, stake]) => isAddress(account) && stake > 0
),
},
})
}
},
[data, next, tokenName, tokenSymbol, members]
)

const handleTokenNameRef = useCallback(element => {
if (element) {
Expand Down Expand Up @@ -280,7 +284,7 @@ function Tokens({
nextEnabled={!disableNext}
nextLabel={`Next: ${screens[screenIndex + 1][0]}`}
onBack={back}
onNext={handleNext}
onNext={handleSubmit}
/>
</form>
)
Expand Down
48 changes: 26 additions & 22 deletions src/templates/kit/Voting.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,28 +103,32 @@ function Voting({ back, data, fields, next, screenIndex, screens }) {

const prevNextRef = useRef()

const handleNext = useCallback(() => {
const error = validationError(duration)
setFormError(error)

// If one of the percentage fields is focused when the form is submitted,
// move the focus on the next button instead.
if (isPercentageFieldFocused() && prevNextRef.current) {
prevNextRef.current.focusNext()
return
}
const handleSubmit = useCallback(
event => {
event.preventDefault()
const error = validationError(duration)
setFormError(error)

// If one of the percentage fields is focused when the form is submitted,
// move the focus on the next button instead.
if (isPercentageFieldFocused() && prevNextRef.current) {
prevNextRef.current.focusNext()
return
}

if (!error) {
next({
...data,
voting: {
support: Math.floor(support),
quorum: Math.floor(quorum),
duration,
},
})
}
}, [data, next, support, quorum, duration, isPercentageFieldFocused])
if (!error) {
next({
...data,
voting: {
support: Math.floor(support),
quorum: Math.floor(quorum),
duration,
},
})
}
},
[data, next, support, quorum, duration, isPercentageFieldFocused]
)

return (
<form
Expand Down Expand Up @@ -210,7 +214,7 @@ function Voting({ back, data, fields, next, screenIndex, screens }) {
nextEnabled
nextLabel={`Next: ${screens[screenIndex + 1][0]}`}
onBack={back}
onNext={handleNext}
onNext={handleSubmit}
/>
</div>
</form>
Expand Down
3 changes: 2 additions & 1 deletion src/templates/membership/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export default {
`,
// longdesc: ``,
// caseStudyUrl: 'https://aragon.org/case-study/membership',
userGuide: 'https://help.aragon.org/article/34-create-a-new-membership-organization',
userGuide:
'https://help.aragon.org/article/34-create-a-new-membership-organization',
sourceCodeUrl:
'https://github.com/aragon/dao-templates/tree/templates-membership-v1.0.0/templates/membership',
registry: 'aragonpm.eth',
Expand Down
3 changes: 2 additions & 1 deletion src/templates/reputation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export default {
`,
// longdesc: ``,
// caseStudyUrl: 'https://aragon.org/case-study/reputation',
userGuide: 'https://help.aragon.org/article/32-create-a-new-reputation-organization',
userGuide:
'https://help.aragon.org/article/32-create-a-new-reputation-organization',
sourceCodeUrl:
'https://github.com/aragon/dao-templates/tree/templates-reputation-v1.0.0/templates/reputation',
registry: 'aragonpm.eth',
Expand Down

0 comments on commit 84116fb

Please sign in to comment.