Skip to content

Commit c2edd0b

Browse files
committed
update api for desktop
1 parent 00145f9 commit c2edd0b

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

apps/web/app/(org)/dashboard/settings/organization/components/DeleteOrgDialog.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ interface DeleteOrgDialogProps {
2323
}
2424

2525
const DeleteOrgDialog = ({ open, onOpenChange }: DeleteOrgDialogProps) => {
26-
const { activeOrganization, organizationData, user } = useDashboardContext();
26+
const { activeOrganization, organizationData } = useDashboardContext();
2727
const [organizationName, setOrganizationName] = useState("");
2828
const rpc = useRpcClient();
29+
const inputId = useId();
2930
const router = useRouter();
3031
const deleteOrg = useEffectMutation({
3132
mutationFn: Effect.fn(function* () {
33+
if (!activeOrganization) return;
3234
yield* rpc.OrganisationDelete({
33-
id: activeOrganization?.organization.id as Organisation.OrganisationId,
35+
id: activeOrganization.organization.id,
3436
});
3537
}),
3638
onSuccess: () => {
@@ -58,7 +60,7 @@ const DeleteOrgDialog = ({ open, onOpenChange }: DeleteOrgDialogProps) => {
5860
</DialogHeader>
5961
<div className="p-5">
6062
<Input
61-
id={useId()}
63+
id={inputId}
6264
value={organizationName}
6365
onChange={(e) => setOrganizationName(e.target.value)}
6466
placeholder="Organization name"

apps/web/app/api/desktop/[...route]/root.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import { buildEnv, serverEnv } from "@cap/env";
99
import { stripe, userIsPro } from "@cap/utils";
1010
import { zValidator } from "@hono/zod-validator";
11-
import { eq, or } from "drizzle-orm";
11+
import { and, eq, isNull, or } from "drizzle-orm";
1212
import { Hono } from "hono";
1313
import { PostHog } from "posthog-node";
1414
import type Stripe from "stripe";
@@ -212,9 +212,12 @@ app.get("/organizations", withAuth, async (c) => {
212212
eq(organizations.id, organizationMembers.organizationId),
213213
)
214214
.where(
215-
or(
216-
eq(organizations.ownerId, user.id),
217-
eq(organizationMembers.userId, user.id),
215+
and(
216+
isNull(organizations.tombstoneAt),
217+
or(
218+
eq(organizations.ownerId, user.id),
219+
eq(organizationMembers.userId, user.id),
220+
),
218221
),
219222
)
220223
.groupBy(organizations.id);

packages/web-backend/src/Organisations/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ export class Organisations extends Effect.Service<Organisations>()(
5353
) {
5454
const user = yield* CurrentUser;
5555

56+
yield* Policy.withPolicy(policy.isOwner(id))(Effect.void);
57+
5658
//this is fake deleting for now
5759
yield* db.use((db) =>
5860
db

0 commit comments

Comments
 (0)