{
+ setEditDialogOpen((preVal) => !preVal);
+ }}
+ open={editDialogOpen}
+ domain={domain}
+ repo={repo}
+ />
>
);
};
diff --git a/packages/frontend/src/components/projects/project/settings/Domains.tsx b/packages/frontend/src/components/projects/project/settings/Domains.tsx
index 9a5f4428..5676edad 100644
--- a/packages/frontend/src/components/projects/project/settings/Domains.tsx
+++ b/packages/frontend/src/components/projects/project/settings/Domains.tsx
@@ -1,15 +1,25 @@
-import React from 'react';
+import React, { useMemo } from 'react';
import { useParams, Link } from 'react-router-dom';
import { Button, Typography } from '@material-tailwind/react';
import DomainCard from './DomainCard';
-import domainsData from '../../../../assets/domains.json';
import { DomainDetails } from '../../../../types/project';
+import domainsData from '../../../../assets/domains.json';
+import repositories from '../../../../assets/repositories.json';
+import projectData from '../../../../assets/projects.json';
const Domains = () => {
const { id } = useParams();
+ const currProject = useMemo(() => {
+ return projectData.find((data) => data.id === Number(id));
+ }, [id]);
+
+ const linkedRepo = useMemo(() => {
+ return repositories.find((repo) => repo.id === currProject?.repositoryId);
+ }, [currProject]);
+
return (
<>
@@ -21,13 +31,16 @@ const Domains = () => {
- {(domainsData as DomainDetails[])
- .filter((domain) => {
- return Number(id) == domain.projectid;
- })
- .map((domain) => {
- return ;
- })}
+ {(domainsData as DomainDetails[]).map((domain) => {
+ return (
+
+ );
+ })}
>
);
};
diff --git a/packages/frontend/src/components/projects/project/settings/EditDomainDialog.tsx b/packages/frontend/src/components/projects/project/settings/EditDomainDialog.tsx
new file mode 100644
index 00000000..46f820f8
--- /dev/null
+++ b/packages/frontend/src/components/projects/project/settings/EditDomainDialog.tsx
@@ -0,0 +1,153 @@
+import React, { useMemo } from 'react';
+import { Controller, useForm } from 'react-hook-form';
+import toast from 'react-hot-toast';
+
+import {
+ Button,
+ Dialog,
+ DialogHeader,
+ DialogBody,
+ DialogFooter,
+ Input,
+ Typography,
+ Select,
+ Option,
+} from '@material-tailwind/react';
+
+import { DomainDetails, RepositoryDetails } from '../../../../types/project';
+import domains from '../../../../assets/domains.json';
+
+const DEFAULT_REDIRECT_OPTIONS = ['none'];
+
+interface EditDomainDialogProp {
+ open: boolean;
+ handleOpen: () => void;
+ domain: DomainDetails;
+ repo: RepositoryDetails;
+}
+
+const EditDomainDialog = ({
+ open,
+ handleOpen,
+ domain,
+ repo,
+}: EditDomainDialogProp) => {
+ const getRedirectUrl = (domain: DomainDetails) => {
+ const domainArr = domain.name.split('www.');
+ let redirectUrl = '';
+ if (domain.name.startsWith('www.')) {
+ redirectUrl = domainArr[1];
+ } else {
+ redirectUrl = `www.${domainArr[0]}`;
+ }
+ return redirectUrl;
+ };
+
+ const redirectOptions = useMemo(() => {
+ const redirectUrl = getRedirectUrl(domain);
+ return [...DEFAULT_REDIRECT_OPTIONS, redirectUrl];
+ }, [domain]);
+
+ const isDisableDropdown = useMemo(() => {
+ const redirectUrl = getRedirectUrl(domain);
+
+ const domainRedirected = domains.find(
+ (domain) => domain.name === redirectUrl,
+ );
+
+ return domainRedirected?.isRedirectedto;
+ }, [domain]);
+
+ const {
+ handleSubmit,
+ register,
+ control,
+ watch,
+ formState: { isValid, isDirty },
+ } = useForm({
+ defaultValues: {
+ name: domain.name,
+ branch: repo.branch[0],
+ redirectedTo: !domain.isRedirectedto
+ ? redirectOptions[0]
+ : redirectOptions[1],
+ },
+ });
+
+ return (
+
+ );
+};
+
+export default EditDomainDialog;
diff --git a/packages/frontend/src/types/project.ts b/packages/frontend/src/types/project.ts
index a73db6d6..d784ed17 100644
--- a/packages/frontend/src/types/project.ts
+++ b/packages/frontend/src/types/project.ts
@@ -15,6 +15,7 @@ export interface ProjectDetails {
createdAt: string;
branch: string;
};
+ repositoryId: number;
}
export interface DeploymentDetails {
@@ -54,6 +55,7 @@ export interface RepositoryDetails {
updatedAt: string;
user: string;
private: boolean;
+ branch: string[];
}
export enum GitSelect {
@@ -77,4 +79,5 @@ export interface DomainDetails {
name: string;
value: string;
};
+ isRedirectedto: boolean;
}