({
report,
disableRedirect,
}: SaveReportProps)
| 33 | type IForm = z.infer<typeof validator>; |
| 34 | |
| 35 | export default function SaveReport({ |
| 36 | report, |
| 37 | disableRedirect, |
| 38 | }: SaveReportProps) { |
| 39 | const router = useRouter(); |
| 40 | const queryClient = useQueryClient(); |
| 41 | const { organizationId, projectId } = useAppParams(); |
| 42 | const searchParams = useSearch({ |
| 43 | from: '/_app/$organizationId/$projectId/reports', |
| 44 | shouldThrow: false, |
| 45 | }); |
| 46 | const dashboardId = searchParams?.dashboardId; |
| 47 | |
| 48 | const trpc = useTRPC(); |
| 49 | const save = useMutation( |
| 50 | trpc.report.create.mutationOptions({ |
| 51 | onError: handleError, |
| 52 | onSuccess(res) { |
| 53 | queryClient.invalidateQueries( |
| 54 | trpc.report.list.queryFilter({ |
| 55 | dashboardId: res.dashboardId, |
| 56 | projectId, |
| 57 | }), |
| 58 | ); |
| 59 | queryClient.invalidateQueries(trpc.dashboard.list.pathFilter()); |
| 60 | |
| 61 | const goToReport = () => { |
| 62 | router.navigate({ |
| 63 | to: '/$organizationId/$projectId/reports/$reportId', |
| 64 | params: { |
| 65 | organizationId, |
| 66 | projectId, |
| 67 | reportId: res.id, |
| 68 | }, |
| 69 | search: searchParams, |
| 70 | }); |
| 71 | }; |
| 72 | |
| 73 | toast('Report created', { |
| 74 | description: `${res.name}`, |
| 75 | action: { |
| 76 | label: 'View report', |
| 77 | onClick: () => goToReport(), |
| 78 | }, |
| 79 | }); |
| 80 | |
| 81 | if (!disableRedirect) { |
| 82 | goToReport(); |
| 83 | } |
| 84 | |
| 85 | popModal(); |
| 86 | }, |
| 87 | }), |
| 88 | ); |
| 89 | |
| 90 | const { register, handleSubmit, formState, control, setValue } = |
| 91 | useForm<IForm>({ |
| 92 | resolver: zodResolver(validator), |
nothing calls this directly
no test coverage detected