Skip to content

Commit 3693936

Browse files
Merge pull request #29 from agokrim/Resolve-jobFom-State-Issue
Resolve the state issue : when editing a job we get the last job edited
2 parents f53b354 + 246916f commit 3693936

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/components/jobs/JobForm.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/**
22
* External dependencies.
33
*/
4+
import { useEffect } from '@wordpress/element';
5+
import { useParams } from 'react-router-dom';
46
import { useSelect, useDispatch } from '@wordpress/data';
57
import { __ } from '@wordpress/i18n';
68

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

2224
export default function JobForm({ job }: Props) {
2325
const dispatch = useDispatch();
26+
const { id } = useParams();
27+
const { invalidateResolutionForStoreSelector } = useDispatch(jobStore);
28+
2429
const jobTypes: Array<Select2SingleRow> = useSelect(
2530
(select) => select(jobStore).getJobTypes(),
2631
[]
@@ -36,6 +41,12 @@ export default function JobForm({ job }: Props) {
3641
[]
3742
);
3843

44+
useEffect(() => {
45+
if (parseInt(id + '') !== form.id) {
46+
invalidateResolutionForStoreSelector('getJobDetail');
47+
}
48+
}, [id, invalidateResolutionForStoreSelector]);
49+
3950
const loadingJobs: boolean = useSelect(
4051
(select) => select(jobStore).getLoadingJobs(),
4152
[]

0 commit comments

Comments
 (0)