mirror of
https://github.com/fosrl/pangolin.git
synced 2026-05-22 00:35:22 +00:00
♻️ refactor
This commit is contained in:
@@ -89,7 +89,13 @@ import { useTranslations } from "next-intl";
|
|||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useParams, useRouter } from "next/navigation";
|
import { useParams, useRouter } from "next/navigation";
|
||||||
import { toASCII } from "punycode";
|
import { toASCII } from "punycode";
|
||||||
import { useEffect, useMemo, useState, useCallback } from "react";
|
import {
|
||||||
|
useMemo,
|
||||||
|
useState,
|
||||||
|
useCallback,
|
||||||
|
useTransition,
|
||||||
|
useEffect
|
||||||
|
} from "react";
|
||||||
import { Controller, useForm } from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
@@ -210,7 +216,7 @@ export default function Page() {
|
|||||||
orgQueries.sites({ orgId: orgId as string })
|
orgQueries.sites({ orgId: orgId as string })
|
||||||
);
|
);
|
||||||
|
|
||||||
const [createLoading, setCreateLoading] = useState(false);
|
const [createLoading, startTransition] = useTransition();
|
||||||
const [showSnippets, setShowSnippets] = useState(false);
|
const [showSnippets, setShowSnippets] = useState(false);
|
||||||
const [niceId, setNiceId] = useState<string>("");
|
const [niceId, setNiceId] = useState<string>("");
|
||||||
|
|
||||||
@@ -293,7 +299,10 @@ export default function Page() {
|
|||||||
{
|
{
|
||||||
id: "raw" as ResourceType,
|
id: "raw" as ResourceType,
|
||||||
title: t("resourceRaw"),
|
title: t("resourceRaw"),
|
||||||
description: build == "saas" ? t("resourceRawDescriptionCloud") : t("resourceRawDescription")
|
description:
|
||||||
|
build == "saas"
|
||||||
|
? t("resourceRawDescriptionCloud")
|
||||||
|
: t("resourceRawDescription")
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
];
|
];
|
||||||
@@ -432,8 +441,6 @@ export default function Page() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
async function onSubmit() {
|
async function onSubmit() {
|
||||||
setCreateLoading(true);
|
|
||||||
|
|
||||||
const baseData = baseForm.getValues();
|
const baseData = baseForm.getValues();
|
||||||
const isHttp = baseData.http;
|
const isHttp = baseData.http;
|
||||||
|
|
||||||
@@ -562,8 +569,6 @@ export default function Page() {
|
|||||||
description: t("resourceErrorCreateMessageDescription")
|
description: t("resourceErrorCreateMessageDescription")
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setCreateLoading(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -1394,7 +1399,7 @@ export default function Page() {
|
|||||||
console.log(httpForm.getValues());
|
console.log(httpForm.getValues());
|
||||||
|
|
||||||
if (baseValid && settingsValid) {
|
if (baseValid && settingsValid) {
|
||||||
onSubmit();
|
startTransition(onSubmit);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
loading={createLoading}
|
loading={createLoading}
|
||||||
|
|||||||
@@ -174,22 +174,17 @@ export default function ProxyResourcesTable({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteResource = (resourceId: number) => {
|
const deleteResource = async (resourceId: number) => {
|
||||||
api.delete(`/resource/${resourceId}`)
|
await api.delete(`/resource/${resourceId}`).catch((e) => {
|
||||||
.catch((e) => {
|
console.error(t("resourceErrorDelte"), e);
|
||||||
console.error(t("resourceErrorDelte"), e);
|
toast({
|
||||||
toast({
|
variant: "destructive",
|
||||||
variant: "destructive",
|
title: t("resourceErrorDelte"),
|
||||||
title: t("resourceErrorDelte"),
|
description: formatAxiosError(e, t("resourceErrorDelte"))
|
||||||
description: formatAxiosError(e, t("resourceErrorDelte"))
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
startTransition(() => {
|
|
||||||
router.refresh();
|
|
||||||
setIsDeleteModalOpen(false);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
router.refresh();
|
||||||
|
setIsDeleteModalOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
async function toggleResourceEnabled(val: boolean, resourceId: number) {
|
async function toggleResourceEnabled(val: boolean, resourceId: number) {
|
||||||
@@ -626,7 +621,11 @@ export default function ProxyResourcesTable({
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
buttonText={t("resourceDeleteConfirm")}
|
buttonText={t("resourceDeleteConfirm")}
|
||||||
onConfirm={async () => deleteResource(selectedResource!.id)}
|
onConfirm={async () =>
|
||||||
|
startTransition(() =>
|
||||||
|
deleteResource(selectedResource!.id)
|
||||||
|
)
|
||||||
|
}
|
||||||
string={selectedResource.name}
|
string={selectedResource.name}
|
||||||
title={t("resourceDelete")}
|
title={t("resourceDelete")}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user