Skip to content

Commit c3d294f

Browse files
feat/minor fix to create project form
1 parent b1309d1 commit c3d294f

File tree

3 files changed

+65
-38
lines changed
  • src

3 files changed

+65
-38
lines changed

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
21
import CreateProjectForm from "@/components/CreateProjectForm";
2+
import { getOrganizationRepos } from "@/data/user/repos";
33
import { organizationParamSchema } from "@/utils/zod-schemas/params";
44
import type { Metadata } from "next";
55

@@ -14,10 +14,11 @@ export default async function CreateProjectPage({
1414
params: unknown;
1515
}) {
1616
const { organizationId } = organizationParamSchema.parse(params);
17+
const repositories = await getOrganizationRepos(organizationId);
1718

1819
return (
1920
<div className="w-full mt-1">
20-
<CreateProjectForm organizationId={organizationId} />
21+
<CreateProjectForm organizationId={organizationId} repositories={repositories} />
2122
</div>
2223
);
2324
}

src/components/CreateProjectForm.tsx

+48-36
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,25 @@ const createProjectFormSchema = z.object({
3232

3333
type CreateProjectFormData = z.infer<typeof createProjectFormSchema>;
3434

35-
const repositories = [
36-
{ id: 12, name: 'Repository 1' },
37-
{ id: 123, name: 'Repository 2' },
38-
{ id: 41, name: 'Repository 3' },
39-
{ id: 24, name: 'Repository 4' },
40-
{ id: 124, name: 'Repository 5' },
41-
];
35+
type Repository = {
36+
id: number;
37+
name: string;
38+
};
4239

43-
export default function CreateProjectForm({ organizationId }: { organizationId: string }) {
44-
const [selectedRepo, setSelectedRepo] = useState(repositories[0].id);
40+
type CreateProjectFormProps = {
41+
organizationId: string;
42+
repositories: Repository[];
43+
};
44+
45+
export default function CreateProjectForm({ organizationId, repositories }: CreateProjectFormProps) {
46+
const [selectedRepo, setSelectedRepo] = useState(repositories[0]?.id || null);
4547
const router = useRouter();
4648

4749
const { control, handleSubmit, setValue, watch } = useForm<CreateProjectFormData>({
4850
resolver: zodResolver(createProjectFormSchema),
4951
defaultValues: {
5052
name: "",
51-
repository: repositories[0].id,
53+
repository: repositories[0]?.id || 0,
5254
terraformDir: "",
5355
managedState: true,
5456
labels: [],
@@ -84,8 +86,6 @@ export default function CreateProjectForm({ organizationId }: { organizationId:
8486
createProjectMutation.mutate(data);
8587
};
8688

87-
88-
8989
return (
9090
<div className="p-6 max-w-4xl mx-auto">
9191
<form onSubmit={(e) => {
@@ -159,31 +159,43 @@ export default function CreateProjectForm({ organizationId }: { organizationId:
159159
</Badge>
160160
</CardHeader>
161161
<CardContent>
162-
<ScrollArea className="w-full whitespace-nowrap rounded-md border">
163-
<div className="flex w-max space-x-4 p-4">
164-
{repositories.map((repo, index) => (
165-
<MotionCard
166-
key={repo.id}
167-
className={`w-[200px] cursor-pointer ${selectedRepo === repo.id ? 'ring-2 ring-primary' : ''}`}
168-
whileHover={{ scale: 1.05 }}
169-
whileTap={{ scale: 0.95 }}
170-
onClick={() => {
171-
setSelectedRepo(repo.id);
172-
setValue("repository", repo.id);
173-
}}
174-
initial={{ opacity: 0, y: 20 }}
175-
animate={{ opacity: 1, y: 0 }}
176-
transition={{ delay: index * 0.1 }}
177-
>
178-
<CardContent className="flex items-center justify-center p-6">
179-
<Github className="mr-2 h-6 w-6" />
180-
<span>{repo.name}</span>
181-
</CardContent>
182-
</MotionCard>
183-
))}
162+
{repositories.length > 0 ? (
163+
<ScrollArea className="w-full whitespace-nowrap rounded-md border">
164+
<div className="flex w-max space-x-4 p-4">
165+
{repositories.map((repo, index) => (
166+
<MotionCard
167+
key={repo.id}
168+
className={`w-[200px] cursor-pointer ${selectedRepo === repo.id ? 'ring-2 ring-primary' : ''}`}
169+
whileHover={{ scale: 1.05 }}
170+
whileTap={{ scale: 0.95 }}
171+
onClick={() => {
172+
setSelectedRepo(repo.id);
173+
setValue("repository", repo.id);
174+
}}
175+
initial={{ opacity: 0, y: 20 }}
176+
animate={{ opacity: 1, y: 0 }}
177+
transition={{ delay: index * 0.1 }}
178+
>
179+
<CardContent className="flex items-center justify-center p-6">
180+
<Github className="mr-2 h-6 w-6" />
181+
<span>{repo.name}</span>
182+
</CardContent>
183+
</MotionCard>
184+
))}
185+
</div>
186+
<ScrollBar orientation="horizontal" />
187+
</ScrollArea>
188+
) : (
189+
<div className="text-center py-8">
190+
<div className="bg-muted/50 rounded-full p-4 inline-block">
191+
<Github className="mx-auto size-8 text-muted-foreground" />
192+
</div>
193+
<T.H4 className="mb-1 mt-4">No Repositories Found</T.H4>
194+
<T.P className="text-muted-foreground mb-4">
195+
It looks like there are no repositories.
196+
</T.P>
184197
</div>
185-
<ScrollBar orientation="horizontal" />
186-
</ScrollArea>
198+
)}
187199
</CardContent>
188200
</MotionCard>
189201

src/data/user/repos.ts

+14
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,17 @@ export async function getRepoDetails(repoId: number) {
1616

1717
return data;
1818
}
19+
20+
export async function getOrganizationRepos(organizationId: string) {
21+
const supabaseClient = createSupabaseUserServerComponentClient();
22+
const { data, error } = await supabaseClient
23+
.from('repos')
24+
.select('id, name')
25+
.eq('organization_id', organizationId);
26+
27+
if (error) {
28+
throw error;
29+
}
30+
31+
return data;
32+
}

0 commit comments

Comments
 (0)