Skip to content

Commit 06d7557

Browse files
committed
chore: add fleetctl directly to app
1 parent 4361940 commit 06d7557

6 files changed

Lines changed: 149 additions & 117 deletions

File tree

apps/app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"crypto": "^1.0.1",
6767
"d3": "^7.9.0",
6868
"dub": "^0.46.29",
69+
"fleetctl": "^4.68.1",
6970
"framer-motion": "^12.9.2",
7071
"geist": "^1.3.1",
7172
"highlight.js": "^11.11.1",

apps/app/src/actions/organization/create-organization-action.ts

Lines changed: 81 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -8,83 +8,86 @@ import { authActionClient } from "../safe-action";
88
import { organizationSchema } from "../schema";
99
import { createStripeCustomer } from "./lib/create-stripe-customer";
1010
import { initializeOrganization } from "./lib/initialize-organization";
11+
import { generateAgentFile } from "@/jobs/tasks/device/generate-agent-file";
1112

1213
export const createOrganizationAction = authActionClient
13-
.schema(organizationSchema)
14-
.metadata({
15-
name: "create-organization",
16-
track: {
17-
event: "create-organization",
18-
channel: "server",
19-
},
20-
})
21-
.action(async ({ parsedInput, ctx }) => {
22-
const { frameworkIds } = parsedInput;
23-
24-
try {
25-
const session = await auth.api.getSession({
26-
headers: await headers(),
27-
});
28-
29-
if (!session?.session.activeOrganizationId) {
30-
throw new Error("User is not part of an organization");
31-
}
32-
33-
await db.onboarding.create({
34-
data: {
35-
organizationId: session.session.activeOrganizationId,
36-
completed: false,
37-
},
38-
});
39-
40-
const organizationId = session.session.activeOrganizationId;
41-
42-
const stripeCustomerId = await createStripeCustomer({
43-
name: "My Organization",
44-
email: session.user.email,
45-
organizationId,
46-
});
47-
48-
if (!stripeCustomerId) {
49-
throw new Error("Failed to create Stripe customer");
50-
}
51-
52-
await db.organization.update({
53-
where: { id: organizationId },
54-
data: { stripeCustomerId },
55-
});
56-
57-
await initializeOrganization({ frameworkIds, organizationId });
58-
59-
await auth.api.setActiveOrganization({
60-
headers: await headers(),
61-
body: {
62-
organizationId,
63-
},
64-
});
65-
66-
const userOrgs = await db.member.findMany({
67-
where: {
68-
userId: session.user.id,
69-
},
70-
select: {
71-
organizationId: true,
72-
},
73-
});
74-
75-
for (const org of userOrgs) {
76-
revalidatePath(`/${org.organizationId}`);
77-
}
78-
79-
return {
80-
success: true,
81-
organizationId,
82-
};
83-
} catch (error) {
84-
console.error("Error during organization creation/update:", error);
85-
86-
throw new Error(
87-
"Failed to create or update organization structure",
88-
);
89-
}
90-
});
14+
.schema(organizationSchema)
15+
.metadata({
16+
name: "create-organization",
17+
track: {
18+
event: "create-organization",
19+
channel: "server",
20+
},
21+
})
22+
.action(async ({ parsedInput, ctx }) => {
23+
const { frameworkIds } = parsedInput;
24+
25+
try {
26+
const session = await auth.api.getSession({
27+
headers: await headers(),
28+
});
29+
30+
if (!session?.session.activeOrganizationId) {
31+
throw new Error("User is not part of an organization");
32+
}
33+
34+
await db.onboarding.create({
35+
data: {
36+
organizationId: session.session.activeOrganizationId,
37+
completed: false,
38+
},
39+
});
40+
41+
const organizationId = session.session.activeOrganizationId;
42+
43+
const stripeCustomerId = await createStripeCustomer({
44+
name: "My Organization",
45+
email: session.user.email,
46+
organizationId,
47+
});
48+
49+
if (!stripeCustomerId) {
50+
throw new Error("Failed to create Stripe customer");
51+
}
52+
53+
await db.organization.update({
54+
where: { id: organizationId },
55+
data: { stripeCustomerId },
56+
});
57+
58+
await initializeOrganization({ frameworkIds, organizationId });
59+
60+
await auth.api.setActiveOrganization({
61+
headers: await headers(),
62+
body: {
63+
organizationId,
64+
},
65+
});
66+
67+
const userOrgs = await db.member.findMany({
68+
where: {
69+
userId: session.user.id,
70+
},
71+
select: {
72+
organizationId: true,
73+
},
74+
});
75+
76+
for (const org of userOrgs) {
77+
revalidatePath(`/${org.organizationId}`);
78+
}
79+
80+
await generateAgentFile.trigger({
81+
organizationId,
82+
});
83+
84+
return {
85+
success: true,
86+
organizationId,
87+
};
88+
} catch (error) {
89+
console.error("Error during organization creation/update:", error);
90+
91+
throw new Error("Failed to create or update organization structure");
92+
}
93+
});

apps/app/src/app/(app)/setup/onboarding/go/[id]/components/onboarding-status.tsx

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,31 @@
22

33
import { useRun } from "@trigger.dev/react-hooks";
44
import React, { useEffect } from "react";
5-
import { onboardOrganization } from "@/jobs/tasks/onboarding/onboard-organization";
5+
import type { onboardOrganization } from "@/jobs/tasks/onboarding/onboard-organization";
66
import { useRouter } from "next/navigation";
77
import { CheckCircle } from "lucide-react";
88

99
export function OnboardingStatus({ runId }: { runId: string }) {
10-
const { run, error, isLoading } = useRun<typeof onboardOrganization>(runId, {
11-
refreshInterval: 1000,
12-
});
10+
const { run, error, isLoading } = useRun<typeof onboardOrganization>(runId, {
11+
refreshInterval: 1000,
12+
});
1313

14-
const router = useRouter();
14+
const router = useRouter();
1515

16-
useEffect(() => {
17-
if (run?.status === "COMPLETED") {
18-
router.replace("/");
19-
}
20-
}, [run?.status, router]);
16+
useEffect(() => {
17+
if (run?.status === "COMPLETED") {
18+
router.replace("/");
19+
}
20+
}, [run?.status, router]);
2121

22-
return (
23-
<div className="flex flex-col items-center justify-center">
24-
{run?.status === "COMPLETED" && (
25-
<div className="flex flex-col items-center justify-center">
26-
<CheckCircle className="h-4 w-4 text-green-500" />
27-
<p className="text-sm text-muted-foreground">
28-
Redirecting
29-
</p>
30-
</div>
31-
)}
32-
</div>
33-
)
34-
}
22+
return (
23+
<div className="flex flex-col items-center justify-center">
24+
{run?.status === "COMPLETED" && (
25+
<div className="flex flex-col items-center justify-center">
26+
<CheckCircle className="h-4 w-4 text-green-500" />
27+
<p className="text-sm text-muted-foreground">Redirecting</p>
28+
</div>
29+
)}
30+
</div>
31+
);
32+
}

apps/app/src/jobs/tasks/onboarding/onboard-organization.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,5 @@ export const onboardOrganization = task({
255255

256256
logger.info(`Created ${extractRisks.object.risks.length} risks`);
257257
logger.info(`Created ${extractVendors.object.vendors.length} vendors`);
258-
259-
await generateAgentFile.trigger({
260-
organizationId: payload.organizationId,
261-
});
262258
},
263259
});

bun.lock

Lines changed: 18 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)