Skip to content

Commit dbd4ebd

Browse files
authored
feat: add new company creation route (#84)
* feat: add create company page * feat: add company switcher * fix: requested changes
1 parent 626f8ff commit dbd4ebd

File tree

4 files changed

+73
-33
lines changed

4 files changed

+73
-33
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import OnboardingCompany from "@/components/onboarding/company";
2+
import { withServerSession } from "@/server/auth";
3+
4+
const OnboardingPage = async () => {
5+
const session = await withServerSession();
6+
const user = session.user;
7+
8+
return <OnboardingCompany formType="create-company" currentUser={user} />;
9+
};
10+
11+
export default OnboardingPage;

src/components/dashboard/sidebar/company-switcher.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,25 @@ import {
66
SelectContent,
77
SelectItem,
88
SelectValue,
9+
SelectSeparator,
10+
SelectItemStyle,
911
} from "@/components/ui/select";
12+
1013
import { type TGetCompanyList } from "@/server/company";
1114
import { api } from "@/trpc/react";
1215
import { useSession } from "next-auth/react";
1316
import { useRouter, useSelectedLayoutSegment } from "next/navigation";
1417
import { useState } from "react";
18+
import * as SelectPrimitive from "@radix-ui/react-select";
19+
import { RiAddCircleLine } from "@remixicon/react";
1520

1621
interface CompanySwitcherProps {
1722
companies: TGetCompanyList;
1823
publicId: string;
1924
}
2025

26+
const createCompanyValue = "cap-co-create-company";
27+
2128
export function CompanySwitcher({ companies, publicId }: CompanySwitcherProps) {
2229
const value = useState(() => publicId)[0];
2330
const { update } = useSession();
@@ -30,6 +37,10 @@ export function CompanySwitcher({ companies, publicId }: CompanySwitcherProps) {
3037
<Select
3138
value={value}
3239
onValueChange={async (newValue) => {
40+
if (newValue === createCompanyValue) {
41+
router.push("/company/new");
42+
}
43+
3344
if (newValue !== value) {
3445
const membership = companies.find(
3546
(item) => item.company.publicId === newValue,
@@ -52,6 +63,18 @@ export function CompanySwitcher({ companies, publicId }: CompanySwitcherProps) {
5263
{item.company.name}
5364
</SelectItem>
5465
))}
66+
67+
<SelectSeparator />
68+
<SelectPrimitive.Item
69+
value={createCompanyValue}
70+
className={SelectItemStyle}
71+
>
72+
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
73+
<RiAddCircleLine className="h-4 w-4" aria-hidden />
74+
</span>
75+
76+
<SelectPrimitive.ItemText>Create Company</SelectPrimitive.ItemText>
77+
</SelectPrimitive.Item>
5578
</SelectContent>
5679
</Select>
5780
);

src/components/onboarding/company.tsx

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,13 @@ import type { User } from "next-auth";
3838

3939
type OnboardingCompanyProps = {
4040
currentUser: User;
41+
formType?: "onboarding" | "create-company";
4142
};
4243

43-
const OnboardingCompany = ({ currentUser }: OnboardingCompanyProps) => {
44+
const OnboardingCompany = ({
45+
currentUser,
46+
formType = "onboarding",
47+
}: OnboardingCompanyProps) => {
4448
const { update } = useSession();
4549
const router = useRouter();
4650

@@ -100,35 +104,37 @@ const OnboardingCompany = ({ currentUser }: OnboardingCompanyProps) => {
100104
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8">
101105
<div className="grid gap-2">
102106
<div className="grid gap-5">
103-
<div className="grid grid-cols-2 gap-4">
104-
<FormField
105-
control={form.control}
106-
name="user.name"
107-
render={({ field }) => (
108-
<FormItem>
109-
<FormLabel>Your full name</FormLabel>
110-
<FormControl>
111-
<Input {...field} />
112-
</FormControl>
113-
<FormMessage />
114-
</FormItem>
115-
)}
116-
/>
107+
{formType === "onboarding" && (
108+
<div className="grid grid-cols-2 gap-4">
109+
<FormField
110+
control={form.control}
111+
name="user.name"
112+
render={({ field }) => (
113+
<FormItem>
114+
<FormLabel>Your full name</FormLabel>
115+
<FormControl>
116+
<Input {...field} />
117+
</FormControl>
118+
<FormMessage />
119+
</FormItem>
120+
)}
121+
/>
117122

118-
<FormField
119-
control={form.control}
120-
name="user.email"
121-
render={({ field }) => (
122-
<FormItem>
123-
<FormLabel>Your work email</FormLabel>
124-
<FormControl>
125-
<Input type="email" {...field} />
126-
</FormControl>
127-
<FormMessage />
128-
</FormItem>
129-
)}
130-
/>
131-
</div>
123+
<FormField
124+
control={form.control}
125+
name="user.email"
126+
render={({ field }) => (
127+
<FormItem>
128+
<FormLabel>Your work email</FormLabel>
129+
<FormControl>
130+
<Input type="email" {...field} />
131+
</FormControl>
132+
<FormMessage />
133+
</FormItem>
134+
)}
135+
/>
136+
</div>
137+
)}
132138

133139
<div className="grid grid-cols-2 gap-4">
134140
<FormField

src/components/ui/select.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,16 @@ const SelectLabel = React.forwardRef<
115115
));
116116
SelectLabel.displayName = SelectPrimitive.Label.displayName;
117117

118+
export const SelectItemStyle =
119+
"relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50";
120+
118121
const SelectItem = React.forwardRef<
119122
React.ElementRef<typeof SelectPrimitive.Item>,
120123
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item>
121124
>(({ className, children, ...props }, ref) => (
122125
<SelectPrimitive.Item
123126
ref={ref}
124-
className={cn(
125-
"relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
126-
className,
127-
)}
127+
className={cn(SelectItemStyle, className)}
128128
{...props}
129129
>
130130
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">

0 commit comments

Comments
 (0)