Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 1x 2x 2x 2x 1x | import React from 'react';
import useSWR from 'swr';
import { fetcher } from '@/helpers';
import styles from './deploymentstatus.module.css';
import Tooltip from '@/components/Tooltip';
import { useIntl } from 'react-intl';
import RenderManager from '@/components/RenderManager';
const url = new URL(`${process.env.NEXT_PUBLIC_DOMAIN}/api/deployments`);
/**
*
* @returns { {data: object, isLoading: boolean, isError: boolean} } - The deployment status
* @description - Fetches the deployment status
* @example - const { data, isLoading, isError } = useDeploymentStatus();
*/
export const useDeploymentStatus = () => {
const { data, error } = useSWR(url, fetcher);
return {
data: data,
isLoading: !error && !data,
isError: error,
};
};
/**
*
* @returns {JSX.Element} - DeploymentStatus component
* @description - Shows the current deployment status
* @example - <DeploymentStatus />
*/
const DeploymentStatus = () => {
const { data, isLoading, isError } = useDeploymentStatus();
const { formatMessage: f } = useIntl();
const { status, username, environment, createdAt } = data ?? {};
return (
<RenderManager error={isError} loading={isLoading}>
<Tooltip>
<Tooltip.Trigger>
<div className={`${styles.status} ${styles[status?.toLowerCase()]}`} />
</Tooltip.Trigger>
<Tooltip.Content>
{f(
{
id: 'deploymentstatus.tooltip',
},
{
status: status,
username: username,
environment: environment,
createdAt: new Date(createdAt).toLocaleString(),
}
)}
</Tooltip.Content>
</Tooltip>
</RenderManager>
);
};
export default DeploymentStatus;
|