2023-11-02 18:27:44 +00:00
|
|
|
import { useEffect, useState, ReactElement } from "react";
|
2024-05-08 17:31:20 +00:00
|
|
|
import { observer } from "mobx-react";
|
2023-10-17 07:16:38 +00:00
|
|
|
import { useTheme } from "next-themes";
|
2023-05-11 13:10:17 +00:00
|
|
|
// ui
|
2024-05-15 16:39:16 +00:00
|
|
|
import { setPromiseToast } from "@plane/ui";
|
2024-03-06 13:09:14 +00:00
|
|
|
// components
|
2024-05-15 16:39:16 +00:00
|
|
|
import { LogoSpinner } from "@/components/common";
|
2024-03-19 14:38:35 +00:00
|
|
|
import { CustomThemeSelector, ThemeSwitch, PageHead } from "@/components/core";
|
2023-10-17 07:16:38 +00:00
|
|
|
// constants
|
2024-03-19 14:38:35 +00:00
|
|
|
import { I_THEME_OPTION, THEME_OPTIONS } from "@/constants/themes";
|
2024-03-06 13:09:14 +00:00
|
|
|
// hooks
|
2024-05-08 17:31:20 +00:00
|
|
|
import { useUserProfile } from "@/hooks/store";
|
2024-03-06 13:09:14 +00:00
|
|
|
// layouts
|
2024-03-19 14:38:35 +00:00
|
|
|
import { ProfilePreferenceSettingsLayout } from "@/layouts/settings-layout/profile/preferences";
|
2023-11-02 18:27:44 +00:00
|
|
|
// type
|
2024-03-19 14:38:35 +00:00
|
|
|
import { NextPageWithLayout } from "@/lib/types";
|
2023-08-10 07:33:42 +00:00
|
|
|
|
2024-01-23 12:19:22 +00:00
|
|
|
const ProfilePreferencesThemePage: NextPageWithLayout = observer(() => {
|
2024-05-08 17:31:20 +00:00
|
|
|
const { setTheme } = useTheme();
|
2023-10-17 07:16:38 +00:00
|
|
|
// states
|
|
|
|
const [currentTheme, setCurrentTheme] = useState<I_THEME_OPTION | null>(null);
|
|
|
|
// hooks
|
2024-05-08 17:31:20 +00:00
|
|
|
const { data: userProfile, updateUserTheme } = useUserProfile();
|
2023-08-03 09:31:31 +00:00
|
|
|
|
2023-05-11 13:10:17 +00:00
|
|
|
useEffect(() => {
|
2024-05-08 17:31:20 +00:00
|
|
|
if (userProfile?.theme?.theme) {
|
|
|
|
const userThemeOption = THEME_OPTIONS.find((t) => t.value === userProfile?.theme?.theme);
|
2023-10-17 07:16:38 +00:00
|
|
|
if (userThemeOption) {
|
|
|
|
setCurrentTheme(userThemeOption);
|
|
|
|
}
|
2023-05-11 13:10:17 +00:00
|
|
|
}
|
2024-05-08 17:31:20 +00:00
|
|
|
}, [userProfile?.theme?.theme]);
|
2023-05-11 13:10:17 +00:00
|
|
|
|
2023-10-17 07:16:38 +00:00
|
|
|
const handleThemeChange = (themeOption: I_THEME_OPTION) => {
|
|
|
|
setTheme(themeOption.value);
|
2024-05-08 17:31:20 +00:00
|
|
|
const updateCurrentUserThemePromise = updateUserTheme({ theme: themeOption.value });
|
2024-03-06 08:48:41 +00:00
|
|
|
|
|
|
|
setPromiseToast(updateCurrentUserThemePromise, {
|
|
|
|
loading: "Updating theme...",
|
|
|
|
success: {
|
|
|
|
title: "Success!",
|
|
|
|
message: () => "Theme updated successfully!",
|
|
|
|
},
|
|
|
|
error: {
|
|
|
|
title: "Error!",
|
|
|
|
message: () => "Failed to Update the theme",
|
|
|
|
},
|
2023-10-17 07:16:38 +00:00
|
|
|
});
|
|
|
|
};
|
2023-09-15 09:33:32 +00:00
|
|
|
|
2023-10-17 07:16:38 +00:00
|
|
|
return (
|
2023-11-02 18:27:44 +00:00
|
|
|
<>
|
2024-02-20 08:06:38 +00:00
|
|
|
<PageHead title="Profile - Theme Prefrence" />
|
2024-05-08 17:31:20 +00:00
|
|
|
{userProfile ? (
|
2024-04-29 07:29:49 +00:00
|
|
|
<div className="mx-auto mt-10 h-full w-full overflow-y-auto md:px-6 px-4 pb-8 md:mt-14 lg:px-20 vertical-scrollbar scrollbar-md">
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="flex items-center border-b border-custom-border-100 pb-3.5">
|
2023-11-02 18:27:44 +00:00
|
|
|
<h3 className="text-xl font-medium">Preferences</h3>
|
|
|
|
</div>
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="grid grid-cols-12 gap-4 py-6 sm:gap-16">
|
2023-11-02 18:27:44 +00:00
|
|
|
<div className="col-span-12 sm:col-span-6">
|
|
|
|
<h4 className="text-lg font-semibold text-custom-text-100">Theme</h4>
|
|
|
|
<p className="text-sm text-custom-text-200">Select or customize your interface color scheme.</p>
|
2023-09-15 09:33:32 +00:00
|
|
|
</div>
|
2023-11-02 18:27:44 +00:00
|
|
|
<div className="col-span-12 sm:col-span-6">
|
|
|
|
<ThemeSwitch value={currentTheme} onChange={handleThemeChange} />
|
2023-05-11 13:10:17 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2024-05-08 17:31:20 +00:00
|
|
|
{userProfile?.theme?.theme === "custom" && <CustomThemeSelector />}
|
2023-11-02 18:27:44 +00:00
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className="grid h-full w-full place-items-center px-4 sm:px-0">
|
2024-05-15 16:39:16 +00:00
|
|
|
<LogoSpinner />
|
2023-11-02 18:27:44 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</>
|
2023-05-11 13:10:17 +00:00
|
|
|
);
|
2023-08-10 07:33:42 +00:00
|
|
|
});
|
2023-05-11 13:10:17 +00:00
|
|
|
|
2024-01-23 12:19:22 +00:00
|
|
|
ProfilePreferencesThemePage.getLayout = function getLayout(page: ReactElement) {
|
|
|
|
return <ProfilePreferenceSettingsLayout>{page}</ProfilePreferenceSettingsLayout>;
|
2023-11-02 18:27:44 +00:00
|
|
|
};
|
|
|
|
|
2024-01-23 12:19:22 +00:00
|
|
|
export default ProfilePreferencesThemePage;
|