Skip to content

Commit

Permalink
[Form]: fixed bug when beforeLeave modal appears in case of redirec…
Browse files Browse the repository at this point in the history
…t in `onSuccess` callback.
  • Loading branch information
AlekseyManetov committed Oct 7, 2024
1 parent e05c1d2 commit 8058a95
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
12 changes: 11 additions & 1 deletion public/docs/content/examples-labeledInput-Basic.json
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
{"object":"value","document":{"object":"document","data":{},"nodes":[{"object":"block","type":"paragraph","data":{},"nodes":[{"object":"text","text":"Basic LabeledInput usage","marks":[]}]}]}}
[
{
"type": "paragraph",
"data": {},
"children": [
{
"text": "Basic LabeledInput usage"
}
]
}
]
4 changes: 2 additions & 2 deletions uui-core/src/data/forms/__tests__/useForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ describe('useForm', () => {

it('Should unblock router when form is saved', async () => {
const saveMock = jest.fn().mockResolvedValue(true);
const beforeLeaveMock = jest.fn().mockResolvedValue(false);
const beforeLeaveMock = jest.fn().mockRejectedValue(false);
const { wrapper, testUuiCtx: svc } = getDefaultUUiContextWrapper();
const props = {
value: testData,
Expand Down Expand Up @@ -676,7 +676,7 @@ describe('useForm', () => {
expect(beforeLeaveMock).toHaveBeenCalledTimes(1);
});

it('Should make redirect and lock form aging if beforeLeave return "remain"', async () => {
it('Should make redirect and lock form aging if beforeLeave returns "remain"', async () => {
const saveMock = jest.fn().mockResolvedValue(true);
const beforeLeaveMock = jest.fn().mockResolvedValue('remain');
const { wrapper, testUuiCtx: svc } = getDefaultUUiContextWrapper();
Expand Down
4 changes: 2 additions & 2 deletions uui-core/src/data/forms/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,9 @@ export function useForm<T>(props: UseFormProps<T>): IFormApi<T> {
}
flushSync(() => {
resetForm(newState);
removeUnsavedChanges();
unblock();
});
removeUnsavedChanges();
unblock();

if (propsRef.current.onSuccess && response) {
propsRef.current.onSuccess(response.form, isSavedBeforeLeave);
Expand Down

0 comments on commit 8058a95

Please sign in to comment.