pl-fe: migrate birthday reminders to tanstack query

Signed-off-by: mkljczk <git@mkljczk.pl>
This commit is contained in:
mkljczk
2024-12-04 18:10:14 +01:00
parent 443e15c591
commit fac30c2ea9
5 changed files with 51 additions and 84 deletions

View File

@ -0,0 +1,22 @@
import { useQuery } from '@tanstack/react-query';
import { importEntities } from 'pl-fe/actions/importer';
import { useAppDispatch } from 'pl-fe/hooks/use-app-dispatch';
import { useClient } from 'pl-fe/hooks/use-client';
const useBirthdayReminders = (month: number, day: number) => {
const client = useClient();
const dispatch = useAppDispatch();
return useQuery({
queryKey: ['accountsLists', 'birthdayReminders', month, day],
queryFn: () => client.accounts.getBirthdays(day, month).then((accounts) => {
dispatch(importEntities({ accounts }));
return accounts.map(({ id }) => id);
}),
});
};
export { useBirthdayReminders };