import moment, { Moment } from "moment"; import { Box, Step as StepperStep, StepContent, StepLabel, StepProps as StepperStepProps, Typography } from "@material-ui/core"; import { useTranslation } from "react-i18next"; import React, { ReactChild, useMemo } from "react"; import { StepIcon } from "@/components/stepIcon"; type StepProps = StepperStepProps & { until?: Moment; completedOn?: Moment; label: string; state?: ReactChild | null; waiting?: boolean; declined?: boolean; } const now = moment(); export const Step = (props: StepProps) => { const { until, label, completedOn, children, completed = false, declined = false, waiting = false, state = null, ...rest } = props; const { t } = useTranslation(); const isLate = useMemo(() => until?.isBefore(completedOn || now), [completedOn, until]); const left = useMemo(() => moment.duration(now.diff(until)), [until]); return { label } { until && { state && <> { state } } { t('until', { date: until }) } { isLate && - { t('late', { by: moment.duration(now.diff(until)) }) } } { !isLate && !completed && - { t('left', { left: left }) } } } { children && { children } } }