fix: improve onboarding
This commit is contained in:
@@ -13,7 +13,7 @@ import { Button } from '../ui/button';
|
||||
const validator = zSignInEmail;
|
||||
type IForm = z.infer<typeof validator>;
|
||||
|
||||
export function SignInEmailForm() {
|
||||
export function SignInEmailForm({ isLastUsed }: { isLastUsed?: boolean }) {
|
||||
const trpc = useTRPC();
|
||||
const mutation = useMutation(
|
||||
trpc.auth.signInEmail.mutationOptions({
|
||||
@@ -54,9 +54,16 @@ export function SignInEmailForm() {
|
||||
type="password"
|
||||
className="bg-def-100/50 border-def-300 focus:border-highlight focus:ring-highlight/20"
|
||||
/>
|
||||
<Button type="submit" size="lg">
|
||||
Sign in
|
||||
</Button>
|
||||
<div className="relative">
|
||||
<Button type="submit" size="lg" className="w-full">
|
||||
Sign in
|
||||
</Button>
|
||||
{isLastUsed && (
|
||||
<span className="absolute -top-2 right-3 text-[10px] font-medium bg-highlight text-white px-1.5 py-0.5 rounded-full leading-none">
|
||||
Used last time
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() =>
|
||||
|
||||
@@ -5,7 +5,8 @@ import { Button } from '../ui/button';
|
||||
export function SignInGithub({
|
||||
type,
|
||||
inviteId,
|
||||
}: { type: 'sign-in' | 'sign-up'; inviteId?: string }) {
|
||||
isLastUsed,
|
||||
}: { type: 'sign-in' | 'sign-up'; inviteId?: string; isLastUsed?: boolean }) {
|
||||
const trpc = useTRPC();
|
||||
const mutation = useMutation(
|
||||
trpc.auth.signInOAuth.mutationOptions({
|
||||
@@ -21,27 +22,34 @@ export function SignInGithub({
|
||||
if (type === 'sign-up') return 'Sign up with Github';
|
||||
};
|
||||
return (
|
||||
<Button
|
||||
className="w-full bg-primary hover:bg-primary/90 text-primary-foreground shadow-sm hover:shadow-md transition-all duration-200 [&_svg]:shrink-0"
|
||||
size="lg"
|
||||
onClick={() =>
|
||||
mutation.mutate({
|
||||
provider: 'github',
|
||||
inviteId: type === 'sign-up' ? inviteId : undefined,
|
||||
})
|
||||
}
|
||||
>
|
||||
<svg
|
||||
className="size-4 mr-2"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="currentColor"
|
||||
<div className="relative">
|
||||
<Button
|
||||
className="w-full bg-primary hover:bg-primary/90 text-primary-foreground shadow-sm hover:shadow-md transition-all duration-200 [&_svg]:shrink-0"
|
||||
size="lg"
|
||||
onClick={() =>
|
||||
mutation.mutate({
|
||||
provider: 'github',
|
||||
inviteId: type === 'sign-up' ? inviteId : undefined,
|
||||
})
|
||||
}
|
||||
>
|
||||
<path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z" />
|
||||
</svg>
|
||||
{title()}
|
||||
</Button>
|
||||
<svg
|
||||
className="size-4 mr-2"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="currentColor"
|
||||
>
|
||||
<path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z" />
|
||||
</svg>
|
||||
{title()}
|
||||
</Button>
|
||||
{isLastUsed && (
|
||||
<span className="absolute -top-2 right-3 text-[10px] font-medium bg-highlight text-white px-1.5 py-0.5 rounded-full leading-none">
|
||||
Used last time
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
import { useTRPC } from '@/integrations/trpc/react';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { Button } from '../ui/button';
|
||||
import { useTRPC } from '@/integrations/trpc/react';
|
||||
|
||||
export function SignInGoogle({
|
||||
type,
|
||||
inviteId,
|
||||
}: { type: 'sign-in' | 'sign-up'; inviteId?: string }) {
|
||||
isLastUsed,
|
||||
}: {
|
||||
type: 'sign-in' | 'sign-up';
|
||||
inviteId?: string;
|
||||
isLastUsed?: boolean;
|
||||
}) {
|
||||
const trpc = useTRPC();
|
||||
const mutation = useMutation(
|
||||
trpc.auth.signInOAuth.mutationOptions({
|
||||
@@ -14,46 +19,57 @@ export function SignInGoogle({
|
||||
window.location.href = res.url;
|
||||
}
|
||||
},
|
||||
}),
|
||||
})
|
||||
);
|
||||
const title = () => {
|
||||
if (type === 'sign-in') return 'Sign in with Google';
|
||||
if (type === 'sign-up') return 'Sign up with Google';
|
||||
if (type === 'sign-in') {
|
||||
return 'Sign in with Google';
|
||||
}
|
||||
if (type === 'sign-up') {
|
||||
return 'Sign up with Google';
|
||||
}
|
||||
};
|
||||
return (
|
||||
<Button
|
||||
className="w-full bg-background hover:bg-def-100 border border-def-300 text-foreground shadow-sm hover:shadow-md transition-all duration-200 [&_svg]:shrink-0"
|
||||
size="lg"
|
||||
onClick={() =>
|
||||
mutation.mutate({
|
||||
provider: 'google',
|
||||
inviteId: type === 'sign-up' ? inviteId : undefined,
|
||||
})
|
||||
}
|
||||
>
|
||||
<svg
|
||||
className="size-4 mr-2"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 24 24"
|
||||
<div className="relative">
|
||||
<Button
|
||||
className="w-full border border-def-300 bg-background text-foreground shadow-sm transition-all duration-200 hover:bg-def-100 hover:shadow-md [&_svg]:shrink-0"
|
||||
onClick={() =>
|
||||
mutation.mutate({
|
||||
provider: 'google',
|
||||
inviteId: type === 'sign-up' ? inviteId : undefined,
|
||||
})
|
||||
}
|
||||
size="lg"
|
||||
>
|
||||
<path
|
||||
fill="#4285F4"
|
||||
d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"
|
||||
/>
|
||||
<path
|
||||
fill="#34A853"
|
||||
d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"
|
||||
/>
|
||||
<path
|
||||
fill="#FBBC05"
|
||||
d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"
|
||||
/>
|
||||
<path
|
||||
fill="#EA4335"
|
||||
d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"
|
||||
/>
|
||||
</svg>
|
||||
{title()}
|
||||
</Button>
|
||||
<svg
|
||||
className="mr-2 size-4"
|
||||
viewBox="0 0 24 24"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"
|
||||
fill="#4285F4"
|
||||
/>
|
||||
<path
|
||||
d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"
|
||||
fill="#34A853"
|
||||
/>
|
||||
<path
|
||||
d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"
|
||||
fill="#FBBC05"
|
||||
/>
|
||||
<path
|
||||
d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"
|
||||
fill="#EA4335"
|
||||
/>
|
||||
</svg>
|
||||
{title()}
|
||||
</Button>
|
||||
{isLastUsed && (
|
||||
<span className="absolute -top-2 right-3 rounded-full bg-highlight px-1.5 py-0.5 font-medium text-[10px] text-white leading-none">
|
||||
Used last time
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
// Based on Christin Alares tag input component (https://github.com/christianalares/seventy-seven)
|
||||
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { cn } from '@/utils/cn';
|
||||
import { useAnimate } from 'framer-motion';
|
||||
import { XIcon } from 'lucide-react';
|
||||
import type { ElementRef } from 'react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { cn } from '@/utils/cn';
|
||||
|
||||
type Props = {
|
||||
interface Props {
|
||||
placeholder: string;
|
||||
value: string[];
|
||||
error?: string;
|
||||
@@ -15,7 +15,7 @@ type Props = {
|
||||
onChange: (value: string[]) => void;
|
||||
renderTag?: (tag: string) => string;
|
||||
id?: string;
|
||||
};
|
||||
}
|
||||
|
||||
const TagInput = ({
|
||||
value: propValue,
|
||||
@@ -49,7 +49,7 @@ const TagInput = ({
|
||||
e.preventDefault();
|
||||
|
||||
const tagAlreadyExists = value.some(
|
||||
(tag) => tag.toLowerCase() === inputValue.toLowerCase(),
|
||||
(tag) => tag.toLowerCase() === inputValue.toLowerCase()
|
||||
);
|
||||
|
||||
if (inputValue) {
|
||||
@@ -61,7 +61,7 @@ const TagInput = ({
|
||||
},
|
||||
{
|
||||
duration: 0.3,
|
||||
},
|
||||
}
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -100,50 +100,50 @@ const TagInput = ({
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={scope}
|
||||
className={cn(
|
||||
'inline-flex w-full flex-wrap items-center gap-2 rounded-md border border-input p-1 px-3 ring-offset-background has-[input:focus]:ring-2 has-[input:focus]:ring-ring has-[input:focus]:ring-offset-1 bg-card',
|
||||
!!error && 'border-destructive',
|
||||
'inline-flex w-full flex-wrap items-center gap-2 rounded-md border border-input bg-card p-1 px-3 ring-offset-background has-[input:focus]:ring-2 has-[input:focus]:ring-ring has-[input:focus]:ring-offset-1',
|
||||
!!error && 'border-destructive'
|
||||
)}
|
||||
ref={scope}
|
||||
>
|
||||
{value.map((tag, i) => {
|
||||
const isCreating = false;
|
||||
|
||||
return (
|
||||
<span
|
||||
data-tag={tag}
|
||||
key={tag}
|
||||
className={cn(
|
||||
'inline-flex items-center gap-2 rounded bg-def-200 px-2 py-1 ',
|
||||
'inline-flex items-center gap-2 rounded bg-def-200 px-2 py-1',
|
||||
isMarkedForDeletion &&
|
||||
i === value.length - 1 &&
|
||||
'bg-destructive-foreground ring-2 ring-destructive/50 ring-offset-1',
|
||||
isCreating && 'opacity-60',
|
||||
'bg-destructive/15 ring-2 ring-destructive ring-offset-2 ring-offset-card',
|
||||
isCreating && 'opacity-60'
|
||||
)}
|
||||
data-tag={tag}
|
||||
key={tag}
|
||||
>
|
||||
{renderTag ? renderTag(tag) : tag}
|
||||
<Button
|
||||
size="icon"
|
||||
variant="outline"
|
||||
className="h-4 w-4 rounded-full"
|
||||
onClick={() => removeTag(tag)}
|
||||
size="icon"
|
||||
variant="outline"
|
||||
>
|
||||
<span className="sr-only">Remove tag</span>
|
||||
<XIcon name="close" className="size-3" />
|
||||
<XIcon className="size-3" name="close" />
|
||||
</Button>
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
|
||||
<input
|
||||
ref={inputRef}
|
||||
placeholder={`${placeholder} ↵`}
|
||||
className="min-w-20 flex-1 py-1 focus-visible:outline-none bg-card"
|
||||
value={inputValue}
|
||||
className="min-w-20 flex-1 bg-card py-1 focus-visible:outline-none"
|
||||
id={id}
|
||||
onBlur={handleBlur}
|
||||
onChange={(e) => setInputValue(e.target.value)}
|
||||
onKeyDown={handleKeyDown}
|
||||
onBlur={handleBlur}
|
||||
id={id}
|
||||
placeholder={`${placeholder} ↵`}
|
||||
ref={inputRef}
|
||||
value={inputValue}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
import { pushModal } from '@/modals';
|
||||
import { SmartphoneIcon } from 'lucide-react';
|
||||
|
||||
import type { IServiceClient } from '@openpanel/db';
|
||||
import { frameworks } from '@openpanel/sdk-info';
|
||||
|
||||
type Props = {
|
||||
client: IServiceClient | null;
|
||||
};
|
||||
|
||||
const ConnectApp = ({ client }: Props) => {
|
||||
return (
|
||||
<div>
|
||||
<div className="flex items-center gap-2 text-xl font-bold capitalize mb-1">
|
||||
<SmartphoneIcon className="size-4" />
|
||||
App
|
||||
</div>
|
||||
<div className="text-muted-foreground mb-2">
|
||||
Pick a framework below to get started.
|
||||
</div>
|
||||
|
||||
<div className="mt-4 grid gap-4 md:grid-cols-2">
|
||||
{frameworks
|
||||
.filter((framework) => framework.type.includes('app'))
|
||||
.map((framework) => (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() =>
|
||||
pushModal('Instructions', {
|
||||
framework,
|
||||
client,
|
||||
})
|
||||
}
|
||||
className="flex items-center gap-4 rounded-md border p-2 py-2 text-left"
|
||||
key={framework.name}
|
||||
>
|
||||
<div className="h-10 w-10 rounded-md bg-def-200 p-2">
|
||||
<framework.IconComponent className="h-full w-full" />
|
||||
</div>
|
||||
<div className="flex-1 font-semibold">{framework.name}</div>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<p className="mt-2 text-sm text-muted-foreground">
|
||||
Missing a framework?{' '}
|
||||
<a
|
||||
href="mailto:hello@openpanel.dev"
|
||||
className="text-foreground underline"
|
||||
>
|
||||
Let us know!
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ConnectApp;
|
||||
@@ -1,86 +0,0 @@
|
||||
import { pushModal } from '@/modals';
|
||||
import { ServerIcon } from 'lucide-react';
|
||||
|
||||
import Syntax from '@/components/syntax';
|
||||
import { useAppContext } from '@/hooks/use-app-context';
|
||||
import type { IServiceClient } from '@openpanel/db';
|
||||
import { frameworks } from '@openpanel/sdk-info';
|
||||
|
||||
type Props = {
|
||||
client: IServiceClient | null;
|
||||
};
|
||||
|
||||
const ConnectBackend = ({ client }: Props) => {
|
||||
const context = useAppContext();
|
||||
return (
|
||||
<>
|
||||
<div>
|
||||
<div>
|
||||
<div className="flex items-center gap-2 text-xl font-bold capitalize mb-1">
|
||||
<ServerIcon className="size-4" />
|
||||
Backend
|
||||
</div>
|
||||
<div className="text-muted-foreground mb-2">
|
||||
Try with a basic curl command
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Syntax
|
||||
language="bash"
|
||||
className="border"
|
||||
code={`curl -X POST ${context.apiUrl}/track \\
|
||||
-H "Content-Type: application/json" \\
|
||||
-H "openpanel-client-id: ${client?.id}" \\
|
||||
-H "openpanel-client-secret: ${client?.secret}" \\
|
||||
-d '{
|
||||
"type": "track",
|
||||
"payload": {
|
||||
"name": "test_event",
|
||||
"properties": {
|
||||
"test": "property"
|
||||
}
|
||||
}
|
||||
}'`}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-muted-foreground mb-2">
|
||||
Pick a framework below to get started.
|
||||
</p>
|
||||
<div className="grid gap-4 md:grid-cols-2">
|
||||
{frameworks
|
||||
.filter((framework) => framework.type.includes('backend'))
|
||||
.map((framework) => (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() =>
|
||||
pushModal('Instructions', {
|
||||
framework,
|
||||
client,
|
||||
})
|
||||
}
|
||||
className="flex items-center gap-4 rounded-md border p-2 py-2 text-left"
|
||||
key={framework.name}
|
||||
>
|
||||
<div className="h-10 w-10 rounded-md bg-def-200 p-2">
|
||||
<framework.IconComponent className="h-full w-full" />
|
||||
</div>
|
||||
<div className="flex-1 font-semibold">{framework.name}</div>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<p className="mt-2 text-sm text-muted-foreground">
|
||||
Missing a framework?{' '}
|
||||
<a
|
||||
href="mailto:hello@openpanel.dev"
|
||||
className="text-foreground underline"
|
||||
>
|
||||
Let us know!
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default ConnectBackend;
|
||||
@@ -1,71 +1,80 @@
|
||||
import { pushModal } from '@/modals';
|
||||
import { MonitorIcon } from 'lucide-react';
|
||||
|
||||
import Syntax from '@/components/syntax';
|
||||
import type { IServiceClient } from '@openpanel/db';
|
||||
import { frameworks } from '@openpanel/sdk-info';
|
||||
import { CopyIcon, PlugIcon } from 'lucide-react';
|
||||
import { Button } from '../ui/button';
|
||||
import Syntax from '@/components/syntax';
|
||||
import { useAppContext } from '@/hooks/use-app-context';
|
||||
import { pushModal } from '@/modals';
|
||||
import { clipboard } from '@/utils/clipboard';
|
||||
|
||||
type Props = {
|
||||
interface Props {
|
||||
client: IServiceClient | null;
|
||||
};
|
||||
}
|
||||
|
||||
const ConnectWeb = ({ client }: Props) => {
|
||||
return (
|
||||
<>
|
||||
<div>
|
||||
<div className="flex items-center gap-2 text-xl font-bold capitalize mb-1">
|
||||
<MonitorIcon className="size-4" />
|
||||
Website
|
||||
</div>
|
||||
<div className="text-muted-foreground mb-2">
|
||||
Paste the script to your website
|
||||
</div>
|
||||
|
||||
<Syntax
|
||||
className="border"
|
||||
code={`<script>
|
||||
const context = useAppContext();
|
||||
const code = `<script>
|
||||
window.op=window.op||function(){var n=[];return new Proxy(function(){arguments.length&&n.push([].slice.call(arguments))},{get:function(t,r){return"q"===r?n:function(){n.push([r].concat([].slice.call(arguments)))}} ,has:function(t,r){return"q"===r}}) }();
|
||||
window.op('init', {
|
||||
window.op('init', {${context.isSelfHosted ? `\n\tapiUrl: '${context.apiUrl}',` : ''}
|
||||
clientId: '${client?.id ?? 'YOUR_CLIENT_ID'}',
|
||||
trackScreenViews: true,
|
||||
trackOutgoingLinks: true,
|
||||
trackAttributes: true,
|
||||
// sessionReplay: {
|
||||
// enabled: true,
|
||||
// },
|
||||
});
|
||||
</script>
|
||||
<script src="https://openpanel.dev/op1.js" defer async></script>`}
|
||||
/>
|
||||
<script src="https://openpanel.dev/op1.js" defer async></script>`;
|
||||
return (
|
||||
<>
|
||||
<div className="col gap-2">
|
||||
<div className="row items-center justify-between gap-4">
|
||||
<div className="flex items-center gap-2 font-bold text-xl capitalize">
|
||||
<PlugIcon className="size-4" />
|
||||
Quick start
|
||||
</div>
|
||||
<div className="row gap-2">
|
||||
<Button
|
||||
icon={CopyIcon}
|
||||
onClick={() => clipboard(code, null)}
|
||||
variant="outline"
|
||||
>
|
||||
Copy
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<Syntax className="border" code={code} />
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-muted-foreground mb-2">
|
||||
<div className="col gap-4">
|
||||
<p className="text-center text-muted-foreground text-sm">
|
||||
Or pick a framework below to get started.
|
||||
</p>
|
||||
<div className="grid gap-4 md:grid-cols-2">
|
||||
{frameworks
|
||||
.filter((framework) => framework.type.includes('website'))
|
||||
.map((framework) => (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() =>
|
||||
pushModal('Instructions', {
|
||||
framework,
|
||||
client,
|
||||
})
|
||||
}
|
||||
className="flex items-center gap-4 rounded-md border p-2 py-2 text-left"
|
||||
key={framework.name}
|
||||
>
|
||||
<div className="h-10 w-10 rounded-md bg-def-200 p-2">
|
||||
<framework.IconComponent className="h-full w-full" />
|
||||
</div>
|
||||
<div className="flex-1 font-semibold">{framework.name}</div>
|
||||
</button>
|
||||
))}
|
||||
{frameworks.map((framework) => (
|
||||
<button
|
||||
className="flex items-center gap-4 rounded-md border p-2 text-left"
|
||||
key={framework.name}
|
||||
onClick={() =>
|
||||
pushModal('Instructions', {
|
||||
framework,
|
||||
client,
|
||||
})
|
||||
}
|
||||
type="button"
|
||||
>
|
||||
<div className="h-10 w-10 rounded-md bg-def-200 p-2">
|
||||
<framework.IconComponent className="h-full w-full" />
|
||||
</div>
|
||||
<div className="flex-1 font-semibold">{framework.name}</div>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<p className="mt-2 text-sm text-muted-foreground">
|
||||
<p className="text-center text-muted-foreground text-sm">
|
||||
Missing a framework?{' '}
|
||||
<a
|
||||
href="mailto:hello@openpanel.dev"
|
||||
className="text-foreground underline"
|
||||
href="mailto:hello@openpanel.dev"
|
||||
>
|
||||
Let us know!
|
||||
</a>
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
import { useAppContext } from '@/hooks/use-app-context';
|
||||
import { useClientSecret } from '@/hooks/use-client-secret';
|
||||
import { clipboard } from '@/utils/clipboard';
|
||||
import type { IServiceProjectWithClients } from '@openpanel/db';
|
||||
import Syntax from '../syntax';
|
||||
import {
|
||||
Accordion,
|
||||
AccordionContent,
|
||||
AccordionItem,
|
||||
AccordionTrigger,
|
||||
} from '../ui/accordion';
|
||||
|
||||
export function CurlPreview({
|
||||
project,
|
||||
}: { project: IServiceProjectWithClients }) {
|
||||
const context = useAppContext();
|
||||
|
||||
const [secret] = useClientSecret();
|
||||
const client = project.clients[0];
|
||||
if (!client) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const payload: Record<string, any> = {
|
||||
type: 'track',
|
||||
payload: {
|
||||
name: 'screen_view',
|
||||
properties: {
|
||||
__title: `Testing OpenPanel - ${project.name}`,
|
||||
__path: `${project.domain}`,
|
||||
__referrer: `${context.dashboardUrl}`,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
if (project.types.includes('app')) {
|
||||
payload.payload.properties.__path = '/';
|
||||
delete payload.payload.properties.__referrer;
|
||||
}
|
||||
|
||||
if (project.types.includes('backend')) {
|
||||
payload.payload.name = 'test_event';
|
||||
payload.payload.properties = {};
|
||||
}
|
||||
|
||||
const code = `curl -X POST ${context.apiUrl}/track \\
|
||||
-H "Content-Type: application/json" \\
|
||||
-H "openpanel-client-id: ${client.id}" \\
|
||||
-H "openpanel-client-secret: ${secret}" \\
|
||||
-H "User-Agent: ${typeof window !== 'undefined' ? window.navigator.userAgent : ''}" \\
|
||||
-d '${JSON.stringify(payload)}'`;
|
||||
|
||||
return (
|
||||
<div className="card">
|
||||
<Accordion type="single" collapsible>
|
||||
<AccordionItem value="item-1">
|
||||
<AccordionTrigger
|
||||
className="px-6"
|
||||
onClick={() => {
|
||||
clipboard(code, null);
|
||||
}}
|
||||
>
|
||||
Try out the curl command
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="p-0">
|
||||
<Syntax code={code} language="bash" />
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,22 +1,20 @@
|
||||
import useWS from '@/hooks/use-ws';
|
||||
import { pushModal } from '@/modals';
|
||||
import { cn } from '@/utils/cn';
|
||||
import { timeAgo } from '@/utils/date';
|
||||
import { CheckCircle2Icon, CheckIcon, Loader2 } from 'lucide-react';
|
||||
import { useState } from 'react';
|
||||
|
||||
import type {
|
||||
IServiceClient,
|
||||
IServiceEvent,
|
||||
IServiceProject,
|
||||
} from '@openpanel/db';
|
||||
import { CheckCircle2Icon, CheckIcon, Loader2 } from 'lucide-react';
|
||||
import { useState } from 'react';
|
||||
import useWS from '@/hooks/use-ws';
|
||||
import { cn } from '@/utils/cn';
|
||||
import { timeAgo } from '@/utils/date';
|
||||
|
||||
type Props = {
|
||||
interface Props {
|
||||
project: IServiceProject;
|
||||
client: IServiceClient | null;
|
||||
events: IServiceEvent[];
|
||||
onVerified: (verified: boolean) => void;
|
||||
};
|
||||
}
|
||||
|
||||
const VerifyListener = ({ client, events: _events, onVerified }: Props) => {
|
||||
const [events, setEvents] = useState<IServiceEvent[]>(_events ?? []);
|
||||
@@ -25,7 +23,7 @@ const VerifyListener = ({ client, events: _events, onVerified }: Props) => {
|
||||
(data) => {
|
||||
setEvents((prev) => [...prev, data]);
|
||||
onVerified(true);
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const isConnected = events.length > 0;
|
||||
@@ -34,15 +32,15 @@ const VerifyListener = ({ client, events: _events, onVerified }: Props) => {
|
||||
if (isConnected) {
|
||||
return (
|
||||
<CheckCircle2Icon
|
||||
strokeWidth={1.2}
|
||||
size={40}
|
||||
className="shrink-0 text-emerald-600"
|
||||
size={40}
|
||||
strokeWidth={1.2}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Loader2 size={40} className="shrink-0 animate-spin text-highlight" />
|
||||
<Loader2 className="shrink-0 animate-spin text-highlight" size={40} />
|
||||
);
|
||||
};
|
||||
|
||||
@@ -51,24 +49,24 @@ const VerifyListener = ({ client, events: _events, onVerified }: Props) => {
|
||||
<div
|
||||
className={cn(
|
||||
'flex gap-6 rounded-xl p-4 md:p-6',
|
||||
isConnected ? 'bg-emerald-100 dark:bg-emerald-700' : 'bg-blue-500/10',
|
||||
isConnected ? 'bg-emerald-100 dark:bg-emerald-700' : 'bg-blue-500/10'
|
||||
)}
|
||||
>
|
||||
{renderIcon()}
|
||||
<div className="flex-1">
|
||||
<div className="text-lg font-semibold leading-normal text-foreground/90">
|
||||
<div className="font-semibold text-foreground/90 text-lg leading-normal">
|
||||
{isConnected ? 'Success' : 'Waiting for events'}
|
||||
</div>
|
||||
{isConnected ? (
|
||||
<div className="flex flex-col-reverse">
|
||||
{events.length > 5 && (
|
||||
<div className="flex items-center gap-2 ">
|
||||
<div className="flex items-center gap-2">
|
||||
<CheckIcon size={14} />{' '}
|
||||
<span>{events.length - 5} more events</span>
|
||||
</div>
|
||||
)}
|
||||
{events.slice(-5).map((event) => (
|
||||
<div key={event.id} className="flex items-center gap-2 ">
|
||||
<div className="flex items-center gap-2" key={event.id}>
|
||||
<CheckIcon size={14} />{' '}
|
||||
<span className="font-medium">{event.name}</span>{' '}
|
||||
<span className="ml-auto text-emerald-800">
|
||||
@@ -84,23 +82,6 @@ const VerifyListener = ({ client, events: _events, onVerified }: Props) => {
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mt-2 text-sm text-muted-foreground">
|
||||
You can{' '}
|
||||
<button
|
||||
type="button"
|
||||
className="underline"
|
||||
onClick={() => {
|
||||
pushModal('OnboardingTroubleshoot', {
|
||||
client,
|
||||
type: 'app',
|
||||
});
|
||||
}}
|
||||
>
|
||||
troubleshoot
|
||||
</button>{' '}
|
||||
if you are having issues connecting your app.
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
190
apps/start/src/components/onboarding/verify-faq.tsx
Normal file
190
apps/start/src/components/onboarding/verify-faq.tsx
Normal file
@@ -0,0 +1,190 @@
|
||||
import type { IServiceProjectWithClients } from '@openpanel/db';
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { GlobeIcon, KeyIcon, UserIcon } from 'lucide-react';
|
||||
import { toast } from 'sonner';
|
||||
import CopyInput from '../forms/copy-input';
|
||||
import { WithLabel } from '../forms/input-with-label';
|
||||
import TagInput from '../forms/tag-input';
|
||||
import Syntax from '../syntax';
|
||||
import {
|
||||
Accordion,
|
||||
AccordionContent,
|
||||
AccordionItem,
|
||||
AccordionTrigger,
|
||||
} from '../ui/accordion';
|
||||
import { Alert, AlertDescription, AlertTitle } from '../ui/alert';
|
||||
import { useAppContext } from '@/hooks/use-app-context';
|
||||
import { useClientSecret } from '@/hooks/use-client-secret';
|
||||
import { handleError, useTRPC } from '@/integrations/trpc/react';
|
||||
|
||||
export function VerifyFaq({
|
||||
project,
|
||||
}: {
|
||||
project: IServiceProjectWithClients;
|
||||
}) {
|
||||
const context = useAppContext();
|
||||
const trpc = useTRPC();
|
||||
const queryClient = useQueryClient();
|
||||
const [secret] = useClientSecret();
|
||||
|
||||
const updateProject = useMutation(
|
||||
trpc.project.update.mutationOptions({
|
||||
onError: handleError,
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries(
|
||||
trpc.project.getProjectWithClients.queryFilter({
|
||||
projectId: project.id,
|
||||
})
|
||||
);
|
||||
toast.success('Allowed domains updated');
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
const client = project.clients[0];
|
||||
if (!client) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const handleCorsChange = (newValue: string[]) => {
|
||||
const normalized = newValue
|
||||
.map((item: string) => {
|
||||
const trimmed = item.trim();
|
||||
if (
|
||||
trimmed.startsWith('http://') ||
|
||||
trimmed.startsWith('https://') ||
|
||||
trimmed === '*'
|
||||
) {
|
||||
return trimmed;
|
||||
}
|
||||
return trimmed ? `https://${trimmed}` : trimmed;
|
||||
})
|
||||
.filter(Boolean);
|
||||
updateProject.mutate({ id: project.id, cors: normalized });
|
||||
};
|
||||
|
||||
const showSecret = secret && secret !== '[CLIENT_SECRET]';
|
||||
|
||||
const payload: Record<string, any> = {
|
||||
type: 'track',
|
||||
payload: {
|
||||
name: 'screen_view',
|
||||
properties: {
|
||||
__title: `Testing OpenPanel - ${project.name}`,
|
||||
__path: `${project.domain}`,
|
||||
__referrer: `${context.dashboardUrl}`,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
if (project.types.includes('app')) {
|
||||
payload.payload.properties.__path = '/';
|
||||
delete payload.payload.properties.__referrer;
|
||||
}
|
||||
|
||||
if (project.types.includes('backend')) {
|
||||
payload.payload.name = 'test_event';
|
||||
payload.payload.properties = {};
|
||||
}
|
||||
|
||||
const code = `curl -X POST ${context.apiUrl}/track \\
|
||||
-H "Content-Type: application/json" \\
|
||||
-H "openpanel-client-id: ${client.id}" \\
|
||||
-H "openpanel-client-secret: ${secret}" \\
|
||||
-H "User-Agent: ${typeof window !== 'undefined' ? window.navigator.userAgent : ''}" \\
|
||||
-d '${JSON.stringify(payload)}'`;
|
||||
|
||||
return (
|
||||
<div className="card">
|
||||
<Accordion collapsible type="single">
|
||||
<AccordionItem value="item-1">
|
||||
<AccordionTrigger className="px-6">
|
||||
No events received?
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="col gap-4 p-6 pt-2">
|
||||
<p>
|
||||
Don't worry, this happens to everyone. Here are a few things you
|
||||
can check:
|
||||
</p>
|
||||
<div className="col gap-2">
|
||||
<Alert>
|
||||
<UserIcon size={16} />
|
||||
<AlertTitle>Ensure client ID is correct</AlertTitle>
|
||||
<AlertDescription className="col gap-2">
|
||||
<span>
|
||||
For web tracking, the <code>clientId</code> in your snippet
|
||||
must match this project. Copy it here if needed:
|
||||
</span>
|
||||
<CopyInput
|
||||
className="[&_.font-mono]:text-sm"
|
||||
label="Client ID"
|
||||
value={client.id}
|
||||
/>
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
<Alert>
|
||||
<GlobeIcon size={16} />
|
||||
<AlertTitle>Correct domain configured</AlertTitle>
|
||||
<AlertDescription className="col gap-2">
|
||||
<span>
|
||||
For websites it's important that the domain is
|
||||
correctly configured. We authenticate requests based on the
|
||||
domain. Update allowed domains below:
|
||||
</span>
|
||||
<WithLabel label="Allowed domains">
|
||||
<TagInput
|
||||
onChange={handleCorsChange}
|
||||
placeholder="Accept events from these domains"
|
||||
renderTag={(tag: string) =>
|
||||
tag === '*' ? 'Accept events from any domains' : tag
|
||||
}
|
||||
value={project.cors ?? []}
|
||||
/>
|
||||
</WithLabel>
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
<Alert>
|
||||
<KeyIcon size={16} />
|
||||
<AlertTitle>Wrong client secret</AlertTitle>
|
||||
<AlertDescription className="col gap-2">
|
||||
<span>
|
||||
For app and backend events you need the correct{' '}
|
||||
<code>clientSecret</code>. Copy it here if needed. Never use
|
||||
the client secret in web or client-side code—it would expose
|
||||
your credentials.
|
||||
</span>
|
||||
{showSecret && (
|
||||
<CopyInput
|
||||
className="[&_.font-mono]:text-sm"
|
||||
label="Client secret"
|
||||
value={secret}
|
||||
/>
|
||||
)}
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
</div>
|
||||
<p>
|
||||
Still have issues? Join our{' '}
|
||||
<a className="underline" href="https://go.openpanel.dev/discord">
|
||||
discord channel
|
||||
</a>{' '}
|
||||
give us an email at{' '}
|
||||
<a className="underline" href="mailto:hello@openpanel.dev">
|
||||
hello@openpanel.dev
|
||||
</a>{' '}
|
||||
and we'll help you out.
|
||||
</p>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
<AccordionItem value="item-2">
|
||||
<AccordionTrigger className="px-6">
|
||||
Personal curl example
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="p-0">
|
||||
<Syntax code={code} language="bash" />
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,18 +1,7 @@
|
||||
import {
|
||||
X_AXIS_STYLE_PROPS,
|
||||
useXAxisProps,
|
||||
useYAxisProps,
|
||||
} from '@/components/report-chart/common/axis';
|
||||
import { Widget, WidgetBody, WidgetHead } from '@/components/widget';
|
||||
import { useNumber } from '@/hooks/use-numer-formatter';
|
||||
import { useTRPC } from '@/integrations/trpc/react';
|
||||
import { formatDate } from '@/utils/date';
|
||||
import { getChartColor } from '@/utils/theme';
|
||||
import { sum } from '@openpanel/common';
|
||||
import type { IServiceOrganization } from '@openpanel/db';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { Loader2Icon } from 'lucide-react';
|
||||
import { pick } from 'ramda';
|
||||
import {
|
||||
Bar,
|
||||
BarChart,
|
||||
@@ -23,16 +12,24 @@ import {
|
||||
YAxis,
|
||||
} from 'recharts';
|
||||
import { BarShapeBlue } from '../charts/common-bar';
|
||||
import {
|
||||
useXAxisProps,
|
||||
useYAxisProps,
|
||||
} from '@/components/report-chart/common/axis';
|
||||
import { Widget, WidgetBody, WidgetHead } from '@/components/widget';
|
||||
import { useNumber } from '@/hooks/use-numer-formatter';
|
||||
import { useTRPC } from '@/integrations/trpc/react';
|
||||
import { formatDate } from '@/utils/date';
|
||||
|
||||
type Props = {
|
||||
interface Props {
|
||||
organization: IServiceOrganization;
|
||||
};
|
||||
}
|
||||
|
||||
function Card({ title, value }: { title: string; value: string }) {
|
||||
return (
|
||||
<div className="col gap-2 p-4 flex-1 min-w-0" title={`${title}: ${value}`}>
|
||||
<div className="text-muted-foreground truncate">{title}</div>
|
||||
<div className="font-mono text-xl font-bold truncate">{value}</div>
|
||||
<div className="col min-w-0 flex-1 gap-2 p-4" title={`${title}: ${value}`}>
|
||||
<div className="truncate text-muted-foreground">{title}</div>
|
||||
<div className="truncate font-bold font-mono text-xl">{value}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -43,18 +40,20 @@ export default function BillingUsage({ organization }: Props) {
|
||||
const usageQuery = useQuery(
|
||||
trpc.subscription.usage.queryOptions({
|
||||
organizationId: organization.id,
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
// Determine interval based on data range - use weekly if more than 30 days
|
||||
const getDataInterval = () => {
|
||||
if (!usageQuery.data || usageQuery.data.length === 0) return 'day';
|
||||
if (!usageQuery.data || usageQuery.data.length === 0) {
|
||||
return 'day';
|
||||
}
|
||||
|
||||
const dates = usageQuery.data.map((item) => new Date(item.day));
|
||||
const minDate = new Date(Math.min(...dates.map((d) => d.getTime())));
|
||||
const maxDate = new Date(Math.max(...dates.map((d) => d.getTime())));
|
||||
const daysDiff = Math.ceil(
|
||||
(maxDate.getTime() - minDate.getTime()) / (1000 * 60 * 60 * 24),
|
||||
(maxDate.getTime() - minDate.getTime()) / (1000 * 60 * 60 * 24)
|
||||
);
|
||||
|
||||
return daysDiff > 30 ? 'week' : 'day';
|
||||
@@ -78,7 +77,7 @@ export default function BillingUsage({ organization }: Props) {
|
||||
return wrapper(
|
||||
<div className="center-center p-8">
|
||||
<Loader2Icon className="animate-spin" />
|
||||
</div>,
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -86,13 +85,16 @@ export default function BillingUsage({ organization }: Props) {
|
||||
return wrapper(
|
||||
<div className="center-center p-8 font-medium">
|
||||
Issues loading usage data
|
||||
</div>,
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (usageQuery.data?.length === 0) {
|
||||
if (
|
||||
usageQuery.data?.length === 0 ||
|
||||
!usageQuery.data?.some((item) => item.count !== 0)
|
||||
) {
|
||||
return wrapper(
|
||||
<div className="center-center p-8 font-medium">No usage data yet</div>,
|
||||
<div className="center-center p-8 font-medium">No usage data yet</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -105,7 +107,9 @@ export default function BillingUsage({ organization }: Props) {
|
||||
|
||||
// Group daily data into weekly intervals if data spans more than 30 days
|
||||
const processChartData = () => {
|
||||
if (!usageQuery.data) return [];
|
||||
if (!usageQuery.data) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (useWeeklyIntervals) {
|
||||
// Group daily data into weekly intervals
|
||||
@@ -157,7 +161,7 @@ export default function BillingUsage({ organization }: Props) {
|
||||
Math.max(
|
||||
subscriptionPeriodEventsLimit,
|
||||
subscriptionPeriodEventsCount,
|
||||
...chartData.map((item) => item.count),
|
||||
...chartData.map((item) => item.count)
|
||||
),
|
||||
] as [number, number];
|
||||
|
||||
@@ -165,7 +169,7 @@ export default function BillingUsage({ organization }: Props) {
|
||||
|
||||
return wrapper(
|
||||
<>
|
||||
<div className="-m-4 mb-4 grid grid-cols-2 [&>div]:shadow-[0_0_0_0.5px] [&_div]:shadow-border border-b">
|
||||
<div className="-m-4 mb-4 grid grid-cols-2 border-b [&>div]:shadow-[0_0_0_0.5px] [&_div]:shadow-border">
|
||||
{organization.hasSubscription ? (
|
||||
<>
|
||||
<Card
|
||||
@@ -186,7 +190,7 @@ export default function BillingUsage({ organization }: Props) {
|
||||
1 -
|
||||
subscriptionPeriodEventsCount /
|
||||
subscriptionPeriodEventsLimit,
|
||||
'%',
|
||||
'%'
|
||||
)
|
||||
}
|
||||
/>
|
||||
@@ -208,7 +212,7 @@ export default function BillingUsage({ organization }: Props) {
|
||||
<Card
|
||||
title="Events from last 30 days"
|
||||
value={number.format(
|
||||
sum(usageQuery.data?.map((item) => item.count) ?? []),
|
||||
sum(usageQuery.data?.map((item) => item.count) ?? [])
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
@@ -217,12 +221,12 @@ export default function BillingUsage({ organization }: Props) {
|
||||
</div>
|
||||
{/* Events Chart */}
|
||||
<div className="space-y-2">
|
||||
<h3 className="text-sm font-medium text-muted-foreground">
|
||||
<h3 className="font-medium text-muted-foreground text-sm">
|
||||
{useWeeklyIntervals ? 'Weekly Events' : 'Daily Events'}
|
||||
</h3>
|
||||
<div className="max-h-[300px] h-[250px] w-full p-4">
|
||||
<div className="h-[250px] max-h-[300px] w-full p-4">
|
||||
<ResponsiveContainer>
|
||||
<BarChart data={chartData} barSize={useWeeklyIntervals ? 20 : 8}>
|
||||
<BarChart barSize={useWeeklyIntervals ? 20 : 8} data={chartData}>
|
||||
<RechartTooltip
|
||||
content={<EventsTooltip useWeekly={useWeeklyIntervals} />}
|
||||
cursor={{
|
||||
@@ -239,15 +243,15 @@ export default function BillingUsage({ organization }: Props) {
|
||||
<YAxis {...yAxisProps} domain={[0, 'dataMax']} />
|
||||
<CartesianGrid
|
||||
horizontal={true}
|
||||
vertical={false}
|
||||
strokeDasharray="3 3"
|
||||
strokeOpacity={0.5}
|
||||
vertical={false}
|
||||
/>
|
||||
</BarChart>
|
||||
</ResponsiveContainer>
|
||||
</div>
|
||||
</div>
|
||||
</>,
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -261,7 +265,7 @@ function EventsTooltip({ useWeekly, ...props }: { useWeekly: boolean } & any) {
|
||||
|
||||
return (
|
||||
<div className="flex min-w-[180px] flex-col gap-2 rounded-xl border bg-card p-3 shadow-xl">
|
||||
<div className="text-sm text-muted-foreground">
|
||||
<div className="text-muted-foreground text-sm">
|
||||
{useWeekly && payload.weekRange
|
||||
? payload.weekRange
|
||||
: payload?.date
|
||||
@@ -271,10 +275,10 @@ function EventsTooltip({ useWeekly, ...props }: { useWeekly: boolean } & any) {
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="h-10 w-1 rounded-full bg-chart-0" />
|
||||
<div className="col gap-1">
|
||||
<div className="text-sm text-muted-foreground">
|
||||
<div className="text-muted-foreground text-sm">
|
||||
Events {useWeekly ? 'this week' : 'this day'}
|
||||
</div>
|
||||
<div className="text-lg font-semibold text-chart-0">
|
||||
<div className="font-semibold text-chart-0 text-lg">
|
||||
{number.format(payload.count)}
|
||||
</div>
|
||||
</div>
|
||||
@@ -293,22 +297,22 @@ function TotalTooltip(props: any) {
|
||||
|
||||
return (
|
||||
<div className="flex min-w-[180px] flex-col gap-2 rounded-xl border bg-card p-3 shadow-xl">
|
||||
<div className="text-sm text-muted-foreground">Total Events</div>
|
||||
<div className="text-muted-foreground text-sm">Total Events</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="h-10 w-1 rounded-full bg-chart-2" />
|
||||
<div className="col gap-1">
|
||||
<div className="text-sm text-muted-foreground">Your events count</div>
|
||||
<div className="text-lg font-semibold text-chart-2">
|
||||
<div className="text-muted-foreground text-sm">Your events count</div>
|
||||
<div className="font-semibold text-chart-2 text-lg">
|
||||
{number.format(payload.count)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{payload.limit > 0 && (
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="h-10 w-1 rounded-full border-2 border-dashed border-chart-1" />
|
||||
<div className="h-10 w-1 rounded-full border-2 border-chart-1 border-dashed" />
|
||||
<div className="col gap-1">
|
||||
<div className="text-sm text-muted-foreground">Your tier limit</div>
|
||||
<div className="text-lg font-semibold text-chart-1">
|
||||
<div className="text-muted-foreground text-sm">Your tier limit</div>
|
||||
<div className="font-semibold text-chart-1 text-lg">
|
||||
{number.format(payload.limit)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,9 +1,3 @@
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useNumber } from '@/hooks/use-numer-formatter';
|
||||
import useWS from '@/hooks/use-ws';
|
||||
import { useTRPC } from '@/integrations/trpc/react';
|
||||
import { pushModal, useOnPushModal } from '@/modals';
|
||||
import { formatDate } from '@/utils/date';
|
||||
import type { IServiceOrganization } from '@openpanel/db';
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
import { differenceInDays } from 'date-fns';
|
||||
@@ -14,6 +8,12 @@ import { Progress } from '../ui/progress';
|
||||
import { Widget, WidgetBody, WidgetHead } from '../widget';
|
||||
import { BillingFaq } from './billing-faq';
|
||||
import BillingUsage from './billing-usage';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useNumber } from '@/hooks/use-numer-formatter';
|
||||
import useWS from '@/hooks/use-ws';
|
||||
import { useTRPC } from '@/integrations/trpc/react';
|
||||
import { pushModal, useOnPushModal } from '@/modals';
|
||||
import { formatDate } from '@/utils/date';
|
||||
|
||||
type Props = {
|
||||
organization: IServiceOrganization;
|
||||
@@ -28,13 +28,13 @@ export default function Billing({ organization }: Props) {
|
||||
const productsQuery = useQuery(
|
||||
trpc.subscription.products.queryOptions({
|
||||
organizationId: organization.id,
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
const currentProductQuery = useQuery(
|
||||
trpc.subscription.getCurrent.queryOptions({
|
||||
organizationId: organization.id,
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
const portalMutation = useMutation(
|
||||
@@ -47,7 +47,7 @@ export default function Billing({ organization }: Props) {
|
||||
onError(error) {
|
||||
toast.error(error.message);
|
||||
},
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
useWS(`/live/organization/${organization.id}`, () => {
|
||||
@@ -55,7 +55,7 @@ export default function Billing({ organization }: Props) {
|
||||
});
|
||||
|
||||
const [recurringInterval, setRecurringInterval] = useState<'year' | 'month'>(
|
||||
(organization.subscriptionInterval as 'year' | 'month') || 'month',
|
||||
(organization.subscriptionInterval as 'year' | 'month') || 'month'
|
||||
);
|
||||
|
||||
const products = useMemo(() => {
|
||||
@@ -66,7 +66,7 @@ export default function Billing({ organization }: Props) {
|
||||
|
||||
const currentProduct = currentProductQuery.data ?? null;
|
||||
const currentPrice = currentProduct?.prices.flatMap((p) =>
|
||||
p.type === 'recurring' && p.amountType === 'fixed' ? [p] : [],
|
||||
p.type === 'recurring' && p.amountType === 'fixed' ? [p] : []
|
||||
)[0];
|
||||
|
||||
const renderStatus = () => {
|
||||
@@ -138,12 +138,12 @@ export default function Billing({ organization }: Props) {
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-8">
|
||||
<div className="grid grid-cols-1 gap-8 md:grid-cols-2">
|
||||
<div className="col gap-8">
|
||||
{currentProduct && currentPrice ? (
|
||||
<Widget className="w-full">
|
||||
<WidgetHead className="flex items-center justify-between gap-4">
|
||||
<div className="flex-1 title truncate">{currentProduct.name}</div>
|
||||
<div className="title flex-1 truncate">{currentProduct.name}</div>
|
||||
<div className="text-lg">
|
||||
<span className="font-bold">
|
||||
{number.currency(currentPrice.priceAmount / 100)}
|
||||
@@ -157,58 +157,58 @@ export default function Billing({ organization }: Props) {
|
||||
<WidgetBody>
|
||||
{renderStatus()}
|
||||
<div className="col mt-4">
|
||||
<div className="font-semibold mb-2">
|
||||
<div className="mb-2 font-semibold">
|
||||
{number.format(organization.subscriptionPeriodEventsCount)} /{' '}
|
||||
{number.format(Number(currentProduct.metadata.eventsLimit))}
|
||||
</div>
|
||||
<Progress
|
||||
size="sm"
|
||||
value={
|
||||
(organization.subscriptionPeriodEventsCount /
|
||||
Number(currentProduct.metadata.eventsLimit)) *
|
||||
100
|
||||
}
|
||||
size="sm"
|
||||
/>
|
||||
<div className="row justify-between mt-4">
|
||||
<div className="row mt-4 justify-between">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() =>
|
||||
portalMutation.mutate({ organizationId: organization.id })
|
||||
}
|
||||
size="sm"
|
||||
variant="outline"
|
||||
>
|
||||
<svg
|
||||
className="size-4 mr-2"
|
||||
width="300"
|
||||
className="mr-2 size-4"
|
||||
fill="none"
|
||||
height="300"
|
||||
viewBox="0 0 300 300"
|
||||
fill="none"
|
||||
width="300"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<g clip-path="url(#clip0_1_4)">
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
clip-rule="evenodd"
|
||||
d="M66.4284 274.26C134.876 320.593 227.925 302.666 274.258 234.219C320.593 165.771 302.666 72.7222 234.218 26.3885C165.77 -19.9451 72.721 -2.0181 26.3873 66.4297C-19.9465 134.877 -2.01938 227.927 66.4284 274.26ZM47.9555 116.67C30.8375 169.263 36.5445 221.893 59.2454 256.373C18.0412 217.361 7.27564 150.307 36.9437 92.318C55.9152 55.2362 87.5665 29.3937 122.5 18.3483C90.5911 36.7105 62.5549 71.8144 47.9555 116.67ZM175.347 283.137C211.377 272.606 244.211 246.385 263.685 208.322C293.101 150.825 282.768 84.4172 242.427 45.2673C264.22 79.7626 269.473 131.542 252.631 183.287C237.615 229.421 208.385 265.239 175.347 283.137ZM183.627 266.229C207.945 245.418 228.016 210.604 236.936 168.79C251.033 102.693 232.551 41.1978 195.112 20.6768C214.97 47.3945 225.022 99.2902 218.824 157.333C214.085 201.724 200.814 240.593 183.627 266.229ZM63.7178 131.844C49.5155 198.43 68.377 260.345 106.374 280.405C85.9962 254.009 75.5969 201.514 81.8758 142.711C86.5375 99.0536 99.4504 60.737 116.225 35.0969C92.2678 55.983 72.5384 90.4892 63.7178 131.844ZM199.834 149.561C200.908 217.473 179.59 272.878 152.222 273.309C124.853 273.742 101.797 219.039 100.724 151.127C99.6511 83.2138 120.968 27.8094 148.337 27.377C175.705 26.9446 198.762 81.648 199.834 149.561Z"
|
||||
fill="currentColor"
|
||||
fill-rule="evenodd"
|
||||
/>
|
||||
</g>
|
||||
<defs>
|
||||
<clipPath id="clip0_1_4">
|
||||
<rect width="300" height="300" fill="white" />
|
||||
<rect fill="white" height="300" width="300" />
|
||||
</clipPath>
|
||||
</defs>
|
||||
</svg>
|
||||
Customer portal
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={() =>
|
||||
pushModal('SelectBillingPlan', {
|
||||
organization,
|
||||
currentProduct,
|
||||
})
|
||||
}
|
||||
size="sm"
|
||||
>
|
||||
{organization.isWillBeCanceled
|
||||
? 'Reactivate subscription'
|
||||
@@ -221,15 +221,13 @@ export default function Billing({ organization }: Props) {
|
||||
) : (
|
||||
<Widget className="w-full">
|
||||
<WidgetHead className="flex items-center justify-between">
|
||||
<div className="font-bold text-lg flex-1">
|
||||
<div className="flex-1 font-bold text-lg">
|
||||
{organization.isTrial
|
||||
? 'Get started'
|
||||
: 'No active subscription'}
|
||||
</div>
|
||||
<div className="text-lg">
|
||||
<span className="">
|
||||
{organization.isTrial ? '30 days free trial' : ''}
|
||||
</span>
|
||||
<div className="text-muted-foreground">
|
||||
{organization.isTrial ? '30 days free trial' : ''}
|
||||
</div>
|
||||
</WidgetHead>
|
||||
<WidgetBody>
|
||||
@@ -239,7 +237,7 @@ export default function Billing({ organization }: Props) {
|
||||
{formatDate(organization.subscriptionEndsAt)} (
|
||||
{differenceInDays(
|
||||
organization.subscriptionEndsAt,
|
||||
new Date(),
|
||||
new Date()
|
||||
) + 1}{' '}
|
||||
days left)
|
||||
</p>
|
||||
@@ -250,29 +248,29 @@ export default function Billing({ organization }: Props) {
|
||||
</p>
|
||||
)}
|
||||
<div className="col mt-4">
|
||||
<div className="font-semibold mb-2">
|
||||
<div className="mb-2 font-semibold">
|
||||
{number.format(organization.subscriptionPeriodEventsCount)} /{' '}
|
||||
{number.format(
|
||||
Number(organization.subscriptionPeriodEventsLimit),
|
||||
Number(organization.subscriptionPeriodEventsLimit)
|
||||
)}
|
||||
</div>
|
||||
<Progress
|
||||
size="sm"
|
||||
value={
|
||||
(organization.subscriptionPeriodEventsCount /
|
||||
Number(organization.subscriptionPeriodEventsLimit)) *
|
||||
100
|
||||
}
|
||||
size="sm"
|
||||
/>
|
||||
<div className="row justify-end mt-4">
|
||||
<div className="row mt-4 justify-end">
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={() =>
|
||||
pushModal('SelectBillingPlan', {
|
||||
organization,
|
||||
currentProduct,
|
||||
})
|
||||
}
|
||||
size="sm"
|
||||
>
|
||||
Upgrade
|
||||
</Button>
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
export function SkeletonDashboard() {
|
||||
return (
|
||||
<div className="fixed inset-0 bg-gradient-to-br from-def-100 to-def-200 overflow-hidden">
|
||||
<div className="inset-0 fixed backdrop-blur-xs bg-background/10 z-10" />
|
||||
<div className="fixed inset-0 overflow-hidden bg-gradient-to-br from-def-100 to-def-200">
|
||||
<div className="fixed inset-0 z-10 bg-background/10 backdrop-blur-xs" />
|
||||
{/* Sidebar Skeleton */}
|
||||
<div className="fixed left-0 top-0 w-72 h-full bg-background/80 border-r border-def-300/50 backdrop-blur-sm">
|
||||
<div className="fixed top-0 left-0 h-full w-72 border-def-300/50 border-r bg-background/80 backdrop-blur-sm">
|
||||
{/* Logo area */}
|
||||
<div className="h-16 border-b border-def-300/50 flex items-center px-4">
|
||||
<div className="w-8 h-8 bg-def-300/60 rounded-lg" />
|
||||
<div className="ml-3 w-24 h-4 bg-def-300/60 rounded" />
|
||||
<div className="flex h-16 items-center border-def-300/50 border-b px-4">
|
||||
<div className="h-8 w-8 rounded-lg bg-def-300/60" />
|
||||
<div className="ml-3 h-4 w-24 rounded bg-def-300/60" />
|
||||
</div>
|
||||
|
||||
{/* Navigation items */}
|
||||
<div className="p-4 space-y-3">
|
||||
<div className="space-y-3 p-4">
|
||||
{[
|
||||
'Dashboard',
|
||||
'Analytics',
|
||||
@@ -21,28 +21,28 @@ export function SkeletonDashboard() {
|
||||
'Projects',
|
||||
].map((item, i) => (
|
||||
<div
|
||||
className="flex items-center space-x-3 rounded-lg p-2"
|
||||
key={`nav-${item.toLowerCase()}`}
|
||||
className="flex items-center space-x-3 p-2 rounded-lg"
|
||||
>
|
||||
<div className="w-5 h-5 bg-def-300/60 rounded" />
|
||||
<div className="w-20 h-3 bg-def-300/60 rounded" />
|
||||
<div className="h-5 w-5 rounded bg-def-300/60" />
|
||||
<div className="h-3 w-20 rounded bg-def-300/60" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Project section */}
|
||||
<div className="px-4 py-2">
|
||||
<div className="w-16 h-3 bg-def-300/60 rounded mb-3" />
|
||||
<div className="mb-3 h-3 w-16 rounded bg-def-300/60" />
|
||||
{['Project Alpha', 'Project Beta', 'Project Gamma'].map(
|
||||
(project, i) => (
|
||||
<div
|
||||
className="mb-2 flex items-center space-x-3 rounded-lg p-2"
|
||||
key={`project-${project.toLowerCase().replace(' ', '-')}`}
|
||||
className="flex items-center space-x-3 p-2 rounded-lg mb-2"
|
||||
>
|
||||
<div className="w-4 h-4 bg-def-300/60 rounded" />
|
||||
<div className="w-24 h-3 bg-def-300/60 rounded" />
|
||||
<div className="h-4 w-4 rounded bg-def-300/60" />
|
||||
<div className="h-3 w-24 rounded bg-def-300/60" />
|
||||
</div>
|
||||
),
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
@@ -51,17 +51,17 @@ export function SkeletonDashboard() {
|
||||
<div className="ml-72 p-8">
|
||||
{/* Header area */}
|
||||
<div className="mb-8">
|
||||
<div className="flex justify-between items-center mb-4">
|
||||
<div className="w-48 h-6 bg-def-300/60 rounded" />
|
||||
<div className="mb-4 flex items-center justify-between">
|
||||
<div className="h-6 w-48 rounded bg-def-300/60" />
|
||||
<div className="flex space-x-2">
|
||||
<div className="w-20 h-8 bg-def-300/60 rounded" />
|
||||
<div className="w-20 h-8 bg-def-300/60 rounded" />
|
||||
<div className="h-8 w-20 rounded bg-def-300/60" />
|
||||
<div className="h-8 w-20 rounded bg-def-300/60" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Dashboard grid */}
|
||||
<div className="grid grid-cols-3 gap-6 mb-8">
|
||||
<div className="mb-8 grid grid-cols-3 gap-6">
|
||||
{[
|
||||
'Total Users',
|
||||
'Active Sessions',
|
||||
@@ -71,36 +71,36 @@ export function SkeletonDashboard() {
|
||||
'Revenue',
|
||||
].map((metric, i) => (
|
||||
<div
|
||||
className="rounded-xl border border-def-300/50 bg-card/60 p-6"
|
||||
key={`metric-${metric.toLowerCase().replace(' ', '-')}`}
|
||||
className="bg-card/60 rounded-xl p-6 border border-def-300/50"
|
||||
>
|
||||
<div className="w-16 h-4 bg-def-300/60 rounded mb-3" />
|
||||
<div className="w-24 h-8 bg-def-300/60 rounded mb-2" />
|
||||
<div className="w-32 h-3 bg-def-300/60 rounded" />
|
||||
<div className="mb-3 h-4 w-16 rounded bg-def-300/60" />
|
||||
<div className="mb-2 h-8 w-24 rounded bg-def-300/60" />
|
||||
<div className="h-3 w-32 rounded bg-def-300/60" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Chart area */}
|
||||
<div className="grid grid-cols-2 gap-6">
|
||||
<div className="bg-card/60 rounded-xl p-6 border border-def-300/50 h-64">
|
||||
<div className="w-20 h-4 bg-def-300/60 rounded mb-4" />
|
||||
<div className="h-64 rounded-xl border border-def-300/50 bg-card/60 p-6">
|
||||
<div className="mb-4 h-4 w-20 rounded bg-def-300/60" />
|
||||
<div className="space-y-3">
|
||||
{['Desktop', 'Mobile', 'Tablet', 'Other'].map((device, i) => (
|
||||
<div
|
||||
key={`chart-${device.toLowerCase()}`}
|
||||
className="flex items-center space-x-3"
|
||||
key={`chart-${device.toLowerCase()}`}
|
||||
>
|
||||
<div className="w-3 h-3 bg-def-300/60 rounded-full" />
|
||||
<div className="flex-1 h-2 bg-def-300/60 rounded" />
|
||||
<div className="w-8 h-3 bg-def-300/60 rounded" />
|
||||
<div className="h-3 w-3 rounded-full bg-def-300/60" />
|
||||
<div className="h-2 flex-1 rounded bg-def-300/60" />
|
||||
<div className="h-3 w-8 rounded bg-def-300/60" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-card/60 rounded-xl p-6 border border-def-300/50 h-64">
|
||||
<div className="w-20 h-4 bg-def-300/60 rounded mb-4" />
|
||||
<div className="h-64 rounded-xl border border-def-300/50 bg-card/60 p-6">
|
||||
<div className="mb-4 h-4 w-20 rounded bg-def-300/60" />
|
||||
<div className="space-y-3">
|
||||
{[
|
||||
'John Doe',
|
||||
@@ -110,15 +110,15 @@ export function SkeletonDashboard() {
|
||||
'Charlie Wilson',
|
||||
].map((user, i) => (
|
||||
<div
|
||||
key={`user-${user.toLowerCase().replace(' ', '-')}`}
|
||||
className="flex items-center space-x-3"
|
||||
key={`user-${user.toLowerCase().replace(' ', '-')}`}
|
||||
>
|
||||
<div className="w-8 h-8 bg-def-300/60 rounded-full" />
|
||||
<div className="h-8 w-8 rounded-full bg-def-300/60" />
|
||||
<div className="flex-1">
|
||||
<div className="w-24 h-3 bg-def-300/60 rounded mb-1" />
|
||||
<div className="w-16 h-2 bg-def-300/60 rounded" />
|
||||
<div className="mb-1 h-3 w-24 rounded bg-def-300/60" />
|
||||
<div className="h-2 w-16 rounded bg-def-300/60" />
|
||||
</div>
|
||||
<div className="w-12 h-3 bg-def-300/60 rounded" />
|
||||
<div className="h-3 w-12 rounded bg-def-300/60" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -1,21 +1,24 @@
|
||||
import { clipboard } from '@/utils/clipboard';
|
||||
import { cn } from '@/utils/cn';
|
||||
import { CopyIcon } from 'lucide-react';
|
||||
import { Light as SyntaxHighlighter } from 'react-syntax-highlighter';
|
||||
import bash from 'react-syntax-highlighter/dist/cjs/languages/hljs/bash';
|
||||
import json from 'react-syntax-highlighter/dist/cjs/languages/hljs/json';
|
||||
import markdown from 'react-syntax-highlighter/dist/cjs/languages/hljs/markdown';
|
||||
import ts from 'react-syntax-highlighter/dist/cjs/languages/hljs/typescript';
|
||||
import docco from 'react-syntax-highlighter/dist/cjs/styles/hljs/vs2015';
|
||||
import { clipboard } from '@/utils/clipboard';
|
||||
import { cn } from '@/utils/cn';
|
||||
|
||||
SyntaxHighlighter.registerLanguage('typescript', ts);
|
||||
SyntaxHighlighter.registerLanguage('json', json);
|
||||
SyntaxHighlighter.registerLanguage('bash', bash);
|
||||
SyntaxHighlighter.registerLanguage('markdown', markdown);
|
||||
|
||||
interface SyntaxProps {
|
||||
code: string;
|
||||
className?: string;
|
||||
language?: 'typescript' | 'bash' | 'json';
|
||||
language?: 'typescript' | 'bash' | 'json' | 'markdown';
|
||||
wrapLines?: boolean;
|
||||
copyable?: boolean;
|
||||
}
|
||||
|
||||
export default function Syntax({
|
||||
@@ -23,23 +26,23 @@ export default function Syntax({
|
||||
className,
|
||||
language = 'typescript',
|
||||
wrapLines = false,
|
||||
copyable = true,
|
||||
}: SyntaxProps) {
|
||||
return (
|
||||
<div className={cn('group relative rounded-lg', className)}>
|
||||
<button
|
||||
type="button"
|
||||
className="absolute right-1 top-1 rounded bg-card p-2 opacity-0 transition-opacity group-hover:opacity-100 row items-center gap-2"
|
||||
onClick={() => {
|
||||
clipboard(code);
|
||||
}}
|
||||
>
|
||||
<span>Copy</span>
|
||||
<CopyIcon size={12} />
|
||||
</button>
|
||||
{copyable && (
|
||||
<button
|
||||
className="row absolute top-1 right-1 items-center gap-2 rounded bg-card p-2 opacity-0 transition-opacity group-hover:opacity-100"
|
||||
onClick={() => {
|
||||
clipboard(code, null);
|
||||
}}
|
||||
type="button"
|
||||
>
|
||||
<span>Copy</span>
|
||||
<CopyIcon size={12} />
|
||||
</button>
|
||||
)}
|
||||
<SyntaxHighlighter
|
||||
wrapLongLines={wrapLines}
|
||||
style={docco}
|
||||
language={language}
|
||||
customStyle={{
|
||||
borderRadius: 'var(--radius)',
|
||||
padding: '1rem',
|
||||
@@ -48,6 +51,9 @@ export default function Syntax({
|
||||
fontSize: 14,
|
||||
lineHeight: 1.3,
|
||||
}}
|
||||
language={language}
|
||||
style={docco}
|
||||
wrapLongLines={wrapLines}
|
||||
>
|
||||
{code}
|
||||
</SyntaxHighlighter>
|
||||
|
||||
Reference in New Issue
Block a user