mirror of
https://github.com/fosrl/pangolin.git
synced 2026-01-29 06:10:47 +00:00
♻️ set default value on domain picker modal in proxy resource page
This commit is contained in:
@@ -16,7 +16,7 @@ import {
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { useResourceContext } from "@app/hooks/useResourceContext";
|
||||
import { ListSitesResponse } from "@server/routers/site";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { AxiosResponse } from "axios";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { useForm } from "react-hook-form";
|
||||
@@ -90,6 +90,25 @@ export default function GeneralForm() {
|
||||
const [resourceFullDomain, setResourceFullDomain] = useState(
|
||||
`${resource.ssl ? "https" : "http"}://${toUnicode(resource.fullDomain || "")}`
|
||||
);
|
||||
|
||||
const [defaultSubdomain, defaultBaseDomain] = useMemo(() => {
|
||||
const resourceUrl = new URL(resourceFullDomain);
|
||||
const domain = resourceUrl.hostname;
|
||||
|
||||
const allDomainParts = domain.split(".");
|
||||
let sub = undefined;
|
||||
let base = domain;
|
||||
|
||||
if (allDomainParts.length >= 3) {
|
||||
// 3 parts: [subdomain, domain, tld]
|
||||
const [first, ...rest] = allDomainParts;
|
||||
sub = first;
|
||||
base = rest.join(".");
|
||||
}
|
||||
|
||||
return [sub, base];
|
||||
}, [resourceFullDomain]);
|
||||
|
||||
const [selectedDomain, setSelectedDomain] = useState<{
|
||||
domainId: string;
|
||||
subdomain?: string;
|
||||
@@ -488,6 +507,8 @@ export default function GeneralForm() {
|
||||
<DomainPicker
|
||||
orgId={orgId as string}
|
||||
cols={1}
|
||||
defaultSubdomain={defaultSubdomain}
|
||||
defaultBaseDomain={defaultBaseDomain}
|
||||
onDomainChange={(res) => {
|
||||
const selected = {
|
||||
domainId: res.domainId,
|
||||
|
||||
Reference in New Issue
Block a user