()
| 11 | import { useMutation } from "react-query"; |
| 12 | |
| 13 | export function CloneButton() { |
| 14 | const hasProAccess = useHasProAccess(); |
| 15 | const language = useContext(AppContext).language; |
| 16 | const userId = useUserId(); |
| 17 | const makeChartMutation = useMutation( |
| 18 | "makeChart", |
| 19 | async () => { |
| 20 | if (!userId) throw new Error("No user id"); |
| 21 | const name = getFunFlowchartName(language as keyof typeof languages); |
| 22 | const fullText = docToString(useDoc.getState()); |
| 23 | const response = await makeChart({ |
| 24 | name, |
| 25 | user_id: userId, |
| 26 | chart: fullText, |
| 27 | }); |
| 28 | return response; |
| 29 | }, |
| 30 | { |
| 31 | retry: false, |
| 32 | onSuccess: (response: any) => { |
| 33 | queryClient.invalidateQueries(["auth", "hostedCharts"]); |
| 34 | window.open(`/u/${response.data[0].id}`, "_blank"); |
| 35 | }, |
| 36 | } |
| 37 | ); |
| 38 | if (!hasProAccess) return null; |
| 39 | return ( |
| 40 | <Button2 |
| 41 | color="blue" |
| 42 | isLoading={makeChartMutation.isLoading} |
| 43 | onClick={() => { |
| 44 | makeChartMutation.mutate(); |
| 45 | }} |
| 46 | data-session-activity="Clone Chart" |
| 47 | > |
| 48 | <Trans>Clone</Trans> |
| 49 | </Button2> |
| 50 | ); |
| 51 | } |
nothing calls this directly
no test coverage detected