From 7ba390d59b4861e103312d08ebe2f27f54fdc9d9 Mon Sep 17 00:00:00 2001 From: Nabarun Gogoi Date: Thu, 28 Dec 2023 14:14:20 +0530 Subject: [PATCH] Implement domains list in project settings tab (#35) * Display pending domains card in domain layout * Rename variables * Refactor fields in domains json --------- Co-authored-by: neeraj --- packages/frontend/src/assets/domains.json | 29 ++++++- .../projects/project/settings/DomainCard.tsx | 82 +++++++++++++++++-- .../projects/project/settings/Domains.tsx | 13 +-- packages/frontend/src/types/project.ts | 17 ++++ 4 files changed, 121 insertions(+), 20 deletions(-) diff --git a/packages/frontend/src/assets/domains.json b/packages/frontend/src/assets/domains.json index 1cff7a29..8017e914 100644 --- a/packages/frontend/src/assets/domains.json +++ b/packages/frontend/src/assets/domains.json @@ -1,8 +1,31 @@ [ { - "domainid": 1, + "id": 1, "projectid": 1, - "domain": "randomurl.snowballtools.xyz", - "status": "live" + "name": "randomurl.snowballtools.xyz", + "status": "live", + "record": null + }, + { + "id": 2, + "projectid": 1, + "name": "saugatt.com", + "status": "pending", + "record": { + "type": "A", + "name": "@", + "value": "56.49.19.21" + } + }, + { + "id": 3, + "projectid": 1, + "name": "www.saugatt.com", + "status": "pending", + "record": { + "type": "CNAME", + "name": "www", + "value": "cname.snowballtools.xyz" + } } ] diff --git a/packages/frontend/src/components/projects/project/settings/DomainCard.tsx b/packages/frontend/src/components/projects/project/settings/DomainCard.tsx index 6f3d9374..1621475b 100644 --- a/packages/frontend/src/components/projects/project/settings/DomainCard.tsx +++ b/packages/frontend/src/components/projects/project/settings/DomainCard.tsx @@ -1,4 +1,5 @@ -import React from 'react'; +import React, { useState } from 'react'; + import { Chip, Typography, @@ -6,28 +7,55 @@ import { MenuHandler, MenuList, MenuItem, + Card, } from '@material-tailwind/react'; -const DomainCard = (props: { domain: string; status: string }) => { +import { DomainDetails, DomainStatus } from '../../../../types/project'; + +enum RefreshStatus { + IDLE, + CHECKING, + CHECK_SUCCESS, + CHECK_FAIL, +} + +interface DomainCardProps { + domain: DomainDetails; +} + +const CHECK_FAIL_TIMEOUT = 5000; // In milliseconds + +const DomainCard = ({ domain }: DomainCardProps) => { + const [refreshStatus, SetRefreshStatus] = useState(RefreshStatus.IDLE); + return ( <>
- ^ {props.domain} + ^ {domain.name} ^} />
- - ^ + { + SetRefreshStatus(RefreshStatus.CHECKING); + setTimeout(() => { + SetRefreshStatus(RefreshStatus.CHECK_FAIL); + }, CHECK_FAIL_TIMEOUT); + }} + > + {refreshStatus === RefreshStatus.CHECKING ? 'L' : 'R'} @@ -41,6 +69,44 @@ const DomainCard = (props: { domain: string; status: string }) => {
Production + {domain.status === DomainStatus.PENDING && ( + + {refreshStatus === RefreshStatus.IDLE ? ( + + ^ Add these records to your domain and refresh to check + + ) : refreshStatus === RefreshStatus.CHECKING ? ( + + ^ Checking records for {domain.name} + + ) : ( +
+
^
+
+ Failed to verify records. DNS propagation can take up to 48 + hours. Please ensure you added the correct records and refresh. +
+
+ )} + + + + + + + + + + + + + + + + +
TypeNameValue
{domain.record.type}{domain.record.name}{domain.record.value}
+
+ )} ); }; diff --git a/packages/frontend/src/components/projects/project/settings/Domains.tsx b/packages/frontend/src/components/projects/project/settings/Domains.tsx index e2709d61..d706a095 100644 --- a/packages/frontend/src/components/projects/project/settings/Domains.tsx +++ b/packages/frontend/src/components/projects/project/settings/Domains.tsx @@ -4,6 +4,7 @@ import { Button, Typography } from '@material-tailwind/react'; import DomainCard from './DomainCard'; import domainsData from '../../../../assets/domains.json'; +import { DomainDetails } from '../../../../types/project'; const Domains = () => { const { id } = useParams(); @@ -11,7 +12,7 @@ const Domains = () => { return ( <>
- Domain + Domain
- {domainsData + {(domainsData as DomainDetails[]) .filter((domain) => { return Number(id) == domain.projectid; }) .map((domain) => { - return ( - - ); + return ; })} ); diff --git a/packages/frontend/src/types/project.ts b/packages/frontend/src/types/project.ts index 7fe677f9..a73db6d6 100644 --- a/packages/frontend/src/types/project.ts +++ b/packages/frontend/src/types/project.ts @@ -61,3 +61,20 @@ export enum GitSelect { GITEA = 'gitea', NONE = 'none', } + +export enum DomainStatus { + LIVE = 'live', + PENDING = 'pending', +} + +export interface DomainDetails { + id: number; + projectid: number; + name: string; + status: DomainStatus; + record: { + type: string; + name: string; + value: string; + }; +}