mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-03 01:06:39 +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 { Input } from "@/components/ui/input";
|
||||||
import { useResourceContext } from "@app/hooks/useResourceContext";
|
import { useResourceContext } from "@app/hooks/useResourceContext";
|
||||||
import { ListSitesResponse } from "@server/routers/site";
|
import { ListSitesResponse } from "@server/routers/site";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { AxiosResponse } from "axios";
|
import { AxiosResponse } from "axios";
|
||||||
import { useParams, useRouter } from "next/navigation";
|
import { useParams, useRouter } from "next/navigation";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
@@ -90,6 +90,25 @@ export default function GeneralForm() {
|
|||||||
const [resourceFullDomain, setResourceFullDomain] = useState(
|
const [resourceFullDomain, setResourceFullDomain] = useState(
|
||||||
`${resource.ssl ? "https" : "http"}://${toUnicode(resource.fullDomain || "")}`
|
`${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<{
|
const [selectedDomain, setSelectedDomain] = useState<{
|
||||||
domainId: string;
|
domainId: string;
|
||||||
subdomain?: string;
|
subdomain?: string;
|
||||||
@@ -488,6 +507,8 @@ export default function GeneralForm() {
|
|||||||
<DomainPicker
|
<DomainPicker
|
||||||
orgId={orgId as string}
|
orgId={orgId as string}
|
||||||
cols={1}
|
cols={1}
|
||||||
|
defaultSubdomain={defaultSubdomain}
|
||||||
|
defaultBaseDomain={defaultBaseDomain}
|
||||||
onDomainChange={(res) => {
|
onDomainChange={(res) => {
|
||||||
const selected = {
|
const selected = {
|
||||||
domainId: res.domainId,
|
domainId: res.domainId,
|
||||||
|
|||||||
Reference in New Issue
Block a user