Skip to content

Commit e632d50

Browse files
committed
wip
1 parent 7a9713e commit e632d50

File tree

4 files changed

+53
-29
lines changed

4 files changed

+53
-29
lines changed

apps/dashboard/src/@3rdweb-sdk/react/cache-keys.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export const engineKeys = {
111111
] as const,
112112
health: (instance: string) =>
113113
[...engineKeys.all, instance, "health"] as const,
114-
latestVersion: () => [...engineKeys.all, "latestVersion"] as const,
114+
deployment: () => [...engineKeys.all, "deployment"] as const,
115115
systemMetrics: (engineId: string) =>
116116
[...engineKeys.all, engineId, "systemMetrics"] as const,
117117
queueMetrics: (engineId: string) =>

apps/dashboard/src/@3rdweb-sdk/react/hooks/useEngine.ts

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,32 +190,46 @@ export function useEngineQueueMetrics(
190190
});
191191
}
192192

193-
export function useEngineLatestVersion() {
193+
interface GetDeploymentInput {
194+
teamId: string;
195+
deploymentId: string;
196+
}
197+
198+
export function useEngineGetDeployment(input: GetDeploymentInput) {
194199
return useQuery({
195-
queryKey: engineKeys.latestVersion(),
200+
queryKey: engineKeys.deployment(),
196201
queryFn: async () => {
197-
const res = await fetch(`${THIRDWEB_API_HOST}/v1/engine/latest-version`, {
198-
method: "GET",
199-
});
202+
const res = await fetch(
203+
`${THIRDWEB_API_HOST}/v1/teams/${input.teamId}/engine/deployments/${input.deploymentId}`,
204+
{
205+
method: "GET",
206+
},
207+
);
200208
if (!res.ok) {
201209
throw new Error(`Unexpected status ${res.status}: ${await res.text()}`);
202210
}
203211
const json = await res.json();
204-
return json.data.version as string;
212+
return json.data as {
213+
serverVersions: {
214+
latest: string;
215+
recent: string[];
216+
};
217+
};
205218
},
206219
});
207220
}
208221

209-
interface UpdateVersionInput {
222+
interface UpdateDeploymentInput {
223+
teamId: string;
210224
deploymentId: string;
211225
serverVersion: string;
212226
}
213227

214-
export function useEngineUpdateServerVersion() {
228+
export function useEngineUpdateDeployment() {
215229
return useMutation({
216-
mutationFn: async (input: UpdateVersionInput) => {
230+
mutationFn: async (input: UpdateDeploymentInput) => {
217231
const res = await fetch(
218-
`${THIRDWEB_API_HOST}/v2/engine/deployments/${input.deploymentId}/infrastructure`,
232+
`${THIRDWEB_API_HOST}/v1/teams/${input.teamId}/engine/deployments/${input.deploymentId}`,
219233
{
220234
method: "PUT",
221235
headers: {
@@ -261,24 +275,26 @@ export function useEngineRemoveFromDashboard() {
261275
});
262276
}
263277

264-
export interface DeleteCloudHostedInput {
278+
export interface DeleteDeploymentInput {
279+
teamId: string;
265280
deploymentId: string;
266281
reason: "USING_SELF_HOSTED" | "TOO_EXPENSIVE" | "MISSING_FEATURES" | "OTHER";
267282
feedback: string;
268283
}
269284

270-
export function useEngineDeleteCloudHosted() {
285+
export function useEngineDeleteDeployment() {
271286
const { user } = useLoggedInUser();
272287
const queryClient = useQueryClient();
273288

274289
return useMutation({
275290
mutationFn: async ({
291+
teamId,
276292
deploymentId,
277293
reason,
278294
feedback,
279-
}: DeleteCloudHostedInput) => {
295+
}: DeleteDeploymentInput) => {
280296
const res = await fetch(
281-
`${THIRDWEB_API_HOST}/v2/engine/deployments/${deploymentId}/infrastructure/delete`,
297+
`${THIRDWEB_API_HOST}/v1/teams/${teamId}/engine/deployments/${deploymentId}/delete`,
282298
{
283299
method: "POST",
284300
headers: {

apps/dashboard/src/components/engine/badges/version.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { Button } from "@/components/ui/button";
22
import { ToolTipLabel } from "@/components/ui/tooltip";
33
import {
44
type EngineInstance,
5-
useEngineLatestVersion,
5+
useEngineGetDeployment,
66
useEngineSystemHealth,
7-
useEngineUpdateServerVersion,
7+
useEngineUpdateDeployment,
88
} from "@3rdweb-sdk/react/hooks/useEngine";
99
import { CircleArrowDownIcon, CloudDownloadIcon } from "lucide-react";
1010
import { useState } from "react";
@@ -28,7 +28,7 @@ export const EngineVersionBadge = ({
2828
instance: EngineInstance;
2929
}) => {
3030
const healthQuery = useEngineSystemHealth(instance.url);
31-
const latestVersionQuery = useEngineLatestVersion();
31+
const latestVersionQuery = useEngineGetDeployment();
3232
const [isModalOpen, setModalOpen] = useState(false);
3333

3434
const currentVersion = healthQuery.data?.engineVersion ?? "...";
@@ -86,7 +86,9 @@ const UpdateVersionModal = (props: {
8686
instance: EngineInstance;
8787
}) => {
8888
const { open, onOpenChange, latestVersion, instance } = props;
89-
const updateEngineServerMutation = useEngineUpdateServerVersion();
89+
const updateDeploymentMutation = useEngineUpdateDeployment();
90+
91+
const teamId = "DEBUG - UNIMPLEMENTED";
9092

9193
if (!instance.deploymentId) {
9294
// For self-hosted, show a prompt to the Github release page.
@@ -123,7 +125,8 @@ const UpdateVersionModal = (props: {
123125
invariant(instance.deploymentId, "Engine is missing deploymentId.");
124126

125127
try {
126-
const promise = updateEngineServerMutation.mutateAsync({
128+
const promise = updateDeploymentMutation.mutateAsync({
129+
teamId,
127130
deploymentId: instance.deploymentId,
128131
serverVersion: latestVersion,
129132
});
@@ -166,7 +169,7 @@ const UpdateVersionModal = (props: {
166169
variant="primary"
167170
className="gap-2"
168171
>
169-
{updateEngineServerMutation.isPending ? (
172+
{updateDeploymentMutation.isPending ? (
170173
<Spinner className="size-4" />
171174
) : (
172175
<CloudDownloadIcon className="size-4" />

apps/dashboard/src/components/engine/engine-instances-table.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import { Input } from "@/components/ui/input";
1414
import { Textarea } from "@/components/ui/textarea";
1515
import { ToolTipLabel } from "@/components/ui/tooltip";
1616
import {
17-
type DeleteCloudHostedInput,
17+
type DeleteDeploymentInput,
1818
type EditEngineInstanceInput,
1919
type EngineInstance,
20-
useEngineDeleteCloudHosted,
20+
useEngineDeleteDeployment,
2121
useEngineEditInstance,
2222
type useEngineInstances,
2323
useEngineRemoveFromDashboard,
@@ -383,17 +383,20 @@ function DeleteSubscriptionModalContent(props: {
383383
"Instance must have a deploymentId to be cancelled.",
384384
);
385385

386-
const deleteCloudHosted = useEngineDeleteCloudHosted();
386+
const teamId = "DEBUG - UNIMPLEMENTED";
387+
388+
const deleteDeploymentMutation = useEngineDeleteDeployment();
387389
const [ackDeletion, setAckDeletion] = useState(false);
388-
const form = useForm<DeleteCloudHostedInput>({
390+
const form = useForm<DeleteDeploymentInput>({
389391
defaultValues: {
392+
teamId,
390393
deploymentId: instance.deploymentId,
391394
},
392395
reValidateMode: "onChange",
393396
});
394397

395-
const onSubmit = (data: DeleteCloudHostedInput) => {
396-
deleteCloudHosted.mutate(data, {
398+
const onSubmit = (data: DeleteDeploymentInput) => {
399+
deleteDeploymentMutation.mutate(data, {
397400
onSuccess: () => {
398401
toast.success("Deleting Engine. Please check again in a few minutes.", {
399402
dismissible: true,
@@ -502,12 +505,14 @@ function DeleteSubscriptionModalContent(props: {
502505
variant="destructive"
503506
disabled={
504507
!ackDeletion ||
505-
deleteCloudHosted.isPending ||
508+
deleteDeploymentMutation.isPending ||
506509
!form.formState.isValid
507510
}
508511
className="gap-2"
509512
>
510-
{deleteCloudHosted.isPending && <Spinner className="size-4" />}
513+
{deleteDeploymentMutation.isPending && (
514+
<Spinner className="size-4" />
515+
)}
511516
Permanently Delete Engine
512517
</Button>
513518
</DialogFooter>

0 commit comments

Comments
 (0)