OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.
fix: ability to create new organizations
Carl-Gerhard Lindesvärd0d122cdf452f
diff --git a/apps/start/src/components/forms/input-with-label.tsx b/apps/start/src/components/forms/input-with-label.tsxindex 6e07fa618..4b74fcb8e 100644--- a/apps/start/src/components/forms/input-with-label.tsx+++ b/apps/start/src/components/forms/input-with-label.tsx@@ -1,18 +1,17 @@import { BanIcon, InfoIcon } from 'lucide-react';import { forwardRef } from 'react';--import { Input } from '../ui/input';import type { InputProps } from '../ui/input';+import { Input } from '../ui/input';import { Label } from '../ui/label';import { Tooltiper } from '../ui/tooltip';-type WithLabel = {+interface WithLabel {children: React.ReactNode;label: string;error?: string | undefined;info?: React.ReactNode;className?: string;-};+}type InputWithLabelProps = InputProps & Omit<WithLabel, 'children'>;export const WithLabel = ({@@ -38,12 +37,12 @@ export const WithLabel = ({</Label>{error && (<Tooltiper+ align="end"asChildcontent={error}tooltipClassName="max-w-80 leading-normal"- align="end">- <div className="flex items-center gap-1 leading-none text-destructive">+ <div className="flex items-center gap-1 text-destructive leading-none">Issues<BanIcon size={14} /></div>@@ -59,10 +58,10 @@ export const InputWithLabel = forwardRef<HTMLInputElement, InputWithLabelProps>((props, ref) => {return (<WithLabel {...props}>- <Input ref={ref} id={props.label} {...props} />+ <Input id={props.label} ref={ref} {...props} /></WithLabel>);- },+ });InputWithLabel.displayName = 'InputWithLabel';diff --git a/apps/start/src/components/ui/label.tsx b/apps/start/src/components/ui/label.tsxindex 61c5a2377..0da71a75f 100644--- a/apps/start/src/components/ui/label.tsx+++ b/apps/start/src/components/ui/label.tsx@@ -1,11 +1,11 @@-import { cn } from '@/utils/cn';import * as LabelPrimitive from '@radix-ui/react-label';-import { cva } from 'class-variance-authority';import type { VariantProps } from 'class-variance-authority';+import { cva } from 'class-variance-authority';import * as React from 'react';+import { cn } from '@/utils/cn';const labelVariants = cva(- 'mb-3 text-sm block font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 text-foreground/70',+ 'mb-3 block min-h-3.5 font-medium text-foreground/70 text-sm leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70');const Label = React.forwardRef<@@ -14,8 +14,8 @@ const Label = React.forwardRef<VariantProps<typeof labelVariants>>(({ className, ...props }, ref) => (<LabelPrimitive.Root- ref={ref}className={cn(labelVariants(), className)}+ ref={ref}{...props}/>));diff --git a/apps/start/src/routes/_steps.onboarding.project.tsx b/apps/start/src/routes/_steps.onboarding.project.tsxindex f09147383..a6e616259 100644--- a/apps/start/src/routes/_steps.onboarding.project.tsx+++ b/apps/start/src/routes/_steps.onboarding.project.tsx@@ -1,6 +1,6 @@import { zodResolver } from '@hookform/resolvers/zod';import { zOnboardingProject } from '@openpanel/validation';-import { useMutation, useQuery } from '@tanstack/react-query';+import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';import { createFileRoute, redirect, useNavigate } from '@tanstack/react-router';import {BuildingIcon,@@ -41,13 +41,21 @@ export const Route = createFileRoute('/_steps/onboarding/project')({},loader: async ({ context, location }) => {const search = validateSearch.safeParse(location.search);+ const promises: Promise<unknown>[] = [+ context.queryClient.prefetchQuery(+ context.trpc.organization.list.queryOptions()+ ),+ ];if (search.success && search.data.inviteId) {- await context.queryClient.prefetchQuery(- context.trpc.organization.getInvite.queryOptions({- inviteId: search.data.inviteId,- })+ promises.push(+ context.queryClient.prefetchQuery(+ context.trpc.organization.getInvite.queryOptions({+ inviteId: search.data.inviteId,+ })+ ));}+ await Promise.all(promises);},pendingComponent: FullPageLoadingState,});@@ -56,6 +64,7 @@ type IForm = z.infer<typeof zOnboardingProject>;function Component() {const trpc = useTRPC();+ const queryClient = useQueryClient();const { data: organizations } = useQuery(trpc.organization.list.queryOptions(undefined, { initialData: [] }));@@ -65,6 +74,7 @@ function Component() {trpc.onboarding.project.mutationOptions({onError: handleError,onSuccess(res) {+ queryClient.invalidateQueries(trpc.organization.list.queryFilter());setSecret(res.secret);navigate({to: '/onboarding/$projectId/connect',@@ -111,6 +121,9 @@ function Component() {});const [showCorsInput, setShowCorsInput] = useState(false);+ const [createNewOrg, setCreateNewOrg] = useState(false);+ const canUseExistingWorkspace = organizations.length > 0;+ const showCreateForm = createNewOrg || organizations.length === 0;useEffect(() => {if (!isWebsite) {@@ -134,36 +147,38 @@ function Component() {onSubmit={form.handleSubmit(onSubmit)}><div className="scrollbar-thin flex-1 overflow-y-auto p-4">+ <div className="row mb-4 gap-2 rounded-lg bg-muted p-1">+ <button+ className={cn(+ 'rounded-md px-3 py-2 font-medium text-sm transition-colors',+ createNewOrg || !canUseExistingWorkspace+ ? 'bg-background text-foreground shadow-sm'+ : 'text-muted-foreground hover:text-foreground'+ )}+ onClick={() => setCreateNewOrg(true)}+ type="button"+ >+ Create new workspace+ </button>+ <button+ className={cn(+ 'rounded-md px-3 py-2 font-medium text-sm transition-colors',+ !createNewOrg && canUseExistingWorkspace+ ? 'bg-background text-foreground shadow-sm'+ : 'text-muted-foreground',+ canUseExistingWorkspace+ ? 'hover:text-foreground'+ : 'cursor-not-allowed opacity-60'+ )}+ disabled={!canUseExistingWorkspace}+ onClick={() => setCreateNewOrg(false)}+ type="button"+ >+ Use existing workspace+ </button>+ </div><div className="grid gap-4 md:grid-cols-2">- {organizations.length > 0 ? (- <Controller- control={form.control}- name="organizationId"- render={({ field, formState }) => {- return (- <div>- <Label>Workspace</Label>- <Combobox- className="w-full"- error={formState.errors.organizationId?.message}- icon={BuildingIcon}- items={- organizations- .filter((item) => item.id)- .map((item) => ({- label: item.name,- value: item.id,- })) ?? []- }- onChange={field.onChange}- placeholder="Select workspace"- value={field.value}- />- </div>- );- }}- />- ) : (+ {showCreateForm ? (<><InputWithLabelerror={form.formState.errors.organization?.message}@@ -191,7 +206,64 @@ function Component() {</WithLabel>)}/>+ {/* {organizations.length > 0 && (+ <button+ className="-mt-2 self-start text-left text-muted-foreground text-sm hover:text-foreground"+ onClick={() => {+ form.setValue('organization', '', {+ shouldValidate: false,+ });+ form.clearErrors(['organization', 'organizationId']);+ setCreateNewOrg(false);+ }}+ type="button"+ >+ ← Use existing workspace+ </button>+ )} */}</>+ ) : (+ <div className="col-span-2">+ <Controller+ control={form.control}+ name="organizationId"+ render={({ field, formState }) => {+ return (+ <WithLabel label="Workspace">+ <Combobox+ className="w-full"+ error={formState.errors.organizationId?.message}+ icon={BuildingIcon}+ items={+ organizations+ .filter((item) => item.id)+ .map((item) => ({+ label: item.name,+ value: item.id,+ })) ?? []+ }+ onChange={field.onChange}+ placeholder="Select workspace"+ value={field.value}+ />+ </WithLabel>+ );+ }}+ />+ {/* <button+ className="mt-2 text-muted-foreground text-sm hover:text-foreground"+ onClick={() => {+ form.setValue('organizationId', undefined, {+ shouldValidate: false,+ });+ form.clearErrors(['organization', 'organizationId']);+ setCreateNewOrg(true);+ }}+ type="button"+ >+ + Create new workspace+ </button> */}+ </div>)}<InputWithLabelerror={form.formState.errors.project?.message}