Remove redirect domain from edit domain form
This commit is contained in:
parent
db56e19c54
commit
496ceff0fa
@ -1,11 +1,19 @@
|
|||||||
import { useCallback, useEffect, useMemo } from 'react';
|
import {
|
||||||
import { Controller, useForm, SubmitHandler } from 'react-hook-form';
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
// useMemo
|
||||||
|
} from 'react';
|
||||||
|
import {
|
||||||
|
// Controller,
|
||||||
|
useForm,
|
||||||
|
SubmitHandler,
|
||||||
|
} from 'react-hook-form';
|
||||||
import { Domain } from 'gql-client';
|
import { Domain } from 'gql-client';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Typography,
|
Typography,
|
||||||
Select,
|
// Select,
|
||||||
Option,
|
// Option,
|
||||||
} from '@snowballtools/material-tailwind-react-fork';
|
} from '@snowballtools/material-tailwind-react-fork';
|
||||||
|
|
||||||
import { useGQLClient } from 'context/GQLClientContext';
|
import { useGQLClient } from 'context/GQLClientContext';
|
||||||
@ -14,7 +22,7 @@ import { Button } from 'components/shared/Button';
|
|||||||
import { Input } from 'components/shared/Input';
|
import { Input } from 'components/shared/Input';
|
||||||
import { useToast } from 'components/shared/Toast';
|
import { useToast } from 'components/shared/Toast';
|
||||||
|
|
||||||
const DEFAULT_REDIRECT_OPTIONS = ['none'];
|
// const DEFAULT_REDIRECT_OPTIONS = ['none'];
|
||||||
|
|
||||||
interface EditDomainDialogProp {
|
interface EditDomainDialogProp {
|
||||||
domains: Domain[];
|
domains: Domain[];
|
||||||
@ -28,7 +36,7 @@ interface EditDomainDialogProp {
|
|||||||
type EditDomainValues = {
|
type EditDomainValues = {
|
||||||
name: string;
|
name: string;
|
||||||
branch: string;
|
branch: string;
|
||||||
redirectedTo: string;
|
// redirectedTo: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const EditDomainDialog = ({
|
const EditDomainDialog = ({
|
||||||
@ -42,58 +50,58 @@ const EditDomainDialog = ({
|
|||||||
const client = useGQLClient();
|
const client = useGQLClient();
|
||||||
const { toast, dismiss } = useToast();
|
const { toast, dismiss } = useToast();
|
||||||
|
|
||||||
const getRedirectUrl = (domain: Domain) => {
|
// const getRedirectUrl = (domain: Domain) => {
|
||||||
const redirectDomain = domain.redirectTo;
|
// const redirectDomain = domain.redirectTo;
|
||||||
|
|
||||||
if (redirectDomain !== null) {
|
// if (redirectDomain !== null) {
|
||||||
return redirectDomain?.name;
|
// return redirectDomain?.name;
|
||||||
} else {
|
// } else {
|
||||||
return 'none';
|
// return 'none';
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
|
|
||||||
const redirectOptions = useMemo(() => {
|
// const redirectOptions = useMemo(() => {
|
||||||
const domainNames = domains
|
// const domainNames = domains
|
||||||
.filter((domainData) => domainData.id !== domain.id)
|
// .filter((domainData) => domainData.id !== domain.id)
|
||||||
.map((domain) => domain.name);
|
// .map((domain) => domain.name);
|
||||||
return ['none', ...domainNames];
|
// return ['none', ...domainNames];
|
||||||
}, [domain, domains]);
|
// }, [domain, domains]);
|
||||||
|
|
||||||
const domainRedirectedFrom = useMemo(() => {
|
// const domainRedirectedFrom = useMemo(() => {
|
||||||
return domains.find(
|
// return domains.find(
|
||||||
(domainData) => domainData.redirectTo?.id === domain.id,
|
// (domainData) => domainData.redirectTo?.id === domain.id,
|
||||||
);
|
// );
|
||||||
}, [domains, domain]);
|
// }, [domains, domain]);
|
||||||
|
|
||||||
const isDisableDropdown = useMemo(() => {
|
// const isDisableDropdown = useMemo(() => {
|
||||||
return domainRedirectedFrom !== undefined;
|
// return domainRedirectedFrom !== undefined;
|
||||||
}, [domain, domains]);
|
// }, [domain, domains]);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
register,
|
register,
|
||||||
control,
|
// control,
|
||||||
watch,
|
// watch,
|
||||||
reset,
|
reset,
|
||||||
formState: { isValid, isDirty },
|
formState: { isValid, isDirty },
|
||||||
} = useForm({
|
} = useForm({
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
name: domain.name,
|
name: domain.name,
|
||||||
branch: domain.branch,
|
branch: domain.branch,
|
||||||
redirectedTo: getRedirectUrl(domain),
|
// redirectedTo: getRedirectUrl(domain),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const updateDomainHandler: SubmitHandler<EditDomainValues> = useCallback(
|
const updateDomainHandler: SubmitHandler<EditDomainValues> = useCallback(
|
||||||
async (data) => {
|
async (data) => {
|
||||||
const domainRedirectTo = domains.find(
|
// const domainRedirectTo = domains.find(
|
||||||
(domainData) => data.redirectedTo === domainData.name,
|
// (domainData) => data.redirectedTo === domainData.name,
|
||||||
);
|
// );
|
||||||
|
|
||||||
const updates = {
|
const updates = {
|
||||||
name: data.name ? data.name : domain.name,
|
name: data.name ? data.name : domain.name,
|
||||||
branch: data.branch ? data.branch : domain.branch,
|
branch: data.branch ? data.branch : domain.branch,
|
||||||
redirectToId: domainRedirectTo ? domainRedirectTo.id : null,
|
// redirectToId: domainRedirectTo ? domainRedirectTo.id : null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const { updateDomain } = await client.updateDomain(domain.id, updates);
|
const { updateDomain } = await client.updateDomain(domain.id, updates);
|
||||||
@ -125,7 +133,7 @@ const EditDomainDialog = ({
|
|||||||
reset({
|
reset({
|
||||||
name: domain.name,
|
name: domain.name,
|
||||||
branch: domain.branch,
|
branch: domain.branch,
|
||||||
redirectedTo: getRedirectUrl(domain),
|
// redirectedTo: getRedirectUrl(domain),
|
||||||
});
|
});
|
||||||
}, [domain]);
|
}, [domain]);
|
||||||
|
|
||||||
@ -137,7 +145,7 @@ const EditDomainDialog = ({
|
|||||||
<Modal.Body className="flex flex-col gap-2">
|
<Modal.Body className="flex flex-col gap-2">
|
||||||
<Typography variant="small">Domain name</Typography>
|
<Typography variant="small">Domain name</Typography>
|
||||||
<Input {...register('name')} />
|
<Input {...register('name')} />
|
||||||
<Typography variant="small">Redirect to</Typography>
|
{/* <Typography variant="small">Redirect to</Typography>
|
||||||
<Controller
|
<Controller
|
||||||
name="redirectedTo"
|
name="redirectedTo"
|
||||||
control={control}
|
control={control}
|
||||||
@ -161,7 +169,7 @@ const EditDomainDialog = ({
|
|||||||
further.
|
further.
|
||||||
</Typography>
|
</Typography>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)} */}
|
||||||
<Typography variant="small">Git branch</Typography>
|
<Typography variant="small">Git branch</Typography>
|
||||||
<Input
|
<Input
|
||||||
{...register('branch', {
|
{...register('branch', {
|
||||||
@ -169,8 +177,9 @@ const EditDomainDialog = ({
|
|||||||
Boolean(branches.length) ? branches.includes(value) : true,
|
Boolean(branches.length) ? branches.includes(value) : true,
|
||||||
})}
|
})}
|
||||||
disabled={
|
disabled={
|
||||||
!Boolean(branches.length) ||
|
!Boolean(branches.length)
|
||||||
watch('redirectedTo') !== DEFAULT_REDIRECT_OPTIONS[0]
|
// ||
|
||||||
|
// watch('redirectedTo') !== DEFAULT_REDIRECT_OPTIONS[0]
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
{!isValid && (
|
{!isValid && (
|
||||||
|
@ -65,7 +65,7 @@ const SetupDomain = () => {
|
|||||||
Setup domain name
|
Setup domain name
|
||||||
</Heading>
|
</Heading>
|
||||||
<p className="text-slate-500 text-sm font-normal leading-tight">
|
<p className="text-slate-500 text-sm font-normal leading-tight">
|
||||||
Add your domain and setup redirects
|
Add your domain {/* and setup redirects */}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -62,17 +62,15 @@ const Domains = () => {
|
|||||||
headingText="Domains"
|
headingText="Domains"
|
||||||
button={
|
button={
|
||||||
<>
|
<>
|
||||||
{domains.length == 0 && (
|
<Button
|
||||||
<Button
|
as="a"
|
||||||
as="a"
|
href="add"
|
||||||
href="add"
|
variant="secondary"
|
||||||
variant="secondary"
|
leftIcon={<PlusIcon />}
|
||||||
leftIcon={<PlusIcon />}
|
size="md"
|
||||||
size="md"
|
>
|
||||||
>
|
Add domain
|
||||||
Add domain
|
</Button>
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
Loading…
Reference in New Issue
Block a user