()
| 6 | import { useHandledAsyncCallback, useSelectedProject } from "~/utils/hooks"; |
| 7 | |
| 8 | const NewMonitorButton = () => { |
| 9 | const router = useRouter(); |
| 10 | const createMonitorMutation = api.monitors.create.useMutation(); |
| 11 | const selectedProject = useSelectedProject().data; |
| 12 | const utils = api.useUtils(); |
| 13 | |
| 14 | const [createDataset, creationInProgress] = useHandledAsyncCallback(async () => { |
| 15 | if (!selectedProject) return; |
| 16 | |
| 17 | const response = await createMonitorMutation.mutateAsync({ |
| 18 | projectId: selectedProject.id, |
| 19 | initialFilters: [], |
| 20 | }); |
| 21 | |
| 22 | const monitorId = response.payload; |
| 23 | |
| 24 | await router.push({ |
| 25 | pathname: "/p/[projectSlug]/monitors/[id]", |
| 26 | query: { projectSlug: selectedProject.slug, id: monitorId }, |
| 27 | }); |
| 28 | await utils.monitors.list.invalidate(); |
| 29 | }, [selectedProject, utils]); |
| 30 | |
| 31 | return ( |
| 32 | <Button colorScheme="blue" isLoading={creationInProgress} onClick={createDataset}> |
| 33 | <HStack spacing={0}> |
| 34 | <Icon as={BsPlus} boxSize={6} strokeWidth={0.8} /> |
| 35 | <Text>New Monitor</Text> |
| 36 | </HStack> |
| 37 | </Button> |
| 38 | ); |
| 39 | }; |
| 40 | |
| 41 | export default NewMonitorButton; |
nothing calls this directly
no test coverage detected