fix: workspace conflict error not showing
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { fetchApi } from "@/api";
|
import { fetchApi, type ApiError } from "@/api";
|
||||||
import type { QueryStatus } from "@/lib/query";
|
import type { QueryStatus } from "@/lib/query";
|
||||||
import { useCallback, useState } from "react";
|
import { useCallback, useState } from "react";
|
||||||
import useSWR, { useSWRConfig } from "swr";
|
import useSWR, { useSWRConfig } from "swr";
|
||||||
@@ -24,7 +24,7 @@ function useWorkspaces() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function useCreateWorkspace() {
|
function useCreateWorkspace() {
|
||||||
const [status, setStatus] = useState<QueryStatus>({ type: "idle" });
|
const [status, setStatus] = useState<QueryStatus<ApiError>>({ type: "idle" });
|
||||||
const { mutate } = useSWRConfig();
|
const { mutate } = useSWRConfig();
|
||||||
|
|
||||||
const createWorkspace = useCallback(
|
const createWorkspace = useCallback(
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { API_ERROR_WORKSPACE_EXISTS, isApiErrorResponse } from "@/api";
|
import { API_ERROR_WORKSPACE_EXISTS } from "@/api";
|
||||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { DialogFooter, DialogHeader } from "@/components/ui/dialog";
|
import { DialogFooter, DialogHeader } from "@/components/ui/dialog";
|
||||||
@@ -21,7 +21,6 @@ import {
|
|||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
SelectValue,
|
SelectValue,
|
||||||
} from "@/components/ui/select";
|
} from "@/components/ui/select";
|
||||||
import { ToastAction } from "@/components/ui/toast";
|
|
||||||
import { useToast } from "@/hooks/use-toast";
|
import { useToast } from "@/hooks/use-toast";
|
||||||
import { useTemplateImages } from "@/templates/api";
|
import { useTemplateImages } from "@/templates/api";
|
||||||
import type { TemplateImage } from "@/templates/types";
|
import type { TemplateImage } from "@/templates/types";
|
||||||
@@ -136,36 +135,24 @@ function NewWorkspaceForm({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
switch (status.type) {
|
switch (status.type) {
|
||||||
case "error":
|
case "error":
|
||||||
if (isApiErrorResponse(status.error)) {
|
{
|
||||||
let toastTitle = "";
|
let toastTitle: string;
|
||||||
switch (status.error.code) {
|
let toastDescription: string;
|
||||||
case API_ERROR_WORKSPACE_EXISTS:
|
if (
|
||||||
toastTitle = "Workspace already exists.";
|
status.error.type === "BAD_REQUEST" &&
|
||||||
break;
|
status.error.details.code === API_ERROR_WORKSPACE_EXISTS
|
||||||
default:
|
) {
|
||||||
toastTitle = "Failed to create the workspace.";
|
toastTitle = "Workspace already exists.";
|
||||||
break;
|
toastDescription = status.error.details.error;
|
||||||
|
} else {
|
||||||
|
toastTitle = "Failed to create the workspace.";
|
||||||
|
toastDescription = "Unknown error";
|
||||||
}
|
}
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
variant: "destructive",
|
variant: "destructive",
|
||||||
title: toastTitle,
|
title: toastTitle,
|
||||||
description: status.error.error,
|
description: toastDescription,
|
||||||
});
|
|
||||||
} else {
|
|
||||||
toast({
|
|
||||||
variant: "destructive",
|
|
||||||
title: "Failed to create the workspace.",
|
|
||||||
description: "Unknown error",
|
|
||||||
action: (
|
|
||||||
<ToastAction
|
|
||||||
onClick={() => {
|
|
||||||
formRef.current?.requestSubmit();
|
|
||||||
}}
|
|
||||||
altText="Try again"
|
|
||||||
>
|
|
||||||
Try again
|
|
||||||
</ToastAction>
|
|
||||||
),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user