-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'recovery-epic' into edit-recovery-flow
- Loading branch information
Showing
42 changed files
with
1,854 additions
and
383 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { _getCountdown } from '.' | ||
|
||
describe('getCountdown', () => { | ||
it('should convert 0 seconds to 0 days, 0 hours, and 0 minutes', () => { | ||
const result = _getCountdown(0) | ||
expect(result).toEqual({ days: 0, hours: 0, minutes: 0 }) | ||
}) | ||
|
||
it('should convert 3600 seconds to 0 days, 1 hour, and 0 minutes', () => { | ||
const result = _getCountdown(3600) | ||
expect(result).toEqual({ days: 0, hours: 1, minutes: 0 }) | ||
}) | ||
|
||
it('should convert 86400 seconds to 1 day, 0 hours, and 0 minutes', () => { | ||
const result = _getCountdown(86400) | ||
expect(result).toEqual({ days: 1, hours: 0, minutes: 0 }) | ||
}) | ||
|
||
it('should convert 123456 seconds to 1 day, 10 hours, and 17 minutes', () => { | ||
const result = _getCountdown(123456) | ||
expect(result).toEqual({ days: 1, hours: 10, minutes: 17 }) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Typography, Box } from '@mui/material' | ||
import type { ReactElement } from 'react' | ||
|
||
export function _getCountdown(seconds: number): { days: number; hours: number; minutes: number } { | ||
const MINUTE_IN_SECONDS = 60 | ||
const HOUR_IN_SECONDS = 60 * MINUTE_IN_SECONDS | ||
const DAY_IN_SECONDS = 24 * HOUR_IN_SECONDS | ||
|
||
const days = Math.floor(seconds / DAY_IN_SECONDS) | ||
|
||
const remainingSeconds = seconds % DAY_IN_SECONDS | ||
const hours = Math.floor(remainingSeconds / HOUR_IN_SECONDS) | ||
const minutes = Math.floor((remainingSeconds % HOUR_IN_SECONDS) / MINUTE_IN_SECONDS) | ||
|
||
return { days, hours, minutes } | ||
} | ||
|
||
export function Countdown({ seconds }: { seconds: number }): ReactElement | null { | ||
if (seconds <= 0) { | ||
return null | ||
} | ||
|
||
const { days, hours, minutes } = _getCountdown(seconds) | ||
|
||
return ( | ||
<Box display="flex" gap={1}> | ||
<TimeLeft value={days} unit="day" /> | ||
<TimeLeft value={hours} unit="hr" /> | ||
<TimeLeft value={minutes} unit="min" /> | ||
</Box> | ||
) | ||
} | ||
|
||
function TimeLeft({ value, unit }: { value: number; unit: string }): ReactElement | null { | ||
if (value === 0) { | ||
return null | ||
} | ||
|
||
return ( | ||
<div> | ||
<Typography fontWeight={700} component="span"> | ||
{value} | ||
</Typography>{' '} | ||
<Typography color="primary.light" component="span"> | ||
{value === 1 ? unit : `${unit}s`} | ||
</Typography> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.