()
| 256 | } |
| 257 | |
| 258 | export function useDuplicateFolderMutation() { |
| 259 | const queryClient = useQueryClient() |
| 260 | |
| 261 | const handlers = createFolderMutationHandlers<DuplicateFolderVariables>( |
| 262 | queryClient, |
| 263 | 'DuplicateFolder', |
| 264 | (variables, tempId, previousFolders) => { |
| 265 | const currentWorkflows = Object.fromEntries( |
| 266 | getWorkflows(variables.workspaceId).map((w) => [w.id, w]) |
| 267 | ) |
| 268 | |
| 269 | const sourceFolder = previousFolders[variables.id] |
| 270 | const targetParentId = variables.parentId ?? sourceFolder?.parentId ?? null |
| 271 | return { |
| 272 | id: tempId, |
| 273 | name: variables.name, |
| 274 | userId: sourceFolder?.userId || '', |
| 275 | workspaceId: variables.workspaceId, |
| 276 | parentId: targetParentId, |
| 277 | color: variables.color || sourceFolder?.color || '#808080', |
| 278 | isExpanded: false, |
| 279 | locked: false, |
| 280 | sortOrder: getTopInsertionSortOrder( |
| 281 | currentWorkflows, |
| 282 | previousFolders, |
| 283 | variables.workspaceId, |
| 284 | targetParentId |
| 285 | ), |
| 286 | createdAt: new Date(), |
| 287 | updatedAt: new Date(), |
| 288 | archivedAt: null, |
| 289 | } |
| 290 | }, |
| 291 | (variables) => variables.newId ?? generateId() |
| 292 | ) |
| 293 | |
| 294 | return useMutation({ |
| 295 | mutationFn: async ({ |
| 296 | id, |
| 297 | workspaceId, |
| 298 | name, |
| 299 | parentId, |
| 300 | color, |
| 301 | newId, |
| 302 | }: DuplicateFolderVariables): Promise<WorkflowFolder> => { |
| 303 | const { folder } = await requestJson(duplicateFolderContract, { |
| 304 | params: { id }, |
| 305 | body: { |
| 306 | workspaceId, |
| 307 | name, |
| 308 | parentId: parentId ?? null, |
| 309 | color, |
| 310 | newId, |
| 311 | }, |
| 312 | }) |
| 313 | return mapFolder(folder) |
| 314 | }, |
| 315 | ...handlers, |
no test coverage detected