Repository navigation
Fixed implementation of useAutoUpdateTimezone to ignore delegate and do the check on focus event #84738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
srikarparsi
merged 8 commits into
Expensify:main
from
shubham1206agra:fix-auto-timezone
Apr 16, 2026
Merged
Fixed implementation of useAutoUpdateTimezone to ignore delegate and do the check on focus event #84738
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
03e916f
Fixed implementation of useAutoUpdateTimezone to ignore delegate and …
shubham1206agra 1a98aa6
Fixed test
shubham1206agra 727613f
Merge branch 'Expensify:main' into fix-auto-timezone
shubham1206agra 5b06573
Fixed autoUpdate flow on mount
shubham1206agra 8f04842
Fixed spellcheck
shubham1206agra 5bf1d89
Fixed initial mount case
shubham1206agra 6098e49
Merge branch 'Expensify:main' into fix-auto-timezone
shubham1206agra 71eb62e
Fixed new login case
shubham1206agra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1,26 +1,44 @@ | ||
| import {useEffect} from 'react'; | ||
| import {useEffect, useEffectEvent} from 'react'; | ||
| import DateUtils from '@libs/DateUtils'; | ||
| import {updateAutomaticTimezone} from '@userActions/PersonalDetails'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import {isActingAsDelegateSelector} from '@src/selectors/Account'; | ||
| import type {SelectedTimezone} from '@src/types/onyx/PersonalDetails'; | ||
| import {isEmptyObject} from '@src/types/utils/EmptyObject'; | ||
| import useAppFocusEvent from './useAppFocusEvent'; | ||
| import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails'; | ||
| import useOnyx from './useOnyx'; | ||
|
|
||
| const useAutoUpdateTimezone = () => { | ||
| const [isActingAsDelegate] = useOnyx(ONYXKEYS.ACCOUNT, {selector: isActingAsDelegateSelector}); | ||
| const currentUserPersonalDetails = useCurrentUserPersonalDetails(); | ||
| const timezone = currentUserPersonalDetails?.timezone ?? {}; | ||
| useEffect(() => { | ||
| const isTimezonePresent = !isEmptyObject(timezone); | ||
| const updateTimezone = () => { | ||
| if (isActingAsDelegate) { | ||
| // Do not update timezone if user is acting as a delegate, as the timezone should be based on the primary account holder, not the delegate. | ||
| return; | ||
| } | ||
| const currentTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone as SelectedTimezone; | ||
| const hasValidCurrentTimezone = typeof currentTimezone === 'string' && currentTimezone.trim().length > 0; | ||
| const proposedTimezone = DateUtils.formatToSupportedTimezone({ | ||
| automatic: true, | ||
| selected: currentTimezone, | ||
| }); | ||
|
|
||
| if (hasValidCurrentTimezone && timezone?.automatic && timezone?.selected !== currentTimezone) { | ||
| updateAutomaticTimezone( | ||
| { | ||
| automatic: true, | ||
| selected: currentTimezone, | ||
| }, | ||
| currentUserPersonalDetails.accountID, | ||
| ); | ||
| if (hasValidCurrentTimezone && timezone?.automatic && timezone?.selected !== proposedTimezone.selected) { | ||
| updateAutomaticTimezone(proposedTimezone, currentUserPersonalDetails.accountID); | ||
| } | ||
| }; | ||
| const updateTimezoneEvent = useEffectEvent(updateTimezone); | ||
| useAppFocusEvent(updateTimezone); | ||
|
shubham1206agra marked this conversation as resolved.
Resolved
shubham1206agra marked this conversation as resolved.
Resolved
|
||
| useEffect(() => { | ||
| if (!isTimezonePresent) { | ||
| // If we don't have a timezone, we can't update it, so we should wait until we do before attempting to update it. | ||
| return; | ||
| } | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, [timezone?.automatic, timezone?.selected]); | ||
| updateTimezoneEvent(); | ||
| }, [isTimezonePresent]); | ||
| }; | ||
|
|
||
| export default useAutoUpdateTimezone; | ||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.