snowballtools-base/packages/frontend/src/components/projects/create/DeployStep.tsx
Nabarun Gogoi ef89d69577
Implement creating project by importing repository (#49)
* Implement create project with import repository

* Add button for creating project in deploy step
2024-02-01 18:10:15 +05:30

89 lines
2.3 KiB
TypeScript

import React, { useState } from 'react';
import toast from 'react-hot-toast';
import { Collapse, Button, Typography } from '@material-tailwind/react';
import { Stopwatch, setStopWatchOffset } from '../../StopWatch';
import FormatMillisecond from '../../FormatMilliSecond';
import processLogs from '../../../assets/process-logs.json';
enum DeployStatus {
PROCESSING = 'progress',
COMPLETE = 'complete',
NOT_STARTED = 'notStarted',
}
interface DeployStepsProps {
status: DeployStatus;
title: string;
step?: string;
startTime?: string;
processTime?: string;
}
const DeployStep = ({
step,
status,
title,
startTime,
processTime,
}: DeployStepsProps) => {
const [collapse, setCollapse] = useState(false);
return (
<div className="border-b-2">
<div className="flex justify-between p-2 gap-2">
{status === DeployStatus.NOT_STARTED && <div>{step}</div>}
{status === DeployStatus.PROCESSING && <div>O</div>}
{status === DeployStatus.COMPLETE && (
<div>
<button
onClick={() => {
setCollapse(!collapse);
}}
>
{collapse ? '-' : '+'}
</button>
</div>
)}
<div className="grow">{title}</div>
{status === DeployStatus.PROCESSING && (
<>
^<Stopwatch offsetTimestamp={setStopWatchOffset(startTime!)} />
</>
)}
{status === DeployStatus.COMPLETE && (
<>
^<FormatMillisecond time={Number(processTime)} />{' '}
</>
)}
</div>
<Collapse open={collapse}>
<div className="p-2 text-sm text-gray-500 h-36 overflow-y-scroll">
{processLogs.map((log, key) => {
return (
<Typography variant="small" color="gray" key={key}>
{log}
</Typography>
);
})}
<div className="sticky bottom-0 left-1/2 flex justify-center">
<Button
size="sm"
onClick={() => {
navigator.clipboard.writeText(processLogs.join('\n'));
toast.success('Logs copied');
}}
color="blue"
>
^ Copy log
</Button>
</div>
</div>
</Collapse>
</div>
);
};
export { DeployStep, DeployStatus };