Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Resolve the state issue : when editing a job we get the last job edited #29

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/components/jobs/JobForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/**
* External dependencies.
*/
import { useEffect } from '@wordpress/element';
import { useParams } from 'react-router-dom';
import { useSelect, useDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';

Expand All @@ -21,6 +23,9 @@ type Props = {

export default function JobForm({ job }: Props) {
const dispatch = useDispatch();
const { id } = useParams();
const { invalidateResolutionForStoreSelector } = useDispatch(jobStore);

const jobTypes: Array<Select2SingleRow> = useSelect(
(select) => select(jobStore).getJobTypes(),
[]
Expand All @@ -36,6 +41,12 @@ export default function JobForm({ job }: Props) {
[]
);

useEffect(() => {
if (parseInt(id + '') !== form.id) {
invalidateResolutionForStoreSelector('getJobDetail');
}
}, [id, invalidateResolutionForStoreSelector]);

const loadingJobs: boolean = useSelect(
(select) => select(jobStore).getLoadingJobs(),
[]
Expand Down