@openmrs/esm-react-utils 6.3.1-pre.3073 → 6.3.1-pre.3077

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
- [0] Successfully compiled: 52 files with swc (153.39ms)
1
+ [0] Successfully compiled: 52 files with swc (180.44ms)
2
2
  [0] swc --strip-leading-paths src -d dist exited with code 0
3
3
  [1] tsc --project tsconfig.build.json exited with code 0
package/dist/useVisit.js CHANGED
@@ -40,7 +40,7 @@ dayjs.extend(isToday);
40
40
  retroData,
41
41
  retrospectiveVisitUuid
42
42
  ]);
43
- const currentVisitIsActive = useRef(false);
43
+ const previousCurrentVisit = useRef(null);
44
44
  useEffect(()=>{
45
45
  // if an active visit is created and there is no visit in context, set the context to the active visit
46
46
  if (manuallySetVisitUuid == null && !activeIsValidating && activeVisit) {
@@ -49,10 +49,10 @@ dayjs.extend(isToday);
49
49
  if (!retroIsValidating) {
50
50
  // if the current visit happened to be active but it just got ended (inactive), remove the
51
51
  // visit from context
52
- if (currentVisitIsActive && !retroIsValidating && currentVisit && currentVisit.stopDatetime) {
52
+ if (previousCurrentVisit.current && currentVisit && previousCurrentVisit.current.uuid === currentVisit.uuid && !previousCurrentVisit.current.stopDatetime && currentVisit.stopDatetime) {
53
53
  setVisitContext(null);
54
54
  }
55
- currentVisitIsActive.current = currentVisit ? !currentVisit.stopDatetime : false;
55
+ previousCurrentVisit.current = currentVisit;
56
56
  }
57
57
  }, [
58
58
  currentVisit,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-react-utils",
3
- "version": "6.3.1-pre.3073",
3
+ "version": "6.3.1-pre.3077",
4
4
  "license": "MPL-2.0",
5
5
  "description": "React utilities for OpenMRS.",
6
6
  "type": "module",
@@ -78,17 +78,17 @@
78
78
  "swr": "2.x"
79
79
  },
80
80
  "devDependencies": {
81
- "@openmrs/esm-api": "6.3.1-pre.3073",
82
- "@openmrs/esm-config": "6.3.1-pre.3073",
83
- "@openmrs/esm-context": "6.3.1-pre.3073",
84
- "@openmrs/esm-emr-api": "6.3.1-pre.3073",
85
- "@openmrs/esm-error-handling": "6.3.1-pre.3073",
86
- "@openmrs/esm-extensions": "6.3.1-pre.3073",
87
- "@openmrs/esm-feature-flags": "6.3.1-pre.3073",
88
- "@openmrs/esm-globals": "6.3.1-pre.3073",
89
- "@openmrs/esm-navigation": "6.3.1-pre.3073",
90
- "@openmrs/esm-state": "6.3.1-pre.3073",
91
- "@openmrs/esm-utils": "6.3.1-pre.3073",
81
+ "@openmrs/esm-api": "6.3.1-pre.3077",
82
+ "@openmrs/esm-config": "6.3.1-pre.3077",
83
+ "@openmrs/esm-context": "6.3.1-pre.3077",
84
+ "@openmrs/esm-emr-api": "6.3.1-pre.3077",
85
+ "@openmrs/esm-error-handling": "6.3.1-pre.3077",
86
+ "@openmrs/esm-extensions": "6.3.1-pre.3077",
87
+ "@openmrs/esm-feature-flags": "6.3.1-pre.3077",
88
+ "@openmrs/esm-globals": "6.3.1-pre.3077",
89
+ "@openmrs/esm-navigation": "6.3.1-pre.3077",
90
+ "@openmrs/esm-state": "6.3.1-pre.3077",
91
+ "@openmrs/esm-utils": "6.3.1-pre.3077",
92
92
  "@swc/cli": "^0.7.7",
93
93
  "@swc/core": "^1.11.29",
94
94
  "concurrently": "^9.1.2",
package/src/useVisit.ts CHANGED
@@ -73,7 +73,7 @@ export function useVisit(patientUuid: string, representation = defaultVisitCusto
73
73
  () => (retrospectiveVisitUuid && retroData ? retroData.data : null),
74
74
  [retroData, retrospectiveVisitUuid],
75
75
  );
76
- const currentVisitIsActive = useRef(false);
76
+ const previousCurrentVisit = useRef<Visit | null>(null);
77
77
 
78
78
  useEffect(() => {
79
79
  // if an active visit is created and there is no visit in context, set the context to the active visit
@@ -83,10 +83,10 @@ export function useVisit(patientUuid: string, representation = defaultVisitCusto
83
83
  if (!retroIsValidating) {
84
84
  // if the current visit happened to be active but it just got ended (inactive), remove the
85
85
  // visit from context
86
- if (currentVisitIsActive && !retroIsValidating && currentVisit && currentVisit.stopDatetime) {
86
+ if (previousCurrentVisit.current && currentVisit && previousCurrentVisit.current.uuid === currentVisit.uuid && !previousCurrentVisit.current.stopDatetime && currentVisit.stopDatetime) {
87
87
  setVisitContext(null);
88
88
  }
89
- currentVisitIsActive.current = currentVisit ? !currentVisit.stopDatetime : false;
89
+ previousCurrentVisit.current = currentVisit;
90
90
  }
91
91
  }, [currentVisit, manuallySetVisitUuid, activeVisit, activeIsValidating, retroIsValidating]);
92
92