Skip to content

Commit 70c8131

Browse files
committed
feat: invalidate cache on signature request changes
Without this patch adding a new signature request to the database doesn't invalidate the cache right away. This needs to be triggered manually.
1 parent 0ba55d3 commit 70c8131

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/client/supabase.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,21 @@ const handleChangeOrders = (
204204
}
205205
};
206206

207+
/* eslint-disable @typescript-eslint/no-explicit-any */
208+
const handleChangeSignatureRequests = (
209+
payload: RealtimePostgresChangesPayload<{ [key: string]: any }>,
210+
) => {
211+
switch (payload.eventType) {
212+
case "INSERT":
213+
case "UPDATE":
214+
case "DELETE":
215+
cache.invalidate([{ typename: "SignatureRequest" }]);
216+
break;
217+
default:
218+
break;
219+
}
220+
};
221+
207222
supabaseCaching
208223
.channel("schema-db-changes")
209224
.on(
@@ -402,4 +417,13 @@ supabaseData
402417
},
403418
(payload) => handleChangeOrders(payload),
404419
)
420+
.on(
421+
"postgres_changes",
422+
{
423+
event: "*",
424+
schema: "public",
425+
table: "signature_requests",
426+
},
427+
(payload) => handleChangeSignatureRequests(payload),
428+
)
405429
.subscribe();

0 commit comments

Comments
 (0)