feat(secret-reminders): rework secret reminders logic

This commit is contained in:
Carlos Monastyrski
2025-07-04 09:47:36 -03:00
parent f6002d81b3
commit 0efc314f33
34 changed files with 1709 additions and 535 deletions
@@ -0,0 +1,3 @@
export { useDeleteReminder } from "./queries";
export { useCreateReminder } from "./queries";
export { useGetReminder } from "./queries";
@@ -0,0 +1,62 @@
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { CreateReminderDTO, DeleteReminderDTO, Reminder } from "./types";
export const reminderKeys = {
getReminder: (secretId: string, projectId: string) =>
["get-reminder", secretId, projectId] as const
};
export const useCreateReminder = (secretId: string, projectId: string) => {
const queryClient = useQueryClient();
return useMutation<Reminder, object, CreateReminderDTO>({
mutationFn: async ({ message, repeatDays, nextReminderDate, recipients }) => {
const { data } = await apiRequest.post<{ reminder: Reminder }>(
`/api/v1/reminders/${projectId}/reminder`,
{
secretId,
message,
repeatDays,
nextReminderDate,
recipients
}
);
return data.reminder;
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: reminderKeys.getReminder(secretId, projectId) });
}
});
};
export const useDeleteReminder = (secretId: string, projectId: string) => {
const queryClient = useQueryClient();
return useMutation<Reminder, object, DeleteReminderDTO>({
mutationFn: async () => {
const { data } = await apiRequest.delete<{ reminder: Reminder }>(
`/api/v1/reminders/${projectId}/reminder/${secretId}`
);
return data.reminder;
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: reminderKeys.getReminder(secretId, projectId) });
}
});
};
export const useGetReminder = (secretId: string, projectId: string) => {
return useQuery({
queryKey: reminderKeys.getReminder(secretId, projectId),
queryFn: async () => {
const { data } = await apiRequest.get<{ reminder: Reminder }>(
`/api/v1/reminders/${projectId}/reminder/${secretId}`
);
return data.reminder;
},
enabled: Boolean(secretId && projectId)
});
};
+21
View File
@@ -0,0 +1,21 @@
export type CreateReminderDTO = {
message?: string | null;
repeatDays?: number | null;
nextReminderDate?: Date | null;
secretId: string;
recipients?: string[];
};
export type DeleteReminderDTO = {
secretId: string;
reminderId: string;
};
export type Reminder = {
id: string;
message?: string | null;
repeatDays?: number | null;
nextReminderDate?: Date | null;
secretId: string;
recipients?: string[];
};