Skip to content

Commit 352b3ec

Browse files
fixes : team id usage on form
1 parent 918cdb5 commit 352b3ec

File tree

3 files changed

+41
-17
lines changed
  • src
    • app/(dynamic-pages)/(authenticated-pages)/(application-pages)/org/[organizationId]
      • (specific-organization-pages)/projects/create
      • team/[teamId]/(specific-team-pages)
    • components

3 files changed

+41
-17
lines changed

src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/org/[organizationId]/(specific-organization-pages)/projects/create/page.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ export const metadata: Metadata = {
1111

1212
export default async function CreateProjectPage({
1313
params,
14+
searchParams,
1415
}: {
1516
params: unknown;
17+
searchParams: { [key: string]: string | string[] | undefined };
18+
1619
}) {
1720
const { organizationId } = organizationParamSchema.parse(params);
21+
const teamId = searchParams.teamId ? Number(searchParams.teamId) : undefined;
22+
1823
const [repositories, fullTeams] = await Promise.all([
1924
getOrganizationRepos(organizationId),
2025
getTeamsInOrganization(organizationId)
@@ -24,7 +29,7 @@ export default async function CreateProjectPage({
2429

2530
return (
2631
<div className="w-full mt-1">
27-
<CreateProjectForm organizationId={organizationId} repositories={repositories} teams={teams} />
32+
<CreateProjectForm organizationId={organizationId} repositories={repositories} teams={teams} teamId={teamId} />
2833
</div>
2934
);
3035
}

src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/org/[organizationId]/team/[teamId]/(specific-team-pages)/page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default async function TeamPage({
5353
)}
5454
</div>
5555
<div className="flex space-x-4">
56-
<Link href={`/org/${organizationId}/projects/create`}>
56+
<Link href={`/org/${organizationId}/projects/create?teamId=${teamId}`}>
5757
<Button variant="default" size="sm">
5858
<Plus className="mr-2 h-4 w-4" />
5959
Create Project

src/components/CreateProjectForm.tsx

+34-15
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import { Button } from "@/components/ui/button";
44
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
55
import { Input } from "@/components/ui/input";
66
import { Label } from "@/components/ui/label";
7-
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
7+
import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectSeparator, SelectTrigger, SelectValue } from "@/components/ui/select";
88
import { createProjectAction } from "@/data/user/projects";
99
import { useSAToastMutation } from "@/hooks/useSAToastMutation";
1010
import { generateSlug } from "@/lib/utils";
1111
import { zodResolver } from "@hookform/resolvers/zod";
1212
import { GitHubLogoIcon } from "@radix-ui/react-icons";
1313
import { motion } from "framer-motion";
14-
import { AlertCircle, Github, Users } from "lucide-react";
14+
import { AlertCircle, Briefcase, Github, Users } from "lucide-react";
1515
import Link from "next/link";
1616
import { useRouter } from "next/navigation";
1717
import { FormEvent, useState } from 'react';
@@ -48,20 +48,21 @@ type CreateProjectFormProps = {
4848
organizationId: string;
4949
repositories: Repository[];
5050
teams: Team[];
51+
teamId: number | undefined;
5152
};
5253

53-
export default function CreateProjectForm({ organizationId, repositories, teams }: CreateProjectFormProps) {
54+
export default function CreateProjectForm({ organizationId, repositories, teams, teamId }: CreateProjectFormProps) {
5455
const router = useRouter();
5556

56-
const { control, handleSubmit, formState: { errors } } = useForm<CreateProjectFormData>({
57+
const { control, handleSubmit, watch, setValue, formState: { errors } } = useForm<CreateProjectFormData>({
5758
resolver: zodResolver(createProjectFormSchema),
5859
defaultValues: {
5960
name: "",
6061
repository: repositories[0]?.id || 0,
6162
terraformDir: "",
6263
managedState: true,
6364
labels: [],
64-
teamId: teams[0]?.id || null,
65+
teamId: teamId || null,
6566
},
6667
});
6768

@@ -236,7 +237,7 @@ export default function CreateProjectForm({ organizationId, repositories, teams
236237
>
237238
<CardHeader className="flex flex-col space-y-0">
238239
<CardTitle className="text-lg mb-0">Select a Team</CardTitle>
239-
<CardDescription className="text-sm text-muted-foreground mt-0">Choose the team for your project</CardDescription>
240+
<CardDescription className="text-sm text-muted-foreground mt-0">Choose the team for your project or create it at the organization level</CardDescription>
240241
</CardHeader>
241242
<CardContent>
242243

@@ -245,19 +246,37 @@ export default function CreateProjectForm({ organizationId, repositories, teams
245246
control={control}
246247
render={({ field }) => (
247248
<div className="relative">
248-
<Select onValueChange={(value) => field.onChange(parseInt(value))} value={field.value?.toString() || ""}>
249+
<Select onValueChange={(value) => {
250+
if (value === 'null') {
251+
field.onChange(null);
252+
} else {
253+
field.onChange(parseInt(value));
254+
}
255+
}} value={field.value?.toString() || "null"}
256+
257+
>
249258
<SelectTrigger className={`w-full ${errors.teamId ? 'border-destructive' : ''}`}>
250259
<SelectValue placeholder="Select a team" />
251260
</SelectTrigger>
252261
<SelectContent>
253-
{teams.map((team) => (
254-
<SelectItem key={team.id} value={team.id.toString()}>
255-
<div className="flex items-center">
256-
<Users className="mr-2 h-4 w-4" />
257-
<span>{team.name}</span>
258-
</div>
259-
</SelectItem>
260-
))}
262+
<SelectItem value="null">
263+
<div className="flex items-center">
264+
<Briefcase className="mr-2 h-4 w-4" />
265+
<span>Create at organization level</span>
266+
</div>
267+
</SelectItem>
268+
<SelectSeparator />
269+
<SelectGroup>
270+
<SelectLabel className='ml-0'>My teams</SelectLabel>
271+
{teams.map((team) => (
272+
<SelectItem key={team.id} value={team.id.toString()}>
273+
<div className="flex items-center">
274+
<Users className="mr-2 h-4 w-4" />
275+
<span>{team.name}</span>
276+
</div>
277+
</SelectItem>
278+
))}
279+
</SelectGroup>
261280
</SelectContent>
262281
</Select>
263282
{errors.teamId && (

0 commit comments

Comments
 (0)