Skip to content

Commit

Permalink
fix: finalize user settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
alarv committed Aug 2, 2024
1 parent 3071a50 commit a00d9c4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/app/dashboard/components/UserOrganizations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ const fetcher: Fetcher<ApiResponse<OrganizationDto[]>, string> = async (
if (!res.ok) {
const message = (await res.json()).message;
const status = res.status;
log.warn(message);
if (status >= 500) {
log.error(message);
}
} else {
return res.json();
}

return res.json();
};

const backgroundColors = ['bg-emerald-400', 'bg-amber-400', 'bg-fuchsia-400'];
Expand All @@ -46,9 +48,7 @@ export default function UserOrganizations() {

useEffect(() => {
setIsLoading(true);
trigger()
.catch((e) => log.warn('could not load user organizations', e))
.finally(() => setIsLoading(false));
trigger().finally(() => setIsLoading(false));
}, [trigger]);

let userOrganizations;
Expand Down
5 changes: 4 additions & 1 deletion src/app/dashboard/dashboard-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ export default function DashboardLayout({
const [isCollapsed, setIsCollapsed] = useState<SidebarCollapseStatus>();
const [userSettings, setUserSettings] = useState<
UserSettingsType | undefined
>(getItemFromLocalStorage(generateUserSettingsKey(session)));
>();

useEffect(() => {
if (!userSettings) {
setUserSettings(
getItemFromLocalStorage(generateUserSettingsKey(session)),
);
return;
}
if (userSettings.darkMode) {
Expand Down
1 change: 1 addition & 0 deletions src/app/dashboard/settings/components/UserSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default function UserSettings() {
<div>
<Switch
defaultSelected={userSettings?.darkMode}
isSelected={userSettings?.darkMode ?? false}
onValueChange={(isSelected) => {
setUserSettings({
...userSettings,
Expand Down
2 changes: 1 addition & 1 deletion src/app/util/local-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const log = logger.child({ module: 'localStorageUtil' });

export const getItemFromLocalStorage = (key: string): any | undefined => {
let currentValue;
if (!localStorage) {
if (typeof window === 'undefined') {
return undefined;
}
try {
Expand Down

0 comments on commit a00d9c4

Please sign in to comment.