|
| 1 | +import { |
| 2 | + GitPullRequestIcon, |
| 3 | + type Icon, |
| 4 | + LifebuoyIcon, |
| 5 | + ListChecksIcon, |
| 6 | + SunIcon, |
| 7 | + TestTubeIcon, |
| 8 | + XIcon, |
| 9 | +} from "@phosphor-icons/react"; |
| 10 | +import { |
| 11 | + Button, |
| 12 | + Dialog, |
| 13 | + DialogContent, |
| 14 | + DialogDescription, |
| 15 | + DialogTitle, |
| 16 | +} from "@posthog/quill"; |
| 17 | +import { LOOPS_FLAG } from "@posthog/shared"; |
| 18 | +import { ANALYTICS_EVENTS } from "@posthog/shared/analytics-events"; |
| 19 | +import { loopHog } from "@posthog/ui/assets/hedgehogs"; |
| 20 | +import { useFeatureFlag } from "@posthog/ui/features/feature-flags/useFeatureFlag"; |
| 21 | +import { useLoopsPromoStore } from "@posthog/ui/features/loops/loopsPromoStore"; |
| 22 | +import { Button as UiButton } from "@posthog/ui/primitives/Button"; |
| 23 | +import { navigateToLoops } from "@posthog/ui/router/navigationBridge"; |
| 24 | +import { useAppView } from "@posthog/ui/router/useAppView"; |
| 25 | +import { track } from "@posthog/ui/shell/analytics"; |
| 26 | +import { Box } from "@radix-ui/themes"; |
| 27 | +import { useEffect, useState } from "react"; |
| 28 | + |
| 29 | +const EXAMPLES: { icon: Icon; label: string }[] = [ |
| 30 | + { |
| 31 | + icon: GitPullRequestIcon, |
| 32 | + label: "Digest open pull requests and flag what needs attention", |
| 33 | + }, |
| 34 | + { |
| 35 | + icon: TestTubeIcon, |
| 36 | + label: "Track down flaky tests and summarize CI failures", |
| 37 | + }, |
| 38 | + { |
| 39 | + icon: ListChecksIcon, |
| 40 | + label: "Triage new issues and flag likely duplicates", |
| 41 | + }, |
| 42 | + { icon: SunIcon, label: "Post a standup summary every weekday morning" }, |
| 43 | + { |
| 44 | + icon: LifebuoyIcon, |
| 45 | + label: "Review support tickets and surface the urgent ones", |
| 46 | + }, |
| 47 | +]; |
| 48 | + |
| 49 | +export function LoopsPromoCard() { |
| 50 | + const loopsEnabled = useFeatureFlag(LOOPS_FLAG, import.meta.env.DEV); |
| 51 | + const dismissed = useLoopsPromoStore((state) => state.dismissed); |
| 52 | + const hasHydrated = useLoopsPromoStore((state) => state._hasHydrated); |
| 53 | + const dismiss = useLoopsPromoStore((state) => state.dismiss); |
| 54 | + const [dialogOpen, setDialogOpen] = useState(false); |
| 55 | + |
| 56 | + // Reaching the Loops page on their own means the promo did its job (or was |
| 57 | + // never needed), so it retires the card the same way answering the dialog does. |
| 58 | + const view = useAppView(); |
| 59 | + const onLoopsPage = view.type === "loops"; |
| 60 | + useEffect(() => { |
| 61 | + if (onLoopsPage && hasHydrated && !dismissed) dismiss(); |
| 62 | + }, [onLoopsPage, hasHydrated, dismissed, dismiss]); |
| 63 | + |
| 64 | + if (!loopsEnabled || !hasHydrated || (dismissed && !dialogOpen)) return null; |
| 65 | + |
| 66 | + const openDialog = () => { |
| 67 | + track(ANALYTICS_EVENTS.LOOPS_PROMO_OPENED); |
| 68 | + setDialogOpen(true); |
| 69 | + }; |
| 70 | + |
| 71 | + const handleDismiss = () => { |
| 72 | + track(ANALYTICS_EVENTS.LOOPS_PROMO_DISMISSED); |
| 73 | + dismiss(); |
| 74 | + }; |
| 75 | + |
| 76 | + // Answering the dialog either way retires the card: it exists to get the |
| 77 | + // user into this dialog once, not to nag after they've decided. |
| 78 | + const handleNotNow = () => { |
| 79 | + track(ANALYTICS_EVENTS.LOOPS_PROMO_DISMISSED); |
| 80 | + setDialogOpen(false); |
| 81 | + dismiss(); |
| 82 | + }; |
| 83 | + |
| 84 | + const handleLearnMore = () => { |
| 85 | + track(ANALYTICS_EVENTS.LOOPS_PROMO_LEARN_MORE_CLICKED); |
| 86 | + setDialogOpen(false); |
| 87 | + dismiss(); |
| 88 | + navigateToLoops(); |
| 89 | + }; |
| 90 | + |
| 91 | + return ( |
| 92 | + <> |
| 93 | + {!dismissed && ( |
| 94 | + <Box className="shrink-0 px-2 pb-2"> |
| 95 | + <div className="group relative overflow-hidden rounded-md border border-gray-6 bg-gray-2"> |
| 96 | + <button |
| 97 | + type="button" |
| 98 | + className="block w-full text-left transition-colors hover:bg-gray-3" |
| 99 | + onClick={openDialog} |
| 100 | + > |
| 101 | + <div className="flex h-24 items-center justify-center border-gray-6 border-b bg-gray-4"> |
| 102 | + <img |
| 103 | + src={loopHog} |
| 104 | + alt="" |
| 105 | + className="h-[72px] w-auto object-contain" |
| 106 | + /> |
| 107 | + </div> |
| 108 | + <div className="flex flex-col gap-0.5 px-3 pt-3 pb-3"> |
| 109 | + <span className="font-medium text-[13px] text-gray-12"> |
| 110 | + Introducing Loops |
| 111 | + </span> |
| 112 | + <span className="text-[11px] text-gray-11 leading-snug"> |
| 113 | + Recurring agent jobs that run in the cloud and report back. |
| 114 | + </span> |
| 115 | + {/* Rendered as a span: the whole card is already a button, and |
| 116 | + nesting real buttons is invalid HTML. */} |
| 117 | + <UiButton |
| 118 | + asChild |
| 119 | + variant="outline" |
| 120 | + color="gray" |
| 121 | + size="1" |
| 122 | + className="mt-2 self-start" |
| 123 | + > |
| 124 | + <span>Learn more</span> |
| 125 | + </UiButton> |
| 126 | + </div> |
| 127 | + </button> |
| 128 | + <button |
| 129 | + type="button" |
| 130 | + aria-label="Dismiss Loops announcement" |
| 131 | + title="Dismiss" |
| 132 | + className="absolute top-1.5 right-1.5 rounded-full bg-(--gray-a3) p-1 text-gray-11 opacity-0 transition-all hover:bg-(--gray-a5) hover:text-gray-12 focus-visible:opacity-100 group-hover:opacity-100" |
| 133 | + onClick={handleDismiss} |
| 134 | + > |
| 135 | + <XIcon size={10} weight="bold" /> |
| 136 | + </button> |
| 137 | + </div> |
| 138 | + </Box> |
| 139 | + )} |
| 140 | + |
| 141 | + <Dialog open={dialogOpen} onOpenChange={setDialogOpen}> |
| 142 | + <DialogContent className="sm:max-w-md"> |
| 143 | + <div className="flex h-48 items-center justify-center border-gray-6 border-b bg-gray-4"> |
| 144 | + <img src={loopHog} alt="" className="h-36 w-auto object-contain" /> |
| 145 | + </div> |
| 146 | + <div className="flex flex-col gap-4 px-5 pt-4 pb-5"> |
| 147 | + <div className="flex flex-col gap-1.5"> |
| 148 | + <DialogTitle className="font-semibold text-[17px] text-gray-12 tracking-tight"> |
| 149 | + Introducing Loops |
| 150 | + </DialogTitle> |
| 151 | + <DialogDescription className="text-[13px] text-gray-11 leading-relaxed"> |
| 152 | + Describe a job once and it keeps running in the cloud, on a |
| 153 | + schedule or when something happens in your repos, even with your |
| 154 | + laptop closed. Every run reports back. |
| 155 | + </DialogDescription> |
| 156 | + </div> |
| 157 | + <div className="flex flex-col gap-2.5"> |
| 158 | + <span className="font-medium text-[11px] text-gray-10 uppercase tracking-wide"> |
| 159 | + Things to try |
| 160 | + </span> |
| 161 | + <ul className="flex flex-col gap-2"> |
| 162 | + {EXAMPLES.map(({ icon: ExampleIcon, label }) => ( |
| 163 | + <li key={label} className="flex items-center gap-2.5"> |
| 164 | + <span className="flex size-6 shrink-0 items-center justify-center rounded-(--radius-2) bg-(--gray-a3) text-gray-11"> |
| 165 | + <ExampleIcon size={13} /> |
| 166 | + </span> |
| 167 | + <span className="text-[13px] text-gray-11">{label}</span> |
| 168 | + </li> |
| 169 | + ))} |
| 170 | + </ul> |
| 171 | + </div> |
| 172 | + <div className="flex justify-end gap-2 pt-1"> |
| 173 | + <Button variant="outline" size="sm" onClick={handleNotNow}> |
| 174 | + Not now |
| 175 | + </Button> |
| 176 | + <Button variant="primary" size="sm" onClick={handleLearnMore}> |
| 177 | + Try now |
| 178 | + </Button> |
| 179 | + </div> |
| 180 | + </div> |
| 181 | + </DialogContent> |
| 182 | + </Dialog> |
| 183 | + </> |
| 184 | + ); |
| 185 | +} |
0 commit comments