MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / DangerZoneSection

Function DangerZoneSection

apps/cloud/src/routes/app/org.tsx:88–213  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

86// removes the workspace and all of its data for every member, cancels billing,
87// and logs the caller out.
88function DangerZoneSection() {
89 const auth = useAuth();
90 const membersResult = useAtomValue(orgMembersAtom);
91 const doDelete = useAtomSet(deleteOrganization, { mode: "promiseExit" });
92 const [open, setOpen] = useState(false);
93 const [confirmText, setConfirmText] = useState("");
94 const [deleting, setDeleting] = useState(false);
95
96 const organizationName = auth.status === "authenticated" ? auth.organization?.name : undefined;
97
98 // Only admins may delete. Derive the caller's role from the members list
99 // (already loaded for this page); render nothing while it loads or for
100 // members, so a delete control never flashes for someone who can't use it.
101 const isAdmin = AsyncResult.match(membersResult, {
102 onInitial: () => false,
103 onFailure: () => false,
104 onSuccess: ({ value }) =>
105 value.members.some((m) => m.isCurrentUser && m.status === "active" && m.role === "admin"),
106 });
107
108 if (!isAdmin || !organizationName) return null;
109
110 const confirmed = confirmText.trim() === organizationName.trim();
111
112 const handleDelete = async () => {
113 if (!confirmed || deleting) return;
114 setDeleting(true);
115 const exit = await doDelete({
116 payload: { confirmName: confirmText.trim() },
117 reactivityKeys: authWriteKeys,
118 });
119 trackEvent("org_deleted", { success: Exit.isSuccess(exit) });
120 if (Exit.isSuccess(exit)) {
121 // The org (and the caller's session) are gone. A full navigation resets
122 // all app state and lets the auth gate rehydrate to another membership or
123 // the create-org screen.
124 toast.success(`Deleted ${organizationName}`);
125 window.location.href = "/";
126 return;
127 }
128 setDeleting(false);
129 toast.error("Failed to delete organization");
130 };
131
132 return (
133 <section className="mb-2 border-t border-border pt-8">
134 <div className="flex items-center justify-between rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3">
135 <div className="min-w-0">
136 <h2 className="text-sm font-medium text-destructive">Delete organization</h2>
137 <p className="mt-0.5 text-sm text-muted-foreground">
138 Permanently delete this organization and all of its data for every member. This cannot
139 be undone.
140 </p>
141 </div>
142 <Button
143 size="sm"
144 variant="destructive"
145 className="ml-4 shrink-0"

Callers

nothing calls this directly

Calls 2

useAuthFunction · 0.90
handleDeleteFunction · 0.70

Tested by

no test coverage detected