Keep adoption transfer codes stable
Deploy / deploy-dev (push) Has been skipped
Deploy / deploy-prod (push) Successful in 2m17s

This commit is contained in:
Corey Blais
2026-06-03 12:10:27 -04:00
parent 7b7171c109
commit 0411ec5175
5 changed files with 116 additions and 40 deletions
+40
View File
@@ -1665,6 +1665,46 @@ function App() {
setEditingVeterinaryInfo(false);
}, [selectedBird]);
useEffect(() => {
const selectedBirdId = selectedBird?.id;
if (!selectedBirdId || !authToken || adoptionTransferCodes[selectedBirdId]) {
return;
}
let canceled = false;
const loadOpenTransferCode = async () => {
try {
const response = await apiFetch(`/birds/${selectedBirdId}/transfer-code`, authToken);
if (!response.ok) {
return;
}
const data =
(await readJsonSafely<{
transferCode?: {
code?: string;
} | null;
}>(response)) ?? {};
const code = data.transferCode?.code;
if (!canceled && code) {
setAdoptionTransferCodes((current) => ({ ...current, [selectedBirdId]: code }));
}
} catch {
// Transfer codes are optional until a report/code is created.
}
};
void loadOpenTransferCode();
return () => {
canceled = true;
};
}, [adoptionTransferCodes, authToken, selectedBird?.id]);
const overviewWindowStartDate = useMemo(() => {
const startDate = new Date();
startDate.setHours(0, 0, 0, 0);