Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useFilters } from "../../../../hooks/use-filters";
export const DeploymentListSearch = () => {
const { filters, updateFilters } = useFilters();

const queryLLMForStructuredOutput = trpc.deployment.search.useMutation({
const queryLLMForStructuredOutput = trpc.deploy.deployment.search.useMutation({
onSuccess(data) {
if (data?.filters.length === 0 || !data) {
toast.error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function useDeploymentLogs({
const scrollRef = useRef<HTMLDivElement>(null);

// Fetch logs via tRPC
const { data: logsData, isLoading } = trpc.deployment.buildLogs.useQuery({
const { data: logsData, isLoading } = trpc.deploy.deployment.buildLogs.useQuery({
deploymentId,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type UseEnvVarsManagerProps = {
};

export function useEnvVarsManager({ projectId, environment }: UseEnvVarsManagerProps) {
const { data } = trpc.environmentVariables.list.useQuery({ projectId });
const { data } = trpc.deploy.environment.list_dummy.useQuery({ projectId });

const envVars = data?.[environment] ?? [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function DiffPage({ params }: Props) {
data: diffData,
isLoading: diffLoading,
error: diffError,
} = trpc.deployment.getOpenApiDiff.useQuery(
} = trpc.deploy.deployment.getOpenApiDiff.useQuery(
{
oldDeploymentId: selectedFromDeployment,
newDeploymentId: selectedToDeployment,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
"use client";

import { NavbarActionButton } from "@/components/navigation/action-button";
import { Navbar } from "@/components/navigation/navbar";
import { collection } from "@/lib/collections";
import {
type CreateProjectRequestSchema,
createProjectRequestSchema,
} from "@/lib/collections/projects";
import { zodResolver } from "@hookform/resolvers/zod";
import { DuplicateKeyError } from "@tanstack/react-db";
import { Plus } from "@unkey/icons";
import { Button, DialogContainer, FormInput, toast } from "@unkey/ui";
import { Button, DialogContainer, FormInput } from "@unkey/ui";
import { useState } from "react";
import { useForm } from "react-hook-form";
import type { z } from "zod";
import { createProjectSchema } from "./create-project.schema";
import { useCreateProject } from "./use-create-project";

type FormValues = z.infer<typeof createProjectSchema>;

export const CreateProjectDialog = () => {
const [isModalOpen, setIsModalOpen] = useState(false);
Expand All @@ -20,34 +20,43 @@ export const CreateProjectDialog = () => {
register,
handleSubmit,
setValue,
setError,
reset,
formState: { errors, isSubmitting },
} = useForm<FormValues>({
resolver: zodResolver(createProjectSchema),
formState: { errors, isSubmitting, isValid },
} = useForm<CreateProjectRequestSchema>({
resolver: zodResolver(createProjectRequestSchema),
defaultValues: {
name: "",
slug: "",
gitRepositoryUrl: "",
},
mode: "onChange",
});

const createProject = useCreateProject((data) => {
toast.success("Project has been created", {
description: `${data.name} is ready to use`,
});
reset();
setIsModalOpen(false);
});

const onSubmitForm = async (values: FormValues) => {
const onSubmitForm = async (values: CreateProjectRequestSchema) => {
try {
await createProject.mutateAsync({
const tx = collection.projects.insert({
name: values.name,
slug: values.slug,
gitRepositoryUrl: values.gitRepositoryUrl ?? null,
gitRepositoryUrl: values.gitRepositoryUrl || null,
activeDeploymentId: null,
updatedAt: null,
id: "will-be-replace-by-server",
});
await tx.isPersisted.promise;

Comment thread
ogzhanolguncu marked this conversation as resolved.
reset();
setIsModalOpen(false);
} catch (error) {
console.error("Form submission error:", error);
if (error instanceof DuplicateKeyError) {
setError("slug", {
type: "custom",
message: "Project with this slug already exists",
});
} else {
console.error("Form submission error:", error);
// The collection's onInsert will handle showing error toasts
}
}
};

Expand All @@ -59,7 +68,6 @@ export const CreateProjectDialog = () => {
.replace(/\s+/g, "-")
.replace(/-+/g, "-")
.replace(/^-|-$/g, "");

setValue("slug", slug);
};

Expand Down Expand Up @@ -91,8 +99,8 @@ export const CreateProjectDialog = () => {
form="project-form"
variant="primary"
size="xlg"
disabled={isSubmitting || createProject.isLoading}
loading={isSubmitting || createProject.isLoading}
disabled={isSubmitting || !isValid}
loading={isSubmitting}
className="w-full rounded-lg"
>
Create Project
Expand All @@ -119,6 +127,7 @@ export const CreateProjectDialog = () => {
})}
placeholder="My Awesome Project"
/>

<FormInput
required
label="Slug"
Expand All @@ -128,6 +137,7 @@ export const CreateProjectDialog = () => {
{...register("slug")}
placeholder="my-awesome-project"
/>

<FormInput
label="Git Repository URL"
className="[&_input:first-of-type]:h-[36px]"
Expand Down

This file was deleted.

This file was deleted.

14 changes: 11 additions & 3 deletions apps/dashboard/app/(app)/projects/_components/list/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import { collection } from "@/lib/collections";
Comment thread
ogzhanolguncu marked this conversation as resolved.
Outdated
import { useLiveQuery } from "@tanstack/react-db";
import { ilike, useLiveQuery } from "@tanstack/react-db";
import { BookBookmark, Dots } from "@unkey/icons";
import { Button, Empty } from "@unkey/ui";
import { useProjectsFilters } from "../hooks/use-projects-filters";
import { ProjectActions } from "./project-actions";
import { ProjectCard } from "./projects-card";
import { ProjectCardSkeleton } from "./projects-card-skeleton";

const MAX_SKELETON_COUNT = 8;

export const ProjectsList = () => {
const projects = useLiveQuery((q) =>
q.from({ project: collection.projects }).orderBy(({ project }) => project.updatedAt, "desc"),
const { filters } = useProjectsFilters();
const projectName = filters.find((f) => f.field === "query")?.value ?? "";
const projects = useLiveQuery(
(q) =>
q
.from({ project: collection.projects })
.orderBy(({ project }) => project.updatedAt, "desc")
.where(({ project }) => ilike(project.name, `%${projectName}%`)),
[projectName],
);

if (projects.isLoading) {
Expand Down
7 changes: 1 addition & 6 deletions apps/dashboard/components/list-search-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ type Props<T extends BaseFilter = BaseFilter> = {
};

const MAX_QUERY_LENGTH = 120;
const DEFAULT_DEBOUNCE = 300;
const DEFAULT_PLACEHOLDER = "Search...";

export const ListSearchInput = <T extends BaseFilter = BaseFilter>({
useFiltersHook,
placeholder = DEFAULT_PLACEHOLDER,
debounceTime = DEFAULT_DEBOUNCE,
className,
}: Props<T>) => {
const { filters, updateFilters } = useFiltersHook();
Expand Down Expand Up @@ -98,10 +96,7 @@ export const ListSearchInput = <T extends BaseFilter = BaseFilter>({
clearTimeout(debounceRef.current);
}

// Set new debounce
debounceRef.current = setTimeout(() => {
updateQuery(value);
}, debounceTime);
updateQuery(value);
};

const handleClear = () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/lib/collections/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const deployments = createCollection<Deployment>(
queryClient,
queryKey: ["deployments"],
retry: 3,
queryFn: () => trpcClient.deployment.list.query(),
queryFn: () => trpcClient.deploy.deployment.list.query(),

getKey: (item) => item.id,
onInsert: async () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/lib/collections/domains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const domains = createCollection<Domain>(
queryClient,
queryKey: ["domains"],
retry: 3,
queryFn: () => trpcClient.domain.list.query(),
queryFn: () => trpcClient.deploy.domain.list.query(),

getKey: (item) => item.id,
onInsert: async () => {
Expand Down
3 changes: 1 addition & 2 deletions apps/dashboard/lib/collections/environments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ export const environments = createCollection<Environment>(
queryClient,
queryKey: ["environments"],
retry: 3,
queryFn: () => trpcClient.environment.list.query(),

queryFn: () => trpcClient.deploy.environment.list.query(),
Comment thread
ogzhanolguncu marked this conversation as resolved.
Outdated
getKey: (item) => item.id,
onInsert: async () => {
throw new Error("Not implemented");
Expand Down
Loading