React SDKHooksOrganizations

useCapxulCreateOrg

Complete one Organization setup through the public onboarding method.

This mutation calls client.onboarding.completeOrganization. It begins setup, authorizes only when the backend waits for founder authorization, and observes the exact Organization until it is ready. A successful result contains organizationId.

Import

import { useCapxulCreateOrg } from "@capxul/sdk-react";

Usage

"use client";

import { useState } from "react";
import { useCapxulCreateOrg } from "@capxul/sdk-react";

function CreateOrgForm({ onCreated }: { onCreated: (orgId: string) => void }) {
  const createOrg = useCapxulCreateOrg();
  const [name, setName] = useState("");
  const [handle, setHandle] = useState("");

  return (
    <form
      onSubmit={async (event) => {
        event.preventDefault();
        const result = await createOrg.mutateAsync({
          name,
          handle,
          country: "GH",
        });
        onCreated(result.organizationId);
      }}
    >
      <input required value={name} onChange={(event) => setName(event.target.value)} />
      <input required value={handle} onChange={(event) => setHandle(event.target.value)} />
      <button type="submit" disabled={createOrg.isPending}>
        Create Organization
      </button>
      {createOrg.error ? <p>Could not create the Organization ({createOrg.error.code}).</p> : null}
    </form>
  );
}

The example country is an ISO country code. Supply the founder's actual country in your application.

Input and result

The mutation takes OrganizationOnboardingInput: required name, handle, and country, with optional bio, size, and logoStorageId. The handle must be available and match the backend's handle rules.

UseMutationResult resolves an OrganizationOnboarding value with organizationId after setup is ready. The hook invalidates the Organization list on success. Expected failures surface as CapxulError.

If your application must store the ID before the signer opens, call client.onboarding.beginOrganization directly. It returns orgId and setup before authorization. Store orgId, call client.org(orgId).setup.authorize only for awaitingAuthorization, then observe setup.subscribe. See Work with organizations for a subscription example that cleans up after asynchronous acquisition.

The hook returns TanStack Query's UseMutationResult. The most-used fields:

FieldDescription
mutateFire the mutation (fire-and-forget; pair with onSuccess/onError callbacks).
mutateAsyncFire the mutation and get a Promise of the result. Rejects with a CapxulError on failure.
dataThe mutation result (typed per hook, shown above). undefined until the first success.
errorA CapxulError when the last attempt failed, otherwise null.
isPendingtrue while the mutation is in flight. Use it to disable submit buttons.
resetClear the mutation state (data, error) back to idle.

Mutations do not retry by default. The full field list is in the TanStack Query useMutation reference; see also the TanStack Query integration guide.

Client-backed mutation hooks are safe to render while CapxulProvider bootstraps. If one is fired before bootstrap finishes, mutateAsync rejects with a CapxulError whose code is WRONG_STATE; applications do not need to hide their route tree behind useCapxul(). Every shipped mutation hook is client-backed — alpha.23 removed the one client-free hook (useCapxulSwitchActingEntity, a documented no-op).

Client method

The hook wraps client.onboarding.completeOrganization(input). It does not call the removed client.createOrg method.

On this page