({
isOpen,
onClose,
onCreated,
}: {
isOpen: boolean
onClose: () => void
onCreated?: (containerTag: string) => void
})
| 83 | ] |
| 84 | |
| 85 | export function AddSpaceModal({ |
| 86 | isOpen, |
| 87 | onClose, |
| 88 | onCreated, |
| 89 | }: { |
| 90 | isOpen: boolean |
| 91 | onClose: () => void |
| 92 | onCreated?: (containerTag: string) => void |
| 93 | }) { |
| 94 | const [spaceName, setSpaceName] = useState("") |
| 95 | const [spaceContext, setSpaceContext] = useState("") |
| 96 | const [showContext, setShowContext] = useState(false) |
| 97 | const [emoji, setEmoji] = useState("📁") |
| 98 | const [isEmojiOpen, setIsEmojiOpen] = useState(false) |
| 99 | const { createProjectMutation } = useProjectMutations() |
| 100 | |
| 101 | const handleClose = () => { |
| 102 | onClose() |
| 103 | setSpaceName("") |
| 104 | setSpaceContext("") |
| 105 | setShowContext(false) |
| 106 | setEmoji("📁") |
| 107 | } |
| 108 | |
| 109 | const handleCreate = () => { |
| 110 | const trimmedName = spaceName.trim() |
| 111 | if (!trimmedName) return |
| 112 | |
| 113 | createProjectMutation.mutate( |
| 114 | { name: trimmedName, emoji: emoji || undefined }, |
| 115 | { |
| 116 | onSuccess: async (data) => { |
| 117 | analytics.spaceCreated() |
| 118 | const tag = data?.containerTag |
| 119 | const context = showContext ? spaceContext.trim() : "" |
| 120 | if (tag && context) { |
| 121 | try { |
| 122 | await $fetch(`@patch/container-tags/${tag}`, { |
| 123 | body: { entityContext: context }, |
| 124 | }) |
| 125 | } catch {} |
| 126 | } |
| 127 | if (tag) onCreated?.(tag) |
| 128 | handleClose() |
| 129 | }, |
| 130 | }, |
| 131 | ) |
| 132 | } |
| 133 | |
| 134 | const handleKeyDown = (e: React.KeyboardEvent) => { |
| 135 | if ( |
| 136 | e.key === "Enter" && |
| 137 | spaceName.trim() && |
| 138 | !createProjectMutation.isPending |
| 139 | ) { |
| 140 | e.preventDefault() |
| 141 | handleCreate() |
| 142 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…