import { HStack, Text, SliderTrack, SliderFilledTrack, Slider, SliderProps } from '@chakra-ui/react'; import { resetStrategy } from 'constants/Settings'; import { formatBytes } from 'utils/formatByte'; import { useTranslation } from 'react-i18next'; import { FC } from 'react'; export const UsageSliderCompact: FC = (props) => { const { used, total } = props; const isUnlimited = total === 0 || total === null; return ( {formatBytes(used)} /{' '} {isUnlimited ? ( ∞ ) : ( formatBytes(total) )} ); }; type UsageSliderProps = { used: number; total: number | null; dataLimitResetStrategy: string | null; totalUsedTraffic: number; } & SliderProps; const getResetStrategy = (strategy: string): string => { for (var i = 0; i < resetStrategy.length; i++) { const entry = resetStrategy[i]; if (entry.value == strategy) { return entry.title; } } return 'No'; }; export const UsageSlider: FC = (props) => { const { used, total, dataLimitResetStrategy, totalUsedTraffic, ...restOfProps } = props; const isUnlimited = total === 0 || total === null; const isReached = !isUnlimited && (used / total) * 100 >= 100; const { t } = useTranslation(); return ( <> {formatBytes(used)} /{' '} {isUnlimited ? ( ∞ ) : ( formatBytes(total) + (dataLimitResetStrategy && dataLimitResetStrategy !== 'no_reset' ? ' ' + t( 'userDialog.resetStrategy' + getResetStrategy(dataLimitResetStrategy) ) : '') )} {t('usersTable.total')}: {formatBytes(totalUsedTraffic)} ); };