({ reportId }: { reportId: string })
| 24 | type IForm = z.infer<typeof validator>; |
| 25 | |
| 26 | export default function ShareReportModal({ reportId }: { reportId: string }) { |
| 27 | const { projectId, organizationId } = useAppParams(); |
| 28 | const navigate = useNavigate(); |
| 29 | const [copied, setCopied] = useState(false); |
| 30 | |
| 31 | const trpc = useTRPC(); |
| 32 | const queryClient = useQueryClient(); |
| 33 | |
| 34 | // Fetch current share status |
| 35 | const shareQuery = useQuery( |
| 36 | trpc.share.report.queryOptions({ |
| 37 | reportId, |
| 38 | }), |
| 39 | ); |
| 40 | |
| 41 | const existingShare = shareQuery.data; |
| 42 | const isShared = existingShare?.public ?? false; |
| 43 | const shareUrl = existingShare?.id |
| 44 | ? `${window.location.origin}/share/report/${existingShare.id}` |
| 45 | : ''; |
| 46 | |
| 47 | const { register, handleSubmit, watch } = useForm<IForm>({ |
| 48 | resolver: zodResolver(validator), |
| 49 | defaultValues: { |
| 50 | public: true, |
| 51 | password: existingShare?.password ? '••••••••' : '', |
| 52 | projectId, |
| 53 | organizationId, |
| 54 | reportId, |
| 55 | }, |
| 56 | }); |
| 57 | |
| 58 | const password = watch('password'); |
| 59 | |
| 60 | const mutation = useMutation( |
| 61 | trpc.share.createReport.mutationOptions({ |
| 62 | onError: handleError, |
| 63 | onSuccess(res) { |
| 64 | queryClient.invalidateQueries(trpc.share.report.pathFilter()); |
| 65 | toast('Success', { |
| 66 | description: `Your report is now ${res.public ? 'public' : 'private'}`, |
| 67 | action: res.public |
| 68 | ? { |
| 69 | label: 'View', |
| 70 | onClick: () => |
| 71 | navigate({ |
| 72 | to: '/share/report/$shareId', |
| 73 | params: { |
| 74 | shareId: res.id, |
| 75 | }, |
| 76 | }), |
| 77 | } |
| 78 | : undefined, |
| 79 | }); |
| 80 | popModal(); |
| 81 | }, |
| 82 | }), |
| 83 | ); |
nothing calls this directly
no test coverage detected