-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Move createFolder action to effect rpc #893
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,12 +7,16 @@ import { | |||||||||||||||||||||||||||||||||||||||||||||
| DialogTitle, | ||||||||||||||||||||||||||||||||||||||||||||||
| Input, | ||||||||||||||||||||||||||||||||||||||||||||||
| } from "@cap/ui"; | ||||||||||||||||||||||||||||||||||||||||||||||
| import type { Folder } from "@cap/web-domain"; | ||||||||||||||||||||||||||||||||||||||||||||||
| import { faFolderPlus } from "@fortawesome/free-solid-svg-icons"; | ||||||||||||||||||||||||||||||||||||||||||||||
| import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||||||||||||||||||||||||||||||||||||||||||||||
| import clsx from "clsx"; | ||||||||||||||||||||||||||||||||||||||||||||||
| import { Option } from "effect"; | ||||||||||||||||||||||||||||||||||||||||||||||
| import { useRouter } from "next/navigation"; | ||||||||||||||||||||||||||||||||||||||||||||||
| import React, { useEffect, useRef, useState } from "react"; | ||||||||||||||||||||||||||||||||||||||||||||||
| import { toast } from "sonner"; | ||||||||||||||||||||||||||||||||||||||||||||||
| import { createFolder } from "@/actions/folders/createFolder"; | ||||||||||||||||||||||||||||||||||||||||||||||
| import { useEffectMutation } from "@/lib/EffectRuntime"; | ||||||||||||||||||||||||||||||||||||||||||||||
| import { withRpc } from "@/lib/Rpcs"; | ||||||||||||||||||||||||||||||||||||||||||||||
| import { BlueFolder, NormalFolder, RedFolder, YellowFolder } from "./Folders"; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| interface Props { | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -54,31 +58,33 @@ export const NewFolderDialog: React.FC<Props> = ({ | |||||||||||||||||||||||||||||||||||||||||||||
| >(null); | ||||||||||||||||||||||||||||||||||||||||||||||
| const [folderName, setFolderName] = useState<string>(""); | ||||||||||||||||||||||||||||||||||||||||||||||
| const folderRefs = useRef<Record<string, any>>({}); | ||||||||||||||||||||||||||||||||||||||||||||||
| const [loading, setLoading] = useState<boolean>(false); | ||||||||||||||||||||||||||||||||||||||||||||||
| const router = useRouter(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (!open) setSelectedColor(null); | ||||||||||||||||||||||||||||||||||||||||||||||
| }, [open]); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const createFolderHandler = async () => { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (!selectedColor) return; | ||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||
| setLoading(true); | ||||||||||||||||||||||||||||||||||||||||||||||
| await createFolder({ | ||||||||||||||||||||||||||||||||||||||||||||||
| name: folderName, | ||||||||||||||||||||||||||||||||||||||||||||||
| color: selectedColor, | ||||||||||||||||||||||||||||||||||||||||||||||
| spaceId, | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
| const createFolder = useEffectMutation({ | ||||||||||||||||||||||||||||||||||||||||||||||
| mutationFn: (data: { name: string; color: Folder.FolderColor }) => | ||||||||||||||||||||||||||||||||||||||||||||||
| withRpc((r) => | ||||||||||||||||||||||||||||||||||||||||||||||
| r.FolderCreate({ | ||||||||||||||||||||||||||||||||||||||||||||||
| name: data.name, | ||||||||||||||||||||||||||||||||||||||||||||||
| color: data.color, | ||||||||||||||||||||||||||||||||||||||||||||||
| spaceId: Option.fromNullable(spaceId), | ||||||||||||||||||||||||||||||||||||||||||||||
| parentId: Option.none(), | ||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+68
to
+76
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Align the mutation payload type with the corrected import Update the payload type to reference Apply this diff: - mutationFn: (data: { name: string; color: Folder.FolderColor }) =>
+ mutationFn: (data: { name: string; color: FolderColor }) =>📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
| onSuccess: () => { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+67
to
+77
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Align mutation payload type with FolderColor and trim the name Use FolderColor for the color type and send a trimmed name to avoid leading/trailing spaces. Apply this diff: - const createFolder = useEffectMutation({
- mutationFn: (data: { name: string; color: Folder.FolderColor }) =>
+ const createFolder = useEffectMutation({
+ mutationFn: (data: { name: string; color: FolderColor }) =>
withRpc((r) =>
r.FolderCreate({
- name: data.name,
+ name: data.name.trim(),
color: data.color,
spaceId: Option.fromNullable(spaceId),
parentId: Option.none(),
}),
),📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
| setFolderName(""); | ||||||||||||||||||||||||||||||||||||||||||||||
| setSelectedColor(null); | ||||||||||||||||||||||||||||||||||||||||||||||
| onOpenChange(false); | ||||||||||||||||||||||||||||||||||||||||||||||
| router.refresh(); | ||||||||||||||||||||||||||||||||||||||||||||||
| toast.success("Folder created successfully"); | ||||||||||||||||||||||||||||||||||||||||||||||
| } catch (error: any) { | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| onError: () => { | ||||||||||||||||||||||||||||||||||||||||||||||
| toast.error("Failed to create folder"); | ||||||||||||||||||||||||||||||||||||||||||||||
| } finally { | ||||||||||||||||||||||||||||||||||||||||||||||
| setLoading(false); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||
| <Dialog open={open} onOpenChange={onOpenChange}> | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -141,13 +147,20 @@ export const NewFolderDialog: React.FC<Props> = ({ | |||||||||||||||||||||||||||||||||||||||||||||
| Cancel | ||||||||||||||||||||||||||||||||||||||||||||||
| </Button> | ||||||||||||||||||||||||||||||||||||||||||||||
| <Button | ||||||||||||||||||||||||||||||||||||||||||||||
| onClick={createFolderHandler} | ||||||||||||||||||||||||||||||||||||||||||||||
| onClick={() => { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (selectedColor === null) return; | ||||||||||||||||||||||||||||||||||||||||||||||
| createFolder.mutate({ name: folderName, color: selectedColor }); | ||||||||||||||||||||||||||||||||||||||||||||||
| }} | ||||||||||||||||||||||||||||||||||||||||||||||
| size="sm" | ||||||||||||||||||||||||||||||||||||||||||||||
| spinner={loading} | ||||||||||||||||||||||||||||||||||||||||||||||
| spinner={createFolder.isPending} | ||||||||||||||||||||||||||||||||||||||||||||||
| variant="dark" | ||||||||||||||||||||||||||||||||||||||||||||||
| disabled={!selectedColor || !folderName.trim().length || loading} | ||||||||||||||||||||||||||||||||||||||||||||||
| disabled={ | ||||||||||||||||||||||||||||||||||||||||||||||
| !selectedColor || | ||||||||||||||||||||||||||||||||||||||||||||||
| !folderName.trim().length || | ||||||||||||||||||||||||||||||||||||||||||||||
| createFolder.isPending | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||
| {loading ? "Creating..." : "Create"} | ||||||||||||||||||||||||||||||||||||||||||||||
| {createFolder.isPending ? "Creating..." : "Create"} | ||||||||||||||||||||||||||||||||||||||||||||||
| </Button> | ||||||||||||||||||||||||||||||||||||||||||||||
| </DialogFooter> | ||||||||||||||||||||||||||||||||||||||||||||||
| </DialogContent> | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix type import:
Folder.FolderColoris not a named type importUsing
Folder.FolderColorwithimport type { Folder }is likely a type error. Import the color type directly and use it in the mutation payload.Apply this diff:
📝 Committable suggestion
🤖 Prompt for AI Agents