Skip to content

Commit

Permalink
fix: #1959 submit modal wizzard wrong close modal behavior (#1960)
Browse files Browse the repository at this point in the history
  • Loading branch information
NghiaPham authored Jul 3, 2020
1 parent 50043bb commit bd66470
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ exports[`Modal should match a snapshot for ModalHeader 1`] = `
className="delete"
data-test="modal-close-button"
onClick={[Function]}
type="button"
/>
</header>
`;
1 change: 1 addition & 0 deletions packages/elements/src/components/Modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const ModalHeader: React.SFC<ModalHeaderProps> = ({ title, afterClose })
className="delete"
aria-label="close"
data-test="modal-close-button"
type="button"
onClick={event => {
event.preventDefault()
afterClose && afterClose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ exports[`AppConfirmInstallContent should match snapshot 1`] = `
className="delete"
data-test="modal-close-button"
onClick={[Function]}
type="button"
/>
</header>
</Component>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ exports[`AppConfirmUninstall render correctly 1`] = `
className="delete"
data-test="modal-close-button"
onClick={[Function]}
type="button"
/>
</header>
</Component>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ exports[`ConfirmUninstall should match a snapshot 1`] = `
className="delete"
data-test="modal-close-button"
onClick={[Function]}
type="button"
/>
</header>
</Component>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ exports[`SubmitAppWizard should match snapshot when visible = true 1`] = `
}
onSubmit={[Function]}
>
<Form>
<Form
onKeyPress={[Function]}
>
<Component
afterClose={[Function]}
title="Before you start"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('SubmitAppWizardModal', () => {
getReduxState: (getReduxState as unknown) as () => ReduxState,
selectSubmitAppFormState: () => 'PENDING',
})()
expect(afterClose).toHaveBeenCalled()
})
})
test('handleUseEffect should run correctly', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ export const customAfterClose = ({
// Has to access redux state of formState manually because it will lead to <Modal/> and result many weird bugs
// E.g: Formik state reset, wizzard step state reset
const submitAppFormState = selectSubmitAppFormState(getReduxState())

if (submitAppFormState === 'SUCCESS') {
const page = qs.parse(location.search)?.page || 1
dispatch(developerRequestData({ page }))
afterClose()
}

afterClose()
}

export const handleUseEffect = (dispatch: Dispatch) => () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,17 @@ export const SubmitAppWizard: React.FC<Pick<ModalProps, 'afterClose'>> = ({ afte
onSubmit={handleSubmit({ setWizardStep, dispatch })}
validationSchema={validationSchemas[currentWizardStep]}
>
<Form>
<Form
onKeyPress={e => {
const key = e.charCode || e.keyCode || 0
// prevent submit form using enter
// not handle yet
const enterKeyCode = 13
if (key === enterKeyCode) {
e.preventDefault()
}
}}
>
<ModalHeader title={titleMap[currentWizardStep]} afterClose={afterClose} />
<CurrentStepComponent afterClose={afterClose} setWizardStep={setWizardStep} />
</Form>
Expand Down
2 changes: 1 addition & 1 deletion packages/marketplace/src/tests/badges/badge-branches.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/marketplace/src/tests/badges/badge-functions.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/marketplace/src/tests/badges/badge-lines.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/marketplace/src/tests/badges/badge-statements.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bd66470

Please sign in to comment.