@@ -2,6 +2,7 @@ import { useState } from 'react'
22import Select , { SingleValue } from 'react-select'
33import { trackDNDEnable } from 'src/lib/analytics'
44import { useUserPreferences } from 'src/stores/preferences'
5+ import { diffBetweenTwoDatesInMinutes } from 'src/utils/DateUtils'
56
67type DndOption = {
78 value : number | 'always'
@@ -30,10 +31,11 @@ export const DNDSettings = ({ setShowSettings }: DNDSettingsProps) => {
3031 }
3132
3233 if ( typeof selectedDNDDuration === 'string' ) {
33- setDNDDuration ( 'always' )
34+ setDNDDuration ( selectedDNDDuration )
3435 } else {
3536 const value = selectedDNDDuration as number
36- const futureDate = new Date ( new Date ( ) . getTime ( ) + value * 60000 )
37+ const futureDate = new Date ( )
38+ futureDate . setMinutes ( futureDate . getMinutes ( ) + value )
3739 setDNDDuration ( {
3840 value : selectedDNDDuration ,
3941 countdown : futureDate . getTime ( ) ,
@@ -64,6 +66,22 @@ export const DNDSettings = ({ setShowSettings }: DNDSettingsProps) => {
6466 }
6567 }
6668
69+ const timeoutLabel = ( ) : string | undefined => {
70+ if ( typeof DNDDuration === 'object' ) {
71+ const DNDDurationObject = DNDDuration as {
72+ value : number
73+ countdown : number
74+ }
75+ const futureDate = new Date ( DNDDurationObject . countdown )
76+ const now = new Date ( )
77+ return `DND will become inactive in ${ diffBetweenTwoDatesInMinutes (
78+ futureDate . getTime ( ) ,
79+ now . getTime ( )
80+ ) } Minutes`
81+ }
82+
83+ return undefined
84+ }
6785 return (
6886 < div className = "settingRow" >
6987 < p className = "settingTitle" >
@@ -88,6 +106,11 @@ export const DNDSettings = ({ setShowSettings }: DNDSettingsProps) => {
88106
89107 < button onClick = { onApplyClicked } > Apply</ button >
90108 </ div >
109+ { timeoutLabel ( ) && (
110+ < div className = "settingHint" >
111+ < p > { timeoutLabel ( ) } </ p >
112+ </ div >
113+ ) }
91114 </ div >
92115 </ div >
93116 )
0 commit comments