Skip to content

Commit

Permalink
fix(app): disable save button once clicked on name transfer screen (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
smb2268 authored Sep 11, 2024
1 parent 9c83c6d commit 455d026
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 3 additions & 1 deletion app/src/organisms/QuickTransferFlow/NameQuickTransfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function NameQuickTransfer(props: NameQuickTransferProps): JSX.Element {
const { t } = useTranslation('quick_transfer')
const [name, setName] = React.useState('')
const keyboardRef = React.useRef(null)
const [isSaving, setIsSaving] = React.useState<boolean>(false)

let error: string | null = null
if (name.length > 60) {
Expand All @@ -38,9 +39,10 @@ export function NameQuickTransfer(props: NameQuickTransferProps): JSX.Element {
header={t('name_your_transfer')}
buttonText={t('save')}
onClickButton={() => {
setIsSaving(true)
onSave(name)
}}
buttonIsDisabled={name === '' || error != null}
buttonIsDisabled={name === '' || error != null || isSaving}
/>
<Flex
// height of ChildNavigation
Expand Down
10 changes: 8 additions & 2 deletions app/src/organisms/QuickTransferFlow/SaveOrRunModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ interface SaveOrRunModalProps {

export const SaveOrRunModal = (props: SaveOrRunModalProps): JSX.Element => {
const { t } = useTranslation('quick_transfer')
const [showNameTransfer, setShowNameTransfer] = React.useState(false)
const [showNameTransfer, setShowNameTransfer] = React.useState<boolean>(false)
const [isLoading, setIsLoading] = React.useState<boolean>(false)

return showNameTransfer ? (
<NameQuickTransfer onSave={props.onSave} />
Expand All @@ -43,6 +44,7 @@ export const SaveOrRunModal = (props: SaveOrRunModalProps): JSX.Element => {
<SmallButton
width="50%"
buttonText={t('save_for_later')}
disabled={isLoading}
onClick={() => {
setShowNameTransfer(true)
}}
Expand All @@ -51,7 +53,11 @@ export const SaveOrRunModal = (props: SaveOrRunModalProps): JSX.Element => {
<SmallButton
width="50%"
buttonText={t('run_now')}
onClick={props.onRun}
disabled={isLoading}
onClick={() => {
setIsLoading(true)
props.onRun()
}}
/>
</Flex>
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ describe('NameQuickTransfer', () => {
expect(saveBtn).toBeEnabled()
fireEvent.click(saveBtn)
expect(props.onSave).toHaveBeenCalled()
expect(saveBtn).toBeDisabled()
})

it('disables save if you enter more than 60 characters', () => {
Expand Down

0 comments on commit 455d026

Please sign in to comment.