-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2027 from bcgov/1212-no-multiple-tab-save
feat: cannot save outdated data
- Loading branch information
Showing
14 changed files
with
282 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import Modal from '@button-inc/bcgov-theme/Modal'; | ||
import Button from '@button-inc/bcgov-theme/Button'; | ||
import { useRouter } from 'next/router'; | ||
import styled from 'styled-components'; | ||
|
||
const StyledText = styled.p` | ||
text-align: center; | ||
`; | ||
|
||
const ButtonContainer = styled.div` | ||
display: flex; | ||
justify-content: center; | ||
`; | ||
|
||
const ConflictModal = ({ id }) => { | ||
const router = useRouter(); | ||
return ( | ||
<Modal id={id}> | ||
<Modal.Header>Error</Modal.Header> | ||
<Modal.Content> | ||
<StyledText> | ||
The form could not save. This sometimes happens when your application | ||
is open in multiple tabs. | ||
</StyledText> | ||
<StyledText> | ||
Unfortunately any recent work on this page has been lost | ||
</StyledText> | ||
<ButtonContainer> | ||
<Button | ||
onClick={() => { | ||
window.location.hash = ''; | ||
router.reload(); | ||
}} | ||
> | ||
Refresh & Continue | ||
</Button> | ||
</ButtonContainer> | ||
</Modal.Content> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default ConflictModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react'; | ||
import { render, fireEvent } from '@testing-library/react'; | ||
import { useRouter } from 'next/router'; | ||
import ConflictModal from 'components/Form/ConflictModal'; | ||
|
||
jest.mock('next/router', () => ({ | ||
useRouter: jest.fn(), | ||
})); | ||
|
||
describe('Conflict Modal tests', () => { | ||
it('renders the modal with error header and text content', () => { | ||
const { getByText } = render(<ConflictModal id="test-id" />); | ||
expect(getByText('Error')).toBeInTheDocument(); | ||
expect( | ||
getByText( | ||
'The form could not save. This sometimes happens when your application is open in multiple tabs.' | ||
) | ||
).toBeInTheDocument(); | ||
expect( | ||
getByText('Unfortunately any recent work on this page has been lost') | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('calls router.reload() when the button is clicked', () => { | ||
const mockReload = jest.fn(); | ||
useRouter.mockImplementation(() => ({ | ||
reload: mockReload, | ||
})); | ||
|
||
const { getByText } = render(<ConflictModal id="test-id" />); | ||
fireEvent.click(getByText('Refresh & Continue')); | ||
expect(window.location.hash).toBe(''); | ||
expect(mockReload).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
-- Deploy ccbc:mutations/update_application_form to pg | ||
|
||
begin; | ||
|
||
create or replace function ccbc_public.update_application_form(form_data_row_id int, json_data jsonb, last_edited_page varchar) | ||
returns ccbc_public.form_data as | ||
$$ | ||
|
||
update ccbc_public.form_data | ||
set | ||
-- use json concatenation operator to merge the provided json_data with the dynamic submission values | ||
json_data = $2 || jsonb_build_object( | ||
'submission', coalesce($2->'submission', jsonb_build_object()) || jsonb_build_object( | ||
'submissionCompletedFor', $2->'organizationProfile'->'organizationName', | ||
'submissionDate', (date_trunc('day', now(), 'America/Vancouver')::date) | ||
) | ||
), | ||
last_edited_page = $3 | ||
where id = form_data_row_id | ||
returning *; | ||
|
||
$$ language sql; | ||
|
||
grant execute on function ccbc_public.update_application_form to ccbc_auth_user; | ||
|
||
comment on function ccbc_public.update_application_form is | ||
$$ | ||
Mutation to update the "application" form. | ||
This mutation should only be used by applicants as it sets the submission page data | ||
$$; | ||
|
||
|
||
commit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,35 @@ | ||
-- Revert ccbc:mutations/update_application_form_data from pg | ||
-- Deploy ccbc:mutations/update_application_form to pg | ||
|
||
begin; | ||
|
||
drop function ccbc_public.update_application_form; | ||
|
||
create or replace function ccbc_public.update_application_form(form_data_row_id int, json_data jsonb, last_edited_page varchar) | ||
returns ccbc_public.form_data as | ||
$$ | ||
|
||
update ccbc_public.form_data | ||
set | ||
-- use json concatenation operator to merge the provided json_data with the dynamic submission values | ||
json_data = $2 || jsonb_build_object( | ||
'submission', coalesce($2->'submission', jsonb_build_object()) || jsonb_build_object( | ||
'submissionCompletedFor', $2->'organizationProfile'->'organizationName', | ||
'submissionDate', (date_trunc('day', now(), 'America/Vancouver')::date) | ||
) | ||
), | ||
last_edited_page = $3 | ||
where id = form_data_row_id | ||
returning *; | ||
|
||
$$ language sql; | ||
|
||
grant execute on function ccbc_public.update_application_form to ccbc_auth_user; | ||
|
||
comment on function ccbc_public.update_application_form is | ||
$$ | ||
Mutation to update the "application" form. | ||
This mutation should only be used by applicants as it sets the submission page data | ||
$$; | ||
|
||
|
||
commit; |
Oops, something went wrong.