Files
kandev/apps/web/components/task/add-workspace-sources/use-submit-workspace-sources.ts
T
Carlos Florêncio bc218dfbbe feat: add workspace sources from files panel (#1900)
* feat: add workspace sources from files panel

* fix: preserve worktree identity during recovery

* feat: unify workspace source actions

* fix: validate recovered workspace repositories

* fix: harden workspace source filesystem boundaries

* test: split workspace repository chip coverage

* fix: restrict repository rescan recovery paths

* fix: stabilize workspace source CI checks

* test: canonicalize workspace source paths

* test: align workspace source container paths

* fix: populate direct workspace repository names

* test: preserve git fixture rewrites across restarts

* test: isolate backend git fixture config

* fix: resume remote workspace executions before creation

* fix: preserve ssh agent identity during resume

* fix: preserve SSH workspace across backend restart

* fix: simplify workspace actions trigger

* fix: refine add workspace repositories UX

* docs: narrow workspace source UX updates

* fix: avoid phantom turn on session resume

* test(web): normalize workspace source request headers

* feat(web): streamline workspace source picker

* docs: remove trailing spaces from workspace source plan

* fix: prevent resume status from creating phantom turns

* fix(web): stabilize workspace source attachment

* refactor(web): extract workspace source store contract

* fix: avoid phantom turns on idle agent resume

* fix: address backend static analysis findings

* fix: preserve agentctl readiness status value

* fix: preserve resume messages without active turns

* fix: resume agents from promoted workspace root

* chore: merge origin/main into feature/add-new-repo-folder-d97

* feat(web): explain workspace source consequences

* test(websocket): count session activity subscription
2026-07-25 21:29:53 +01:00

68 lines
1.8 KiB
TypeScript

import { useCallback, type Dispatch, type SetStateAction } from "react";
import { flushSync } from "react-dom";
import { attachTaskWorkspaceSources } from "@/lib/api/domains/kanban-api";
import {
buildWorkspaceSourcesPayload,
type WorkspaceSourceRow,
} from "@/components/workspace-source-picker/workspace-source-state";
type Props = {
errors: Record<string, string>;
onOpenChange: (open: boolean) => void;
onSuccess: () => void;
reconcileWorkspaceSourcesAdopted: (sessionIds: string[]) => void;
rows: WorkspaceSourceRow[];
setSubmitting: Dispatch<SetStateAction<boolean>>;
setSubmitError: Dispatch<SetStateAction<string | null>>;
submitting: boolean;
taskId: string;
};
export function useSubmitWorkspaceSources({
errors,
onOpenChange,
onSuccess,
reconcileWorkspaceSourcesAdopted,
rows,
setSubmitting,
setSubmitError,
submitting,
taskId,
}: Props) {
return useCallback(async () => {
if (submitting) return;
if (rows.length === 0) return setSubmitError("Add at least one source.");
if (Object.keys(errors).length)
return setSubmitError("Fix the marked sources before adding them.");
setSubmitting(true);
setSubmitError(null);
try {
const result = await attachTaskWorkspaceSources(taskId, buildWorkspaceSourcesPayload(rows));
flushSync(() => {
reconcileWorkspaceSourcesAdopted(result.adopted_session_ids ?? result.session_ids);
onSuccess();
});
onOpenChange(false);
} catch (error) {
setSubmitError(
error instanceof Error
? error.message
: "Could not add sources. Your entries are still here to retry.",
);
} finally {
setSubmitting(false);
}
}, [
errors,
onOpenChange,
onSuccess,
reconcileWorkspaceSourcesAdopted,
rows,
setSubmitting,
setSubmitError,
submitting,
taskId,
]);
}