Skip to content

Commit 11eb94d

Browse files
fix deprecation: switch to jotai-family for atom family (#15290)
1 parent 8b8b44f commit 11eb94d

File tree

6 files changed

+43
-31
lines changed

6 files changed

+43
-31
lines changed

package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"i18next-resources-to-backend": "^1.2.1",
108108
"input-otp": "^1.4.2",
109109
"jotai": "^2.12.3",
110+
"jotai-family": "^1.0.1",
110111
"jspdf": "^3.0.2",
111112
"libphonenumber-js": "^1.11.18",
112113
"lucide-react": "^0.548.0",

src/atoms/location-atom.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { LocationRead } from "@/types/location/location";
2+
import { atomFamily } from "jotai-family";
3+
import { atomWithStorage } from "jotai/utils";
4+
5+
/**
6+
* Atom family for payment reconcilation location caching per facility
7+
*/
8+
export const paymentReconcilationLocationAtom = atomFamily(
9+
(facilityId: string) =>
10+
atomWithStorage<LocationRead | null>(
11+
`payment_reconcilation_location_cache--${facilityId}`,
12+
null,
13+
),
14+
);
15+
16+
/**
17+
* Helper to invalidate all payment reconcilation location caches
18+
*/
19+
export const invalidateAllPaymentReconcilationLocationCaches = () => {
20+
for (const key in localStorage) {
21+
if (key.startsWith("payment_reconcilation_location_cache--")) {
22+
localStorage.removeItem(key);
23+
}
24+
}
25+
};

src/components/Auth/Login.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ import FiltersCache from "@/Utils/FiltersCache";
4242
import ViewCache from "@/Utils/ViewCache";
4343
import mutate from "@/Utils/request/mutate";
4444
import { HTTPError } from "@/Utils/request/types";
45-
import { invalidateAllLocationCaches } from "@/atoms/location-atom";
4645
import authApi from "@/types/auth/authApi";
4746
import { TokenData } from "@/types/otp/otp";
4847
import otpApi from "@/types/otp/otpApi";
4948

5049
import { clearQueryPersistenceCache } from "@/Utils/request/queryClient";
50+
import { invalidateAllPaymentReconcilationLocationCaches } from "@/atoms/paymentReconcilationLocationAtom";
5151
import { AuthHero } from "./AuthHero";
5252

5353
interface OtpLoginData {
@@ -245,7 +245,7 @@ const Login = (props: LoginProps) => {
245245
if (!validated) return;
246246

247247
FiltersCache.invalidateAll();
248-
invalidateAllLocationCaches();
248+
invalidateAllPaymentReconcilationLocationCaches();
249249
clearQueryPersistenceCache();
250250
try {
251251
await signIn(validated);

src/pages/Facility/billing/PaymentReconciliationSheet.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import {
4040
} from "@/components/ui/sheet";
4141
import { Textarea } from "@/components/ui/textarea";
4242

43-
import { locationAtomFamily } from "@/atoms/location-atom";
43+
import { paymentReconcilationLocationAtom } from "@/atoms/paymentReconcilationLocationAtom";
4444
import { LocationPicker } from "@/components/Location/LocationPicker";
4545
import { Label } from "@/components/ui/label";
4646
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
@@ -185,7 +185,7 @@ export function PaymentReconciliationSheet({
185185
const { t } = useTranslation();
186186
const queryClient = useQueryClient();
187187
const [selectedLocationObject, setSelectedLocationObject] = useAtom(
188-
locationAtomFamily(facilityId),
188+
paymentReconcilationLocationAtom(facilityId),
189189
);
190190
useShortcutSubContext();
191191

0 commit comments

Comments
 (0)