refactor: improve return of reorder

This commit is contained in:
Carlos Valente
2025-05-16 20:23:35 +02:00
committed by arc-alex
parent 776649c997
commit e287215179
6 changed files with 36 additions and 15 deletions
+1 -1
View File
@@ -64,7 +64,7 @@ export type ReorderEntry = {
/**
* HTTP request to reorder an entry
*/
export async function patchReorderEntry(data: ReorderEntry): Promise<AxiosResponse<OntimeEntry>> {
export async function patchReorderEntry(data: ReorderEntry): Promise<AxiosResponse<Rundown>> {
return axios.patch(`${rundownPath}/reorder`, data);
}
@@ -549,6 +549,22 @@ export const useEntryActions = () => {
onError: (_error, _data, context) => {
queryClient.setQueryData<Rundown>(RUNDOWN, context?.previousData);
},
// Mutation finished, we update the rundown with the response
onSuccess: (response) => {
if (response.data) {
const { id, title, order, flatOrder, entries, revision } = response.data;
queryClient.setQueryData<Rundown>(RUNDOWN, {
id,
title,
order,
flatOrder,
entries,
revision,
});
}
},
// Mutation finished, failed or successful
// Fetch anyway, just to be sure
onSettled: () => {