|
@@ -51,13 +51,17 @@ import { createApiClient } from "@app/lib/api";
|
|
|
import { useEnvContext } from "@app/hooks/useEnvContext";
|
|
|
import { subdomainSchema } from "@server/schemas/subdomainSchema";
|
|
|
import { CaretSortIcon, CheckIcon } from "@radix-ui/react-icons";
|
|
|
+import { pullEnv } from "@app/lib/pullEnv";
|
|
|
+import { RadioGroup, RadioGroupItem } from "@app/components/ui/radio-group";
|
|
|
+import { Label } from "@app/components/ui/label";
|
|
|
|
|
|
const GeneralFormSchema = z
|
|
|
.object({
|
|
|
subdomain: z.string().optional(),
|
|
|
name: z.string().min(1).max(255),
|
|
|
proxyPort: z.number().optional(),
|
|
|
- http: z.boolean()
|
|
|
+ http: z.boolean(),
|
|
|
+ isBaseDomain: z.boolean().optional()
|
|
|
})
|
|
|
.refine(
|
|
|
(data) => {
|
|
@@ -78,7 +82,7 @@ const GeneralFormSchema = z
|
|
|
)
|
|
|
.refine(
|
|
|
(data) => {
|
|
|
- if (data.http) {
|
|
|
+ if (data.http && !data.isBaseDomain) {
|
|
|
return subdomainSchema.safeParse(data.subdomain).success;
|
|
|
}
|
|
|
return true;
|
|
@@ -103,9 +107,11 @@ export default function GeneralForm() {
|
|
|
const { org } = useOrgContext();
|
|
|
const router = useRouter();
|
|
|
|
|
|
+ const { env } = useEnvContext();
|
|
|
+
|
|
|
const orgId = params.orgId;
|
|
|
|
|
|
- const api = createApiClient(useEnvContext());
|
|
|
+ const api = createApiClient({ env });
|
|
|
|
|
|
const [sites, setSites] = useState<ListSitesResponse["sites"]>([]);
|
|
|
const [saveLoading, setSaveLoading] = useState(false);
|
|
@@ -113,13 +119,18 @@ export default function GeneralForm() {
|
|
|
const [transferLoading, setTransferLoading] = useState(false);
|
|
|
const [open, setOpen] = useState(false);
|
|
|
|
|
|
+ const [domainType, setDomainType] = useState<"subdomain" | "basedomain">(
|
|
|
+ resource.isBaseDomain ? "basedomain" : "subdomain"
|
|
|
+ );
|
|
|
+
|
|
|
const form = useForm<GeneralFormValues>({
|
|
|
resolver: zodResolver(GeneralFormSchema),
|
|
|
defaultValues: {
|
|
|
name: resource.name,
|
|
|
subdomain: resource.subdomain ? resource.subdomain : undefined,
|
|
|
proxyPort: resource.proxyPort ? resource.proxyPort : undefined,
|
|
|
- http: resource.http
|
|
|
+ http: resource.http,
|
|
|
+ isBaseDomain: resource.isBaseDomain ? true : false
|
|
|
},
|
|
|
mode: "onChange"
|
|
|
});
|
|
@@ -148,7 +159,8 @@ export default function GeneralForm() {
|
|
|
.post(`resource/${resource?.resourceId}`, {
|
|
|
name: data.name,
|
|
|
subdomain: data.subdomain,
|
|
|
- proxyPort: data.proxyPort
|
|
|
+ proxyPort: data.proxyPort,
|
|
|
+ isBaseDomain: data.isBaseDomain
|
|
|
})
|
|
|
.catch((e) => {
|
|
|
toast({
|
|
@@ -170,7 +182,8 @@ export default function GeneralForm() {
|
|
|
updateResource({
|
|
|
name: data.name,
|
|
|
subdomain: data.subdomain,
|
|
|
- proxyPort: data.proxyPort
|
|
|
+ proxyPort: data.proxyPort,
|
|
|
+ isBaseDomain: data.isBaseDomain
|
|
|
});
|
|
|
}
|
|
|
setSaveLoading(false);
|
|
@@ -242,40 +255,103 @@ export default function GeneralForm() {
|
|
|
)}
|
|
|
/>
|
|
|
|
|
|
- {resource.http ? (
|
|
|
- <FormField
|
|
|
- control={form.control}
|
|
|
- name="subdomain"
|
|
|
- render={({ field }) => (
|
|
|
- <FormItem>
|
|
|
- <FormLabel>Subdomain</FormLabel>
|
|
|
- <FormControl>
|
|
|
- <CustomDomainInput
|
|
|
- value={
|
|
|
- field.value || ""
|
|
|
- }
|
|
|
- domainSuffix={
|
|
|
- domainSuffix
|
|
|
- }
|
|
|
- placeholder="Enter subdomain"
|
|
|
- onChange={(value) =>
|
|
|
- form.setValue(
|
|
|
- "subdomain",
|
|
|
- value
|
|
|
- )
|
|
|
- }
|
|
|
- />
|
|
|
- </FormControl>
|
|
|
- <FormDescription>
|
|
|
- This is the subdomain that
|
|
|
- will be used to access the
|
|
|
- resource.
|
|
|
- </FormDescription>
|
|
|
- <FormMessage />
|
|
|
- </FormItem>
|
|
|
+ {resource.http && (
|
|
|
+ <>
|
|
|
+ {env.flags.allowBaseDomainResources && (
|
|
|
+ <div>
|
|
|
+ <RadioGroup
|
|
|
+ className="flex space-x-4"
|
|
|
+ defaultValue={domainType}
|
|
|
+ onValueChange={(val) => {
|
|
|
+ setDomainType(
|
|
|
+ val as any
|
|
|
+ );
|
|
|
+ form.setValue(
|
|
|
+ "isBaseDomain",
|
|
|
+ val === "basedomain"
|
|
|
+ );
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <div className="flex items-center space-x-2">
|
|
|
+ <RadioGroupItem
|
|
|
+ value="subdomain"
|
|
|
+ id="r1"
|
|
|
+ />
|
|
|
+ <Label htmlFor="r1">
|
|
|
+ Subdomain
|
|
|
+ </Label>
|
|
|
+ </div>
|
|
|
+ <div className="flex items-center space-x-2">
|
|
|
+ <RadioGroupItem
|
|
|
+ value="basedomain"
|
|
|
+ id="r2"
|
|
|
+ />
|
|
|
+ <Label htmlFor="r2">
|
|
|
+ Base Domain
|
|
|
+ </Label>
|
|
|
+ </div>
|
|
|
+ </RadioGroup>
|
|
|
+ </div>
|
|
|
)}
|
|
|
- />
|
|
|
- ) : (
|
|
|
+
|
|
|
+ <FormField
|
|
|
+ control={form.control}
|
|
|
+ name="subdomain"
|
|
|
+ render={({ field }) => (
|
|
|
+ <FormItem>
|
|
|
+ {!env.flags
|
|
|
+ .allowBaseDomainResources && (
|
|
|
+ <FormLabel>
|
|
|
+ Subdomain
|
|
|
+ </FormLabel>
|
|
|
+ )}
|
|
|
+
|
|
|
+ {domainType ===
|
|
|
+ "subdomain" ? (
|
|
|
+ <FormControl>
|
|
|
+ <CustomDomainInput
|
|
|
+ value={
|
|
|
+ field.value ||
|
|
|
+ ""
|
|
|
+ }
|
|
|
+ domainSuffix={
|
|
|
+ domainSuffix
|
|
|
+ }
|
|
|
+ placeholder="Enter subdomain"
|
|
|
+ onChange={(
|
|
|
+ value
|
|
|
+ ) =>
|
|
|
+ form.setValue(
|
|
|
+ "subdomain",
|
|
|
+ value
|
|
|
+ )
|
|
|
+ }
|
|
|
+ />
|
|
|
+ </FormControl>
|
|
|
+ ) : (
|
|
|
+ <FormControl>
|
|
|
+ <Input
|
|
|
+ value={
|
|
|
+ domainSuffix
|
|
|
+ }
|
|
|
+ readOnly
|
|
|
+ disabled
|
|
|
+ />
|
|
|
+ </FormControl>
|
|
|
+ )}
|
|
|
+ <FormDescription>
|
|
|
+ This is the subdomain
|
|
|
+ that will be used to
|
|
|
+ access the resource.
|
|
|
+ </FormDescription>
|
|
|
+ <FormMessage />
|
|
|
+ </FormItem>
|
|
|
+ )}
|
|
|
+ />
|
|
|
+ </>
|
|
|
+ )}
|
|
|
+
|
|
|
+ {!resource.http && (
|
|
|
<FormField
|
|
|
control={form.control}
|
|
|
name="proxyPort"
|