-
Notifications
You must be signed in to change notification settings - Fork 609
feat: new projects UI #3734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: new projects UI #3734
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
7d991b2
feat: init new projects view
ogzhanolguncu 1f3f1c8
fix: typo
ogzhanolguncu 9666438
feat: add dummy controls
ogzhanolguncu f279a56
feat: add parts of card
ogzhanolguncu e15cffb
refactor: organize
ogzhanolguncu c531912
refactor: gradient
ogzhanolguncu 2322c0b
refactor: finalize gradient
ogzhanolguncu 3b1b1d3
feat: add tRPC back
ogzhanolguncu 04f2370
feat: add missing load more and skeleton
ogzhanolguncu 8256fd9
fix: skeleton and layout
ogzhanolguncu b831ac2
feat: add search
ogzhanolguncu c998843
fix: add missing empty state
ogzhanolguncu d3a061f
feat: add create project dialog
ogzhanolguncu 74fcb95
feat: add actinos
ogzhanolguncu 2aa3a02
fix: action skeleton
ogzhanolguncu 13aac18
chore: add back flag check
ogzhanolguncu 60ec968
refactor: create hook
ogzhanolguncu 8b9eb98
chore: remove redundant log
ogzhanolguncu 3f7632f
Merge branch 'main' into new-projects-ui
ogzhanolguncu 2250bfb
fix: coderabbit issues
ogzhanolguncu 2dae742
refactor: redundant check
ogzhanolguncu c306874
Merge branch 'main' into new-projects-ui
ogzhanolguncu b0e0fae
fix: add redirection to deployments
ogzhanolguncu 293a40e
fix: comments
ogzhanolguncu c53da4f
chore: revert change
ogzhanolguncu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
184 changes: 184 additions & 0 deletions
184
...shboard/app/(app)/projects/_components/controls/components/projects-list-search/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,184 @@ | ||
| import { Button } from "@unkey/ui"; | ||
| import { cn } from "@unkey/ui/src/lib/utils"; | ||
| import { Search, X } from "lucide-react"; | ||
| import { useEffect, useRef, useState } from "react"; | ||
| import { useProjectsFilters } from "../../../hooks/use-projects-filters"; | ||
|
|
||
| type Props = { | ||
| placeholder?: string; | ||
| debounceTime?: number; | ||
| className?: string; | ||
| }; | ||
|
|
||
| const MAX_QUERY_LENGTH = 120; | ||
| const DEFAULT_DEBOUNCE = 300; | ||
| const DEFAULT_PLACEHOLDER = "Search projects..."; | ||
|
|
||
| export const ProjectsSearchInput = ({ | ||
| placeholder = DEFAULT_PLACEHOLDER, | ||
| debounceTime = DEFAULT_DEBOUNCE, | ||
| className, | ||
| }: Props) => { | ||
| const { filters, updateFilters } = useProjectsFilters(); | ||
| const [searchText, setSearchText] = useState(""); | ||
| const [isInitialized, setIsInitialized] = useState(false); | ||
| const debounceRef = useRef<NodeJS.Timeout>(); | ||
| const inputRef = useRef<HTMLInputElement>(null); | ||
| const previousFilterValueRef = useRef<string>(""); | ||
|
|
||
| // Get current query filter value from URL on mount and when filters change | ||
| useEffect(() => { | ||
| const queryFilter = filters.find((f) => f.field === "query"); | ||
| const currentValue = typeof queryFilter?.value === "string" ? queryFilter.value : ""; | ||
|
|
||
| // Only update if the filter value actually changed (not from our own input) | ||
| if (currentValue !== previousFilterValueRef.current) { | ||
| previousFilterValueRef.current = currentValue; | ||
| setSearchText(currentValue); | ||
| } | ||
|
|
||
| // Mark as initialized after first effect run | ||
| if (!isInitialized) { | ||
| setIsInitialized(true); | ||
| } | ||
| }, [filters, isInitialized]); | ||
|
|
||
| // Cleanup debounce on unmount | ||
| useEffect(() => { | ||
| return () => { | ||
| if (debounceRef.current) { | ||
| clearTimeout(debounceRef.current); | ||
| } | ||
| }; | ||
| }, []); | ||
|
|
||
| const updateQuery = (value: string) => { | ||
| // Remove existing filters for query field | ||
| const filtersWithoutCurrent = filters.filter((f) => f.field !== "query"); | ||
|
|
||
| if (value.trim()) { | ||
| // Add new filter | ||
| updateFilters([ | ||
| ...filtersWithoutCurrent, | ||
| { | ||
| field: "query", | ||
| id: crypto.randomUUID(), | ||
| operator: "contains", | ||
| value: value.trim(), | ||
| }, | ||
| ]); | ||
| } else { | ||
| // Just remove query filters if empty | ||
| updateFilters(filtersWithoutCurrent); | ||
| } | ||
| }; | ||
|
|
||
| const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
| const value = e.target.value; | ||
| setSearchText(value); | ||
|
|
||
| // Clear existing debounce | ||
| if (debounceRef.current) { | ||
| clearTimeout(debounceRef.current); | ||
| } | ||
|
|
||
| // Set new debounce | ||
| debounceRef.current = setTimeout(() => { | ||
| updateQuery(value); | ||
| }, debounceTime); | ||
| }; | ||
|
|
||
| const handleClear = () => { | ||
| setSearchText(""); | ||
|
|
||
| // Clear debounce | ||
| if (debounceRef.current) { | ||
| clearTimeout(debounceRef.current); | ||
| } | ||
|
|
||
| // Immediately update filters | ||
| updateQuery(""); | ||
| }; | ||
|
|
||
| const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => { | ||
| if (e.key === "Escape") { | ||
| handleClear(); | ||
| inputRef.current?.blur(); | ||
| } | ||
|
|
||
| if (e.key === "Enter") { | ||
| // Clear debounce and immediately update | ||
| if (debounceRef.current) { | ||
| clearTimeout(debounceRef.current); | ||
| } | ||
| updateQuery(searchText); | ||
| } | ||
| }; | ||
|
|
||
| // Show loading state while initializing | ||
| if (!isInitialized) { | ||
| return ( | ||
| <div className={cn("relative flex-1", className)}> | ||
| <div | ||
| className={cn( | ||
| "px-2 flex items-center flex-1 md:w-80 gap-2 border rounded-lg py-1 h-8 border-none cursor-pointer", | ||
| "bg-gray-3 opacity-50", | ||
| )} | ||
| > | ||
| <div className="flex items-center gap-2 w-full flex-1 md:w-80"> | ||
| <div className="flex-shrink-0"> | ||
| <Search className="text-accent-9 size-4" /> | ||
| </div> | ||
| <div className="flex-1"> | ||
| <div className="text-accent-11 text-[13px] animate-pulse">Loading...</div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <div className={cn("relative flex-1", className)}> | ||
| <div | ||
| className={cn( | ||
| "px-2 flex items-center flex-1 md:w-80 gap-2 border rounded-lg py-1 h-8 border-none cursor-pointer hover:bg-gray-3", | ||
| "focus-within:bg-gray-4", | ||
| "transition-all duration-200", | ||
| searchText.length > 0 ? "bg-gray-4" : "", | ||
| )} | ||
| > | ||
| <div className="flex items-center gap-2 w-full flex-1 md:w-80"> | ||
| <div className="flex-shrink-0"> | ||
| <Search className="text-accent-9 size-4" /> | ||
| </div> | ||
|
|
||
| <div className="flex-1"> | ||
| <input | ||
| ref={inputRef} | ||
| type="text" | ||
| value={searchText} | ||
| onChange={handleInputChange} | ||
| onKeyDown={handleKeyDown} | ||
| maxLength={MAX_QUERY_LENGTH} | ||
| placeholder={placeholder} | ||
| className="truncate text-accent-12 font-medium text-[13px] bg-transparent border-none outline-none focus:ring-0 focus:outline-none placeholder:text-accent-12 selection:bg-gray-6 w-full" | ||
| /> | ||
| </div> | ||
| </div> | ||
|
|
||
| {searchText && ( | ||
| <Button | ||
| variant="ghost" | ||
| onClick={handleClear} | ||
| className="text-accent-9 hover:text-accent-12 rounded transition-colors flex-shrink-0" | ||
| size="icon" | ||
| aria-label="Clear search" | ||
| > | ||
| <X className="!size-3" /> | ||
| </Button> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
12 changes: 12 additions & 0 deletions
12
apps/dashboard/app/(app)/projects/_components/controls/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { ControlsContainer, ControlsLeft } from "@/components/logs/controls-container"; | ||
| import { ProjectsSearchInput } from "./components/projects-list-search"; | ||
|
|
||
| export function ProjectsListControls() { | ||
| return ( | ||
| <ControlsContainer> | ||
| <ControlsLeft> | ||
| <ProjectsSearchInput /> | ||
| </ControlsLeft> | ||
| </ControlsContainer> | ||
| ); | ||
| } |
143 changes: 143 additions & 0 deletions
143
apps/dashboard/app/(app)/projects/_components/create-project/create-project-dialog.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| "use client"; | ||
|
|
||
| import { NavbarActionButton } from "@/components/navigation/action-button"; | ||
| import { Navbar } from "@/components/navigation/navbar"; | ||
| import { zodResolver } from "@hookform/resolvers/zod"; | ||
| import { Plus } from "@unkey/icons"; | ||
| import { Button, DialogContainer, FormInput, toast } 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); | ||
|
|
||
| const { | ||
| register, | ||
| handleSubmit, | ||
| setValue, | ||
| reset, | ||
| formState: { errors, isSubmitting }, | ||
| } = useForm<FormValues>({ | ||
| resolver: zodResolver(createProjectSchema), | ||
| defaultValues: { | ||
| name: "", | ||
| slug: "", | ||
| gitRepositoryUrl: "", | ||
| }, | ||
| }); | ||
|
|
||
| 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) => { | ||
| try { | ||
| await createProject.mutateAsync({ | ||
| name: values.name, | ||
| slug: values.slug, | ||
| gitRepositoryUrl: values.gitRepositoryUrl || undefined, | ||
| }); | ||
| } catch (error) { | ||
| console.error("Form submission error:", error); | ||
| } | ||
| }; | ||
ogzhanolguncu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const handleNameChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
| const name = e.target.value; | ||
| const slug = name | ||
| .toLowerCase() | ||
| .replace(/[^a-z0-9\s-]/g, "") | ||
| .replace(/\s+/g, "-") | ||
| .replace(/-+/g, "-") | ||
| .replace(/^-|-$/g, ""); | ||
|
|
||
| setValue("slug", slug); | ||
| }; | ||
|
|
||
| const handleModalClose = (open: boolean) => { | ||
| if (!open) { | ||
| reset(); | ||
| } | ||
| setIsModalOpen(open); | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
| <Navbar.Actions> | ||
| <NavbarActionButton title="Create new project" onClick={() => setIsModalOpen(true)}> | ||
| <Plus /> | ||
| Create new project | ||
| </NavbarActionButton> | ||
| </Navbar.Actions> | ||
|
|
||
| <DialogContainer | ||
| isOpen={isModalOpen} | ||
| onOpenChange={handleModalClose} | ||
| title="Create New Project" | ||
| subTitle="Set up a new project with a unique name and optional Git repository" | ||
| footer={ | ||
| <div className="flex flex-col items-center justify-center w-full gap-2"> | ||
| <Button | ||
| type="submit" | ||
| form="project-form" | ||
| variant="primary" | ||
| size="xlg" | ||
| disabled={isSubmitting || createProject.isLoading} | ||
| loading={isSubmitting || createProject.isLoading} | ||
| className="w-full rounded-lg" | ||
| > | ||
| Create Project | ||
| </Button> | ||
| <div className="text-xs text-gray-9"> | ||
| Project will be available immediately after creation | ||
| </div> | ||
| </div> | ||
| } | ||
| > | ||
| <form | ||
| id="project-form" | ||
| onSubmit={handleSubmit(onSubmitForm)} | ||
| className="flex flex-col gap-4" | ||
| > | ||
| <FormInput | ||
| required | ||
| label="Project Name" | ||
| className="[&_input:first-of-type]:h-[36px]" | ||
| description="A descriptive name for your project." | ||
| error={errors.name?.message} | ||
| {...register("name", { | ||
| onChange: handleNameChange, | ||
| })} | ||
| placeholder="My Awesome Project" | ||
| /> | ||
| <FormInput | ||
| required | ||
| label="Slug" | ||
| className="[&_input:first-of-type]:h-[36px]" | ||
| description="URL-friendly identifier for your project (auto-generated from name)." | ||
| error={errors.slug?.message} | ||
| {...register("slug")} | ||
| placeholder="my-awesome-project" | ||
| /> | ||
| <FormInput | ||
| label="Git Repository URL" | ||
| className="[&_input:first-of-type]:h-[36px]" | ||
| description="Optional: Link to your project's Git repository." | ||
| error={errors.gitRepositoryUrl?.message} | ||
| {...register("gitRepositoryUrl")} | ||
| placeholder="https://github.com/username/repo" | ||
| /> | ||
| </form> | ||
| </DialogContainer> | ||
| </> | ||
| ); | ||
| }; | ||
15 changes: 15 additions & 0 deletions
15
apps/dashboard/app/(app)/projects/_components/create-project/create-project.schema.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { z } from "zod"; | ||
|
|
||
| export const createProjectSchema = z.object({ | ||
| name: z.string().trim().min(1, "Project name is required").max(256, "Project name too long"), | ||
| slug: z | ||
| .string() | ||
| .trim() | ||
| .min(1, "Project slug is required") | ||
| .max(256, "Project slug too long") | ||
| .regex( | ||
| /^[a-z0-9-]+$/, | ||
| "Project slug must contain only lowercase letters, numbers, and hyphens", | ||
| ), | ||
| gitRepositoryUrl: z.string().trim().url("Must be a valid URL").optional().or(z.literal("")), | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.