[#339] added API calls to timezone selectors (#396)

Co-authored-by: Camille Moussu <cmoussu@linagora.com>
This commit is contained in:
Camille Moussu
2025-12-07 07:43:00 +01:00
committed by GitHub
parent 7567bfbd7b
commit 1056220719
4 changed files with 310 additions and 32 deletions
+30 -27
View File
@@ -47,7 +47,7 @@ type SettingsSubTab = "settings" | "notifications";
export default function SettingsPage() {
const dispatch = useAppDispatch();
const { t } = useI18n();
// const previousConfig = useAppSelector((state) => state.user.coreConfig);
const previousConfig = useAppSelector((state) => state.user.coreConfig);
const userLanguage = useAppSelector(
(state) => state.user?.coreConfig.language
);
@@ -115,46 +115,49 @@ export default function SettingsPage() {
};
const handleTimeZoneChange = (newTimeZone: string) => {
// const previousTimeZone = currentTimeZone;
const previousTimeZone = currentTimeZone;
// Optimistic update - update UI immediately
dispatch(setUserTimeZone(newTimeZone));
dispatch(setSettingsTimeZone(newTimeZone));
// // Call API in background, don't wait for it
// dispatch(
// updateUserConfigurationsAsync({ timezone: newTimeZone, previousConfig })
// )
// .unwrap()
// .catch((error) => {
// console.error("Failed to update TimeZone:", error);
// // Rollback on error
// dispatch(setUserTimeZone(previousTimeZone));
// dispatch(setSettingsTimeZone(previousTimeZone));
// setTimeZoneErrorOpen(true);
// });
// Call API in background, don't wait for it
dispatch(
updateUserConfigurationsAsync({ timezone: newTimeZone, previousConfig })
)
.unwrap()
.catch((error) => {
console.error("Failed to update TimeZone:", error);
// Rollback on error
dispatch(setUserTimeZone(previousTimeZone));
dispatch(setSettingsTimeZone(previousTimeZone));
setTimeZoneErrorOpen(true);
});
};
const handleTimeZoneDefaultChange = (isDefault: boolean) => {
const previousTimeZone = currentTimeZone;
// Optimistic update - update UI immediately
dispatch(setIsBrowserDefaultTimeZone(isDefault));
if (isDefault) {
dispatch(setUserTimeZone(null));
dispatch(setSettingsTimeZone(browserDefaultTimeZone));
}
// // Call API in background, don't wait for it
// dispatch(
// updateUserConfigurationsAsync({ timezone: newTimeZone, previousConfig })
// )
// .unwrap()
// .catch((error) => {
// console.error("Failed to update TimeZone:", error);
// // Rollback on error
// dispatch(setUserTimeZone(previousTimeZone));
// dispatch(setSettingsTimeZone(previousTimeZone));
// setTimeZoneErrorOpen(true);
// });
// Call API in background, don't wait for it
dispatch(
updateUserConfigurationsAsync({ timezone: null, previousConfig })
)
.unwrap()
.catch((error) => {
console.error("Failed to update TimeZone:", error);
// Rollback on error
dispatch(setUserTimeZone(previousTimeZone));
dispatch(setSettingsTimeZone(previousTimeZone));
dispatch(setIsBrowserDefaultTimeZone(!isDefault));
setTimeZoneErrorOpen(true);
});
}
};
const handleTimeZoneErrorClose = () => {
+1 -1
View File
@@ -37,7 +37,7 @@ export async function getUserDetails(id: string) {
export interface UserConfigurationUpdates {
language?: string;
notifications?: Record<string, unknown>;
timezone?: string;
timezone?: string | null;
previousConfig?: Record<string, any>;
}