Keep adoption transfer codes stable
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user