Skip to content

Open-source status page, incident response and uptime monitoring

feat: plain support bubble (#858)

Maximilian Kaske422757c7b007
diff --git a/apps/web/.env.example b/apps/web/.env.example
index 32fb8d4dd..d2c8cd5c1 100644
--- a/apps/web/.env.example
+++ b/apps/web/.env.example
@@ -71,3 +71,5 @@ AUTH_GITHUB_ID=
AUTH_GITHUB_SECRET=
AUTH_GOOGLE_ID=
AUTH_GOOGLE_SECRET=
+
+PLAIN_API_KEY=
\ No newline at end of file
diff --git a/apps/web/package.json b/apps/web/package.json
index fbdc2a4b0..b019cc3ab 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -41,6 +41,7 @@
"@tailwindcss/container-queries": "0.1.1",
"@tailwindcss/typography": "0.5.10",
"@tanstack/react-table": "8.10.3",
+ "@team-plain/typescript-sdk": "4.2.3",
"@tremor/react": "3.13.3",
"@trpc/client": "10.45.1",
"@trpc/next": "10.45.1",
diff --git a/apps/web/src/app/app/layout.tsx b/apps/web/src/app/app/layout.tsx
index 341f2f9e6..0366202f2 100644
--- a/apps/web/src/app/app/layout.tsx
+++ b/apps/web/src/app/app/layout.tsx
@@ -2,6 +2,8 @@ import { SessionProvider } from "next-auth/react";
import { PHProvider, PostHogPageview } from "@/providers/posthog";
+import { Bubble } from "@/components/support/bubble";
+
export default function AuthLayout({
children, // will be a page or nested layout
}: {
@@ -11,6 +13,7 @@ export default function AuthLayout({
<PHProvider>
<PostHogPageview />
<SessionProvider>{children}</SessionProvider>
+ <Bubble />
</PHProvider>
);
}
diff --git a/apps/web/src/components/support/action.ts b/apps/web/src/components/support/action.ts
new file mode 100644
index 000000000..effa263b8
--- /dev/null
+++ b/apps/web/src/components/support/action.ts
@@ -0,0 +1,71 @@
+"use server";
+
+import { PlainClient } from "@team-plain/typescript-sdk";
+
+import { env } from "@/env";
+
+import type { FormValues } from "./contact-form";
+
+const labelTypeIds = {
+ bug: "lt_01HZDA8FCA0CMPCJ2YSTVE78XN",
+ demo: "lt_01HZDA8N33R1A9AN97RGXPZ93F",
+ feature: "lt_01HZDA8V56431V27GFDAVV58FX",
+ question: "lt_01HZDA8XWTY0SWY4MKNY6F4EVK",
+ security: "lt_01HZDA91M7KVR4529FHVHE18MG",
+};
+
+function getPriority(type: FormValues["type"], isBlocking: boolean) {
+ if (type === "security") return 0;
+ if (type === "bug" && isBlocking) return 1;
+ return 2;
+}
+
+function isString(s: unknown): s is string {
+ return typeof s === "string";
+}
+
+const client = new PlainClient({
+ apiKey: env.PLAIN_API_KEY || "",
+});
+
+export async function handlePlainSupport(values: FormValues) {
+ const upsertCustomerRes = await client.upsertCustomer({
+ identifier: {
+ emailAddress: values.email,
+ },
+ onCreate: {
+ fullName: values.name,
+ email: {
+ email: values.email,
+ isVerified: true,
+ },
+ },
+ onUpdate: {},
+ });
+
+ if (upsertCustomerRes.error) {
+ console.error(upsertCustomerRes.error);
+ return { error: upsertCustomerRes.error.message };
+ }
+
+ console.log(`Customer upserted ${upsertCustomerRes.data.customer.id}`);
+
+ const createThreadRes = await client.createThread({
+ customerIdentifier: {
+ customerId: upsertCustomerRes.data.customer.id,
+ },
+ title: "Support request!",
+ components: [{ componentText: { text: values.message } }],
+ labelTypeIds: [labelTypeIds[values.type]].filter(isString),
+ priority: getPriority(values.type, values.blocker),
+ });
+
+ if (createThreadRes.error) {
+ console.error(createThreadRes.error);
+ return { error: createThreadRes.error.message };
+ }
+
+ console.log(`Thread created ${createThreadRes.data.id}`);
+
+ return { error: null };
+}
diff --git a/apps/web/src/components/support/bubble.tsx b/apps/web/src/components/support/bubble.tsx
new file mode 100644
index 000000000..dba30d57d
--- /dev/null
+++ b/apps/web/src/components/support/bubble.tsx
@@ -0,0 +1,85 @@
+"use client";
+
+import { useState } from "react";
+import { MessageCircle } from "lucide-react";
+
+import {
+ Button,
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+} from "@openstatus/ui";
+
+import { ContactForm } from "./contact-form";
+
+export function Bubble() {
+ const [open, setOpen] = useState(false);
+ const [formVisible, setFormVisible] = useState(false);
+
+ return (
+ <div className="fixed right-4 bottom-4 z-50 rounded-full bg-background">
+ <Popover
+ open={open}
+ onOpenChange={(value) => {
+ // TODO: improve as if you do it quickly, it will still be visible and jump
+ if (formVisible && !value) {
+ setTimeout(() => setFormVisible(false), 300); // reset form after popover closes
+ }
+ setOpen(value);
+ }}
+ >
+ <PopoverTrigger className="rounded-full border p-2 shadow">
+ <MessageCircle className="h-6 w-6" />
+ </PopoverTrigger>
+ <PopoverContent
+ side="top"
+ sideOffset={8}
+ align="end"
+ alignOffset={0}
+ className={formVisible ? "w-80" : undefined}
+ >
+ {!formVisible ? (
+ <div className="space-y-2">
+ <p className="font-medium text-foreground">Need help?</p>
+ <p className="text-muted-foreground text-sm">
+ We are here to help you with any questions you may have.
+ </p>
+ <Button variant="ghost" className="w-full" asChild>
+ <a
+ target="_blank"
+ rel="noreferrer"
+ href="https://cal.com/team/openstatus/30min"
+ >
+ Book a call
+ </a>
+ </Button>
+ <Button variant="ghost" className="w-full" asChild>
+ <a
+ target="_blank"
+ rel="noreferrer"
+ href="https://docs.openstatus.dev"
+ >
+ Browse documentation
+ </a>
+ </Button>
+ <Button variant="ghost" className="w-full" asChild>
+ <a target="_blank" rel="noreferrer" href="/discord">
+ Join Discord
+ </a>
+ </Button>
+ <Button
+ variant="ghost"
+ className="w-full"
+ onClick={() => setFormVisible((prev) => !prev)}
+ >
+ Get in touch
+ </Button>
+ </div>
+ ) : (
+ <ContactForm onSubmit={() => setOpen(false)} />
+ )}
+ </PopoverContent>
+ </Popover>
+ </div>
+ );
+}
diff --git a/apps/web/src/components/support/contact-form.tsx b/apps/web/src/components/support/contact-form.tsx
new file mode 100644
index 000000000..82be9a7a5
--- /dev/null
+++ b/apps/web/src/components/support/contact-form.tsx
@@ -0,0 +1,188 @@
+"use client";
+
+import { useTransition } from "react";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { useForm } from "react-hook-form";
+import { z } from "zod";
+
+import {
+ Button,
+ Checkbox,
+ Form,
+ FormControl,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+ Input,
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+ Textarea,
+} from "@openstatus/ui";
+
+import { LoadingAnimation } from "../loading-animation";
+import { handlePlainSupport } from "./action";
+import { toast } from "@/lib/toast";
+
+export const types = [
+ {
+ label: "Report a bug",
+ value: "bug" as const,
+ },
+ {
+ label: "Book a demo",
+ value: "demo" as const,
+ },
+ {
+ label: "Suggest a feature",
+ value: "feature" as const,
+ },
+ {
+ label: "Report a security issue",
+ value: "security" as const,
+ },
+ {
+ label: "Something else",
+ value: "question" as const,
+ },
+];
+
+export const FormSchema = z.object({
+ name: z.string().min(1),
+ type: z.enum(["bug", "demo", "feature", "security", "question"]),
+ email: z.string().email(),
+ message: z.string().min(1),
+ blocker: z.boolean().optional().default(false),
+});
+
+export type FormValues = z.infer<typeof FormSchema>;
+
+interface ContactFormProps {
+ defaultValues?: FormValues;
+ onSubmit?: () => void;
+}
+
+export function ContactForm({
+ defaultValues,
+ onSubmit: handleSubmit,
+}: ContactFormProps) {
+ const form = useForm<FormValues>({
+ resolver: zodResolver(FormSchema),
+ defaultValues,
+ });
+ const [isPending, startTransition] = useTransition();
+
+ async function onSubmit(data: FormValues) {
+ startTransition(async () => {
+ const result = await handlePlainSupport(data);
+ if (result.error) {
+ console.error(result.error);
+ toast.error("Something went wrong. Please try again.");
+ } else {
+ handleSubmit?.();
+ toast.success(
+ "Your message has been sent! We will get back to you soon."
+ );
+ }
+ });
+ }
+
+ const watchType = form.watch("type");
+
+ return (
+ <Form {...form}>
+ <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-3">
+ <FormField
+ control={form.control}
+ name="name"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Name</FormLabel>
+ <FormControl>
+ <Input placeholder="Max" {...field} />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="email"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Email</FormLabel>
+ <FormControl>
+ <Input placeholder="[email protected]" {...field} />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="type"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Type</FormLabel>
+ <Select onValueChange={field.onChange} defaultValue={field.value}>
+ <FormControl>
+ <SelectTrigger>
+ <SelectValue placeholder="What you need help with" />
+ </SelectTrigger>
+ </FormControl>
+ <SelectContent>
+ {types.map((type) => (
+ <SelectItem key={type.value} value={type.value}>
+ {type.label}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ {watchType ? (
+ <FormField
+ control={form.control}
+ name="message"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Message</FormLabel>
+ <FormControl>
+ <Textarea placeholder="Tell us about it..." {...field} />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ ) : null}
+ {watchType === "bug" ? (
+ <FormField
+ control={form.control}
+ name="blocker"
+ render={({ field }) => (
+ <FormItem className="flex flex-row items-start space-x-2 space-y-0">
+ <FormControl>
+ <Checkbox
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ />
+ </FormControl>
+ <FormLabel className="font-normal leading-none">
+ This bug prevents me from using the product.
+ </FormLabel>
+ </FormItem>
+ )}
+ />
+ ) : null}
+ <Button type="submit" className="w-full" disabled={isPending}>
+ {isPending ? <LoadingAnimation /> : "Submit"}
+ </Button>
+ </form>
+ </Form>
+ );
+}
diff --git a/apps/web/src/env.ts b/apps/web/src/env.ts
index bdf01fab6..728bccfe7 100644
--- a/apps/web/src/env.ts
+++ b/apps/web/src/env.ts
@@ -23,6 +23,7 @@ export const env = createEnv({
CLICKHOUSE_URL: z.string(),
CLICKHOUSE_USERNAME: z.string(),
CLICKHOUSE_PASSWORD: z.string(),
+ PLAIN_API_KEY: z.string().optional(),
},
client: {
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY: z.string(),
@@ -55,6 +56,7 @@ export const env = createEnv({
CLICKHOUSE_URL: process.env.CLICKHOUSE_URL,
CLICKHOUSE_USERNAME: process.env.CLICKHOUSE_USERNAME,
CLICKHOUSE_PASSWORD: process.env.CLICKHOUSE_PASSWORD,
+ PLAIN_API_KEY: process.env.PLAIN_API_KEY,
},
skipValidation: true,
});
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index ca603b164..4d505c490 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -317,6 +317,9 @@ importers:
'@tanstack/react-table':
specifier: 8.10.3
+ '@team-plain/typescript-sdk':
+ specifier: 4.2.3
+ version: 4.2.3
'@tremor/react':
specifier: 3.13.3
@@ -2185,6 +2188,11 @@ packages:
resolution: {integrity: sha512-vwj0jzkHNgY/WvqrNt763QfO3mRHIO1GSFW22scOneI5pcu5sMb/JPN+P+cDPTEXRNPdZCaZ/HicLHZNxbseyA==}
engines: {node: '>=v14'}
+ '@graphql-typed-document-node/[email protected]':
+ resolution: {integrity: sha512-mB9oAsNCm9aM3/SOv4YtBMqZbYj10R7dkq8byBqxGY/ncFwhf2oQzMV+LCRlWoDSEBJ3COiR1yeDvMtsoOsuFQ==}
+ peerDependencies:
+ graphql: ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0
+
resolution: {integrity: sha512-yMaA/cIsRhGzW3ymCNpdlPcInXcovztlgu/rirThj2b87u3RzWUszliOqZ/pldy7yhmJPS8uwog+kZSTa4A0PQ==}
engines: {node: ^8.13.0 || >=10.10.0}
@@ -3770,6 +3778,9 @@ packages:
'@tanstack/[email protected]':
resolution: {integrity: sha512-SYXOBTjJb05rXa2vl55TTwO40A6wKu0R5i1qQwhJYNDIqaIGF7D0HsLw+pJAyi2OvntlEIVusx3xtbbgSUi6zg==}
+ '@team-plain/[email protected]':
+ resolution: {integrity: sha512-aJjN7qXc07t4aJzf55CsiRd6o5OD7hLAEvsG0qMWOSCBq2O802SSucPmHTufAMo5r5/TVLpFVz+aR29nXwW4xg==}
+
'@tootallnate/[email protected]':
resolution: {integrity: sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A==}
engines: {node: '>= 10'}
@@ -4065,6 +4076,17 @@ packages:
resolution: {integrity: sha512-4I7Td01quW/RpocfNayFdFVk1qSuoh0E7JrbRJ16nH01HhKFQ88INq9Sd+nd72zqRySlr9BmDA8xlEJ6vJMrYA==}
engines: {node: '>=8'}
+ resolution: {integrity: sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==}
+ peerDependencies:
+ ajv: ^8.0.0
+ peerDependenciesMeta:
+ ajv:
+ optional: true
+
+ resolution: {integrity: sha512-oYs1UUtO97ZO2lJ4bwnWeQW8/zvOIQLGKcvPTsWmvc2SYgBb+upuNS5NxoLaMU4h8Ju3Nbj6Cq8mD2LQoqVKFA==}
+
resolution: {integrity: sha512-WvV2YWgsnXLxaY0QYux0crpBAg/0JA763NmbMVz22jKhMPo7dpTBet8G2IlF7ixTjLDzGlkHk1ZaKqqQmjJ+4w==}
peerDependencies:
@@ -5106,6 +5128,9 @@ packages:
resolution: {integrity: sha512-hMQ4CX1p1izmuLYyZqLMO/qGNw10wSv9QDCPfzXfyFrOaCSSoRfqE1Kf1s5an66J5JZC62NewG+mK49jOCtQew==}
engines: {node: '>=4'}
+ resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==}
+
resolution: {integrity: sha512-WF1Wi8PwwSY7/6Kx0vKXtw8RwuSGoM1bvDaJbu7MxDlR1vovZjIAKrnzyrThgAjm6JDTu0fVgWXDlMGspodfoQ==}
engines: {node: '>=6.0.0'}
@@ -5328,6 +5353,10 @@ packages:
resolution: {integrity: sha512-rEDCuqUQ4tbD78TpzsMtt5OIf0cBCSDWSJtUDaF6JsAh+k0v9r++NzxNEG87oDZx9ZwGhD8DaezR2L/yrw0Jdw==}
engines: {node: '>=10'}
+ resolution: {integrity: sha512-59LZHPdGZVh695Ud9lRzPBVTtlX9ZCV150Er2W43ro37wVof0ctenSaskPPjN7lVTIN8mSZt8PHUNKZuNQUuxw==}
+ engines: {node: ^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0}
+
resolution: {integrity: sha512-5v6yZd4JK3eMI3FqqCouswVqwugaA9r4dNZB1wwcmrD02QkV5H0y7XBQW8QwQqEaZY1pM9aqORSORhJRdNK44Q==}
engines: {node: '>=6.0'}
@@ -5828,6 +5857,9 @@ packages:
resolution: {integrity: sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==}
+ resolution: {integrity: sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==}
+
resolution: {integrity: sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w==}
@@ -7041,6 +7073,10 @@ packages:
resolution: {integrity: sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==}
engines: {node: '>=0.10.0'}
+ resolution: {integrity: sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==}
+ engines: {node: '>=0.10.0'}
+
resolution: {integrity: sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==}
@@ -7787,6 +7823,9 @@ packages:
resolution: {integrity: sha512-WRbjgmYzgXkCV7zNVpy5YgrHgbBv126rMALQQMrmzOVC4GM2waQ9x7xtm8VU+1yF2kWyPzI9zbZ48n4vSxwfSA==}
+ resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==}
+
resolution: {integrity: sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==}
@@ -9274,6 +9313,10 @@ snapshots:
- encoding
- supports-color
+ '@graphql-typed-document-node/[email protected]([email protected])':
+ dependencies:
+ graphql: 16.8.1
+
dependencies:
'@grpc/proto-loader': 0.7.10
@@ -11229,6 +11272,14 @@ snapshots:
'@tanstack/[email protected]': {}
+ '@team-plain/[email protected]':
+ dependencies:
+ '@graphql-typed-document-node/core': 3.2.0([email protected])
+ ajv: 8.14.0
+ ajv-formats: 2.1.1([email protected])
+ graphql: 16.8.1
+ zod: 3.22.4
+
'@tootallnate/[email protected]': {}
'@tootallnate/[email protected]': {}
@@ -11562,6 +11613,17 @@ snapshots:
clean-stack: 2.2.0
indent-string: 4.0.0
+ optionalDependencies:
+ ajv: 8.14.0
+
+ dependencies:
+ fast-deep-equal: 3.1.3
+ json-schema-traverse: 1.0.0
+ require-from-string: 2.0.2
+ uri-js: 4.4.1
+
dependencies:
'@analytics/type-utils': 0.6.2
@@ -12562,6 +12624,8 @@ snapshots:
iconv-lite: 0.4.24
tmp: 0.0.33
+
@@ -12850,6 +12914,8 @@ snapshots:
chalk: 4.1.2
tinygradient: 1.1.5
+
dependencies:
js-yaml: 3.14.1
@@ -13461,6 +13527,8 @@ snapshots:
+
@@ -15074,6 +15142,8 @@ snapshots:
+
@@ -15482,7 +15552,7 @@ snapshots:
detective: 5.2.1
didyoumean: 1.2.2
dlv: 1.1.3
- fast-glob: 3.3.1
+ fast-glob: 3.3.2
glob-parent: 6.0.2
is-glob: 4.0.3
lilconfig: 2.1.0
@@ -15884,6 +15954,10 @@ snapshots:
+ dependencies:
+ punycode: 2.3.0
+
dependencies:
querystringify: 2.2.0