Remove redirect domain creation while adding custom domain

This commit is contained in:
Shreerang Kale 2025-01-30 14:38:29 +05:30 committed by IshaVenikar
parent c202554002
commit 4ae4670dca
3 changed files with 55 additions and 53 deletions

View File

@ -1243,7 +1243,7 @@ export class Service {
data: { name: string },
): Promise<{
primaryDomain: Domain;
redirectedDomain: Domain;
// redirectedDomain: Domain;
}> {
const currentProject = await this.db.getProjectById(projectId);
@ -1259,22 +1259,22 @@ export class Service {
const savedPrimaryDomain = await this.db.addDomain(primaryDomainDetails);
const domainArr = data.name.split('www.');
// const domainArr = data.name.split('www.');
const redirectedDomainDetails = {
name: domainArr.length > 1 ? domainArr[1] : `www.${domainArr[0]}`,
branch: currentProject.prodBranch,
project: currentProject,
redirectTo: savedPrimaryDomain,
};
// const redirectedDomainDetails = {
// name: domainArr.length > 1 ? domainArr[1] : `www.${domainArr[0]}`,
// branch: currentProject.prodBranch,
// project: currentProject,
// redirectTo: savedPrimaryDomain,
// };
const savedRedirectedDomain = await this.db.addDomain(
redirectedDomainDetails,
);
// const savedRedirectedDomain = await this.db.addDomain(
// redirectedDomainDetails,
// );
return {
primaryDomain: savedPrimaryDomain,
redirectedDomain: savedRedirectedDomain,
// redirectedDomain: savedRedirectedDomain,
};
}

View File

@ -1,12 +1,12 @@
import { useEffect, useState } from 'react';
// import { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { useForm } from 'react-hook-form';
import { Heading } from 'components/shared/Heading';
import { InlineNotification } from 'components/shared/InlineNotification';
// import { InlineNotification } from 'components/shared/InlineNotification';
import { Input } from 'components/shared/Input';
import { Button } from 'components/shared/Button';
import { Radio } from 'components/shared/Radio';
// import { Radio } from 'components/shared/Radio';
interface SetupDomainFormValues {
domainName: string;
@ -18,47 +18,45 @@ const SetupDomain = () => {
register,
handleSubmit,
formState: { isValid },
watch,
setValue,
// watch,
// setValue,
} = useForm<SetupDomainFormValues>({
defaultValues: {
domainName: '',
isWWW: 'false',
// isWWW: 'false',
},
mode: 'onChange',
});
const [domainStr, setDomainStr] = useState<string>('');
// const [domainStr, setDomainStr] = useState<string>('');
const navigate = useNavigate();
const isWWWRadioOptions = [
{ label: domainStr, value: 'false' },
{ label: `www.${domainStr}`, value: 'true' },
];
// const isWWWRadioOptions = [
// { label: domainStr, value: 'false' },
// { label: `www.${domainStr}`, value: 'true' },
// ];
useEffect(() => {
const subscription = watch((value, { name }) => {
if (name === 'domainName' && value.domainName) {
const domainArr = value.domainName.split('www.');
const cleanedDomain =
domainArr.length > 1 ? domainArr[1] : domainArr[0];
setDomainStr(cleanedDomain);
// useEffect(() => {
// const subscription = watch((value, { name }) => {
// if (name === 'domainName' && value.domainName) {
// const domainArr = value.domainName.split('www.');
// const cleanedDomain =
// domainArr.length > 1 ? domainArr[1] : domainArr[0];
// setDomainStr(cleanedDomain);
setValue(
'isWWW',
value.domainName.startsWith('www.') ? 'true' : 'false',
);
}
});
// setValue(
// 'isWWW',
// value.domainName.startsWith('www.') ? 'true' : 'false',
// );
// }
// });
return () => subscription.unsubscribe();
}, [watch, setValue]);
// return () => subscription.unsubscribe();
// }, [watch, setValue]);
return (
<form
onSubmit={handleSubmit(() => {
watch('isWWW') === 'true'
? navigate(`config?name=www.${domainStr}`)
: navigate(`config?name=${domainStr}`);
onSubmit={handleSubmit((e) => {
navigate(`config?name=${e.domainName}`)
})}
className="flex flex-col gap-6 w-full"
>
@ -80,7 +78,7 @@ const SetupDomain = () => {
label="Domain name"
/>
{isValid && (
{/* {isValid && (
<div className="self-stretch flex flex-col gap-4">
<Heading className="text-sky-950 text-lg font-medium leading-normal">
Primary domain
@ -99,7 +97,7 @@ const SetupDomain = () => {
}. Redirect preferences can be changed later`}
/>
</div>
)}
)} */}
<div className="self-stretch">
<Button disabled={!isValid} type="submit" shape="default">

View File

@ -61,6 +61,8 @@ const Domains = () => {
<ProjectSettingContainer
headingText="Domains"
button={
<>
{domains.length == 0 && (
<Button
as="a"
href="add"
@ -70,6 +72,8 @@ const Domains = () => {
>
Add domain
</Button>
)}
</>
}
>
{domains.map((domain) => {