11import { useEffect } from 'react' ;
22import useAutoUpdateTimezone from '@hooks/useAutoUpdateTimezone' ;
33import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails' ;
4- import * as User from '@userActions/User' ;
4+ import { clearCustomStatus , clearDraftCustomStatus } from '@userActions/User' ;
55import CONST from '@src/CONST' ;
66
7- function clearStatus ( currentUserAccountID : number ) {
8- User . clearCustomStatus ( currentUserAccountID ) ;
9- User . clearDraftCustomStatus ( ) ;
10- }
11-
127/**
138 * Component that does not render anything and owns the timezone auto-update logic and
149 * the status-clear timer effect.
@@ -21,11 +16,15 @@ function UserStatusHandler() {
2116
2217 const currentUserPersonalDetails = useCurrentUserPersonalDetails ( ) ;
2318
19+ const clearStatus = ( ) => {
20+ clearCustomStatus ( currentUserPersonalDetails . accountID ) ;
21+ clearDraftCustomStatus ( ) ;
22+ } ;
23+
2424 useEffect ( ( ) => {
2525 if ( ! currentUserPersonalDetails . status ?. clearAfter ) {
2626 return ;
2727 }
28- const currentUserAccountID = currentUserPersonalDetails . accountID ;
2928 const currentTime = new Date ( ) ;
3029 const clearAfterTime = new Date ( currentUserPersonalDetails . status . clearAfter ) ;
3130 if ( Number . isNaN ( clearAfterTime . getTime ( ) ) ) {
@@ -42,7 +41,7 @@ function UserStatusHandler() {
4241 const remainingTime = clearAfterTime . getTime ( ) - now . getTime ( ) ;
4342
4443 if ( remainingTime <= 0 ) {
45- clearStatus ( currentUserAccountID ) ;
44+ clearStatus ( ) ;
4645 if ( intervalId ) {
4746 clearInterval ( intervalId ) ;
4847 }
@@ -51,13 +50,13 @@ function UserStatusHandler() {
5150 clearInterval ( intervalId ) ;
5251 }
5352 timeoutId = setTimeout ( ( ) => {
54- clearStatus ( currentUserAccountID ) ;
53+ clearStatus ( ) ;
5554 } , remainingTime ) ;
5655 }
5756 } , CONST . LIMIT_TIMEOUT ) ;
5857 } else {
5958 timeoutId = setTimeout ( ( ) => {
60- clearStatus ( currentUserAccountID ) ;
59+ clearStatus ( ) ;
6160 } , subMillisecondsTime ) ;
6261 }
6362
@@ -71,8 +70,8 @@ function UserStatusHandler() {
7170 } ;
7271 }
7372
74- clearStatus ( currentUserAccountID ) ;
75- } , [ currentUserPersonalDetails . accountID , currentUserPersonalDetails . status ?. clearAfter ] ) ;
73+ clearStatus ( ) ;
74+ } , [ clearStatus , currentUserPersonalDetails . status ?. clearAfter ] ) ;
7675
7776 return null ;
7877}
0 commit comments