()
| 156 | } |
| 157 | |
| 158 | export function useCreateFolder() { |
| 159 | const queryClient = useQueryClient() |
| 160 | |
| 161 | const handlers = createFolderMutationHandlers<CreateFolderVariables>( |
| 162 | queryClient, |
| 163 | 'CreateFolder', |
| 164 | (variables, tempId, previousFolders) => { |
| 165 | const currentWorkflows = Object.fromEntries( |
| 166 | getWorkflows(variables.workspaceId).map((w) => [w.id, w]) |
| 167 | ) |
| 168 | |
| 169 | return { |
| 170 | id: tempId, |
| 171 | name: variables.name, |
| 172 | userId: '', |
| 173 | workspaceId: variables.workspaceId, |
| 174 | parentId: variables.parentId || null, |
| 175 | color: variables.color || '#808080', |
| 176 | isExpanded: false, |
| 177 | locked: false, |
| 178 | sortOrder: |
| 179 | variables.sortOrder ?? |
| 180 | getTopInsertionSortOrder( |
| 181 | currentWorkflows, |
| 182 | previousFolders, |
| 183 | variables.workspaceId, |
| 184 | variables.parentId |
| 185 | ), |
| 186 | createdAt: new Date(), |
| 187 | updatedAt: new Date(), |
| 188 | archivedAt: null, |
| 189 | } |
| 190 | }, |
| 191 | (variables) => variables.id ?? generateId() |
| 192 | ) |
| 193 | |
| 194 | return useMutation({ |
| 195 | mutationFn: async ({ workspaceId, sortOrder, ...payload }: CreateFolderVariables) => { |
| 196 | const { folder } = await requestJson(createFolderContract, { |
| 197 | body: { ...payload, workspaceId, sortOrder }, |
| 198 | }) |
| 199 | return mapFolder(folder) |
| 200 | }, |
| 201 | ...handlers, |
| 202 | }) |
| 203 | } |
| 204 | |
| 205 | export function useUpdateFolder() { |
| 206 | const queryClient = useQueryClient() |
no test coverage detected