From 239df3661e127c03a3c5537dd342986d8c5788da Mon Sep 17 00:00:00 2001 From: Wahyu Kurniawan Date: Tue, 27 Feb 2024 20:38:51 +0700 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20feat:=20create=20project?= =?UTF-8?q?=20card=20component?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/projects/ProjectCard.tsx | 71 ----------- .../projects/ProjectCard/ProjectCard.theme.ts | 70 +++++++++++ .../projects/ProjectCard/ProjectCard.tsx | 119 ++++++++++++++++++ .../components/projects/ProjectCard/index.ts | 1 + .../frontend/src/pages/org-slug/index.tsx | 2 +- 5 files changed, 191 insertions(+), 72 deletions(-) delete mode 100644 packages/frontend/src/components/projects/ProjectCard.tsx create mode 100644 packages/frontend/src/components/projects/ProjectCard/ProjectCard.theme.ts create mode 100644 packages/frontend/src/components/projects/ProjectCard/ProjectCard.tsx create mode 100644 packages/frontend/src/components/projects/ProjectCard/index.ts diff --git a/packages/frontend/src/components/projects/ProjectCard.tsx b/packages/frontend/src/components/projects/ProjectCard.tsx deleted file mode 100644 index 157a0ed4..00000000 --- a/packages/frontend/src/components/projects/ProjectCard.tsx +++ /dev/null @@ -1,71 +0,0 @@ -import React from 'react'; -import { Link } from 'react-router-dom'; -import { Project } from 'gql-client'; - -import { - Menu, - MenuHandler, - MenuList, - MenuItem, - Typography, - Avatar, -} from '@material-tailwind/react'; - -import { relativeTimeMs } from '../../utils/time'; - -interface ProjectCardProps { - project: Project; -} - -const ProjectCard: React.FC = ({ project }) => { - return ( -
-
- -
- - {project.name} - - {project.deployments[0]?.domain?.name ?? - 'No Production Deployment'} - - -
- - - - - - ^ Project settings - - ^ Delete project - - - -
-
- {project.deployments.length > 0 ? ( - <> - - ^ {project.deployments[0].commitMessage} - - - {relativeTimeMs(project.deployments[0].createdAt)} on ^  - {project.deployments[0].branch} - - - ) : ( - - No Production deployment - - )} -
-
- ); -}; - -export default ProjectCard; diff --git a/packages/frontend/src/components/projects/ProjectCard/ProjectCard.theme.ts b/packages/frontend/src/components/projects/ProjectCard/ProjectCard.theme.ts new file mode 100644 index 00000000..81f0e67c --- /dev/null +++ b/packages/frontend/src/components/projects/ProjectCard/ProjectCard.theme.ts @@ -0,0 +1,70 @@ +import { VariantProps, tv } from 'tailwind-variants'; + +export const projectCardTheme = tv({ + slots: { + wrapper: [ + 'bg-surface-card', + 'shadow-card', + 'rounded-2xl', + 'flex', + 'flex-col', + ], + upperContent: ['px-4', 'py-4', 'flex', 'items-start', 'gap-3', 'relative'], + content: ['flex', 'flex-col', 'gap-1', 'flex-1'], + title: [ + 'text-sm', + 'font-medium', + 'text-elements-high-em', + 'tracking-[-0.006em]', + ], + description: ['text-xs', 'text-elements-low-em'], + lowerContent: [ + 'bg-surface-card-hovered', + 'px-4', + 'py-4', + 'flex', + 'flex-col', + 'gap-2', + 'rounded-b-2xl', + ], + latestDeployment: ['flex', 'items-center', 'gap-2'], + deploymentStatusContainer: [ + 'h-3', + 'w-3', + 'flex', + 'items-center', + 'justify-center', + ], + deploymentStatus: ['w-1', 'h-1', 'rounded-full'], + deploymentName: ['text-xs', 'text-elements-low-em'], + deploymentText: [ + 'text-xs', + 'text-elements-low-em', + 'font-jetbrains-mono', + 'flex', + 'items-center', + 'gap-2', + ], + }, + variants: { + status: { + success: { + deploymentStatus: ['bg-emerald-500'], + }, + 'in-progress': { + deploymentStatus: ['bg-orange-400'], + }, + failure: { + deploymentStatus: ['bg-rose-500'], + }, + pending: { + deploymentStatus: ['bg-gray-500'], + }, + }, + }, + defaultVariants: { + status: 'pending', + }, +}); + +export type ProjectCardTheme = VariantProps; diff --git a/packages/frontend/src/components/projects/ProjectCard/ProjectCard.tsx b/packages/frontend/src/components/projects/ProjectCard/ProjectCard.tsx new file mode 100644 index 00000000..0ebfd255 --- /dev/null +++ b/packages/frontend/src/components/projects/ProjectCard/ProjectCard.tsx @@ -0,0 +1,119 @@ +import React, { ComponentPropsWithoutRef, MouseEvent } from 'react'; +import { ProjectCardTheme, projectCardTheme } from './ProjectCard.theme'; +import { Project } from 'gql-client'; +import { Button } from 'components/shared/Button'; +import { WavyBorder } from 'components/shared/WavyBorder'; +import { + BranchIcon, + ClockIcon, + GitHubLogo, + HorizontalDotIcon, +} from 'components/shared/CustomIcon'; +import { relativeTimeMs } from 'utils/time'; +import { Link } from 'react-router-dom'; +import { Avatar } from 'components/shared/Avatar'; +import { getInitials } from 'utils/geInitials'; +import { + Menu, + MenuHandler, + MenuItem, + MenuList, +} from '@material-tailwind/react'; + +export interface ProjectCardProps + extends ComponentPropsWithoutRef<'div'>, + ProjectCardTheme { + project: Project; +} + +export const ProjectCard = ({ + className, + project, + status, + ...props +}: ProjectCardProps) => { + const theme = projectCardTheme(); + const hasDeployment = project.deployments.length > 0; + console.log(project); + const handleOptionsClick = ( + e: MouseEvent, + ) => { + e.stopPropagation(); + }; + + return ( +
+ {/* Upper content */} +
+ {/* Icon container */} + + {/*
*/} + {/* Title and website */} + +

{project.name}

+

+ {project.deployments[0]?.domain?.name ?? 'No domain'} +

+ + {/* Dot icon */} + {/* // TODO: Add popover menu here */} + + + + + + Project settings + + Delete project + + + +
+ {/* Wave */} + + {/* Lower content */} +
+ {/* Latest deployment */} +
+ {/* Dot icon */} +
+
+
+

+ {hasDeployment + ? project.deployments[0]?.commitMessage + : 'No production deployment'} +

+
+ {/* Deployment and branch name */} +
+ {hasDeployment ? ( + <> + + {relativeTimeMs(project.deployments[0].createdAt)} on + + {project.deployments[0].branch} + + ) : ( + <> + + Created {relativeTimeMs(project.createdAt)} + + )} +
+
+
+ ); +}; diff --git a/packages/frontend/src/components/projects/ProjectCard/index.ts b/packages/frontend/src/components/projects/ProjectCard/index.ts new file mode 100644 index 00000000..c9169b8b --- /dev/null +++ b/packages/frontend/src/components/projects/ProjectCard/index.ts @@ -0,0 +1 @@ +export * from './ProjectCard'; diff --git a/packages/frontend/src/pages/org-slug/index.tsx b/packages/frontend/src/pages/org-slug/index.tsx index 8fed8636..406c7639 100644 --- a/packages/frontend/src/pages/org-slug/index.tsx +++ b/packages/frontend/src/pages/org-slug/index.tsx @@ -5,9 +5,9 @@ import { Button } from 'components/shared/Button'; import { Typography, Chip } from '@material-tailwind/react'; -import ProjectCard from '../../components/projects/ProjectCard'; import { useGQLClient } from '../../context/GQLClientContext'; import { PlusIcon } from 'components/shared/CustomIcon'; +import { ProjectCard } from 'components/projects/ProjectCard'; const Projects = () => { const client = useGQLClient();