diff --git a/src/app/[orgId]/settings/resources/[niceId]/general/page.tsx b/src/app/[orgId]/settings/resources/[niceId]/general/page.tsx index 28f7754b..dfd16ad0 100644 --- a/src/app/[orgId]/settings/resources/[niceId]/general/page.tsx +++ b/src/app/[orgId]/settings/resources/[niceId]/general/page.tsx @@ -68,9 +68,9 @@ export default function GeneralForm() { const router = useRouter(); const t = useTranslations(); const [editDomainOpen, setEditDomainOpen] = useState(false); - const {licenseStatus } = useLicenseStatusContext(); + const { licenseStatus } = useLicenseStatusContext(); const subscriptionStatus = useSubscriptionStatusContext(); - const {user} = useUserContext(); + const { user } = useUserContext(); const { env } = useEnvContext(); @@ -102,6 +102,7 @@ export default function GeneralForm() { enabled: z.boolean(), subdomain: z.string().optional(), name: z.string().min(1).max(255), + niceId: z.string().min(1).max(255).optional(), domainId: z.string().optional(), proxyPort: z.number().int().min(1).max(65535).optional(), // enableProxy: z.boolean().optional() @@ -130,6 +131,7 @@ export default function GeneralForm() { defaultValues: { enabled: resource.enabled, name: resource.name, + niceId: resource.niceId, subdomain: resource.subdomain ? resource.subdomain : undefined, domainId: resource.domainId || undefined, proxyPort: resource.proxyPort || undefined, @@ -192,6 +194,7 @@ export default function GeneralForm() { { enabled: data.enabled, name: data.name, + niceId: data.niceId, subdomain: data.subdomain ? toASCII(data.subdomain) : undefined, domainId: data.domainId, proxyPort: data.proxyPort, @@ -212,16 +215,12 @@ export default function GeneralForm() { }); if (res && res.status === 200) { - toast({ - title: t("resourceUpdated"), - description: t("resourceUpdatedDescription") - }); - - const resource = res.data.data; + const updated = res.data.data; updateResource({ enabled: data.enabled, name: data.name, + niceId: data.niceId, subdomain: data.subdomain, fullDomain: resource.fullDomain, proxyPort: data.proxyPort, @@ -230,8 +229,20 @@ export default function GeneralForm() { // }) }); - router.refresh(); + toast({ + title: t("resourceUpdated"), + description: t("resourceUpdatedDescription") + }); + + if (data.niceId && data.niceId !== resource?.niceId) { + router.replace(`/${updated.orgId}/settings/resources/${data.niceId}/general`); + } else { + router.refresh(); + } + + setSaveLoading(false); } + setSaveLoading(false); } @@ -304,6 +315,24 @@ export default function GeneralForm() { )} /> + ( + + {t("niceId") || "Nice ID"} + + + + + + )} + /> + {!resource.http && ( <> { - setTempNiceId(niceId); - setIsEditing(true); - }; - - const handleCancel = () => { - setTempNiceId(niceId); - setIsEditing(false); - }; - - const handleSave = async () => { - if (tempNiceId.trim() === "") { - toast({ - variant: "destructive", - title: t("error"), - description: t("niceIdCannotBeEmpty") - }); - return; - } - - if (tempNiceId === niceId) { - setIsEditing(false); - return; - } - - setIsLoading(true); - - try { - const res = await api - .post>( - `resource/${resource?.resourceId}`, - { - niceId: tempNiceId.trim() - } - ); - - setNiceId(tempNiceId.trim()); - setIsEditing(false); - - updateResource({ - niceId: tempNiceId.trim() - }); - - // update the URL to reflect the new niceId - const newPath = pathname.replace(`/resources/${niceId}`, `/resources/${tempNiceId.trim()}`); - router.replace(newPath); - - toast({ - title: t("niceIdUpdated"), - description: t("niceIdUpdatedSuccessfully") - }); - } catch (e: any) { - toast({ - variant: "destructive", - title: t("niceIdUpdateError"), - description: formatAxiosError( - e, - t("niceIdUpdateErrorDescription") - ) - }); - } finally { - setIsLoading(false); - } - }; - - - const handleKeyDown = (e: React.KeyboardEvent) => { - if (e.key === "Enter") { - handleSave(); - } else if (e.key === "Escape") { - handleCancel(); - } - }; - return ( {/* 4 cols because of the certs */} - - - {t("niceId")} - - -
- {isEditing ? ( - <> - setTempNiceId(e.target.value)} - onKeyDown={handleKeyDown} - disabled={isLoading} - className="flex-1" - autoFocus - /> - - - - ) : ( - <> - {niceId} - - - )} -
-
-
{resource.http ? ( <>