diff --git a/src/pages/RepoPage/shared/components/CommitInfo/CommitInfo.tsx b/src/pages/RepoPage/shared/components/CommitInfo/CommitInfo.tsx new file mode 100644 index 0000000000..2b4bd2b58e --- /dev/null +++ b/src/pages/RepoPage/shared/components/CommitInfo/CommitInfo.tsx @@ -0,0 +1,74 @@ +import { useMemo } from 'react' + +import { cn } from 'shared/utils/cn' + +interface CommitInfoProps { + commitSha: string + author: string + message: string + timestamp: number + branch: string + ciPassed?: boolean +} + +export function CommitInfo({ + commitSha, + author, + message, + timestamp, + branch, + ciPassed, +}: CommitInfoProps) { + const shortSha = useMemo(() => commitSha.slice(0, 7), [commitSha]) + + const authorDisplay = useMemo( + () => `${author} on ${branch}`, + [author, branch] + ) + + const formattedDate = useMemo(() => { + return new Date(timestamp).toLocaleDateString() + }, [timestamp]) + + const statusText = useMemo(() => { + return ciPassed ? 'Passed' : 'Failed' + }, [ciPassed]) + + const statusClassName = useMemo( + () => + cn( + 'rounded px-2 py-1 text-xs font-semibold', + ciPassed + ? 'bg-ds-primary-green text-white' + : 'bg-ds-primary-red text-white' + ), + [ciPassed] + ) + + const truncatedMessage = useMemo(() => { + return message.length > 50 ? message.slice(0, 50) + '...' : message + }, [message]) + + return ( +
+ {shortSha}
+
+ {ciPassed !== undefined && (
+ {statusText}
+ )}
+ {truncatedMessage}
+{authorDisplay}
+