Redirect to experiments page after deleting experiment (#21)
This commit is contained in:
@@ -41,12 +41,9 @@ const DeleteButton = () => {
|
|||||||
|
|
||||||
const [onDeleteConfirm] = useHandledAsyncCallback(async () => {
|
const [onDeleteConfirm] = useHandledAsyncCallback(async () => {
|
||||||
if (!experiment.data?.id) return;
|
if (!experiment.data?.id) return;
|
||||||
const nextExperiment = await mutation.mutateAsync({ id: experiment.data.id });
|
await mutation.mutateAsync({ id: experiment.data.id });
|
||||||
await utils.experiments.list.invalidate();
|
await utils.experiments.list.invalidate();
|
||||||
|
await router.push({ pathname: "/experiments" });
|
||||||
if (nextExperiment) {
|
|
||||||
await router.push({ pathname: "/experiments/[id]", query: { id: nextExperiment } });
|
|
||||||
}
|
|
||||||
onClose();
|
onClose();
|
||||||
}, [mutation, experiment.data?.id, router]);
|
}, [mutation, experiment.data?.id, router]);
|
||||||
|
|
||||||
|
|||||||
@@ -110,14 +110,5 @@ export const experimentsRouter = createTRPCRouter({
|
|||||||
id: input.id,
|
id: input.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Return the ID of the newest existing experiment so the client can redirect to it
|
|
||||||
const newestExperiment = await prisma.experiment.findFirst({
|
|
||||||
orderBy: {
|
|
||||||
sortIndex: "desc",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return newestExperiment?.id;
|
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user