-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8037d36
commit e4dbe17
Showing
11 changed files
with
148 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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,5 +1,29 @@ | ||
"use client"; | ||
|
||
import { useEffect, useState } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
import DashboardPageWrapper from "@/layouts/dashboard/DashboardPageWrapper"; | ||
import services from "@/services"; | ||
import { User } from "@/types/user"; | ||
import UserSettings from "@/layouts/user/UserSettings"; | ||
|
||
const UserPage = () => { | ||
const [userData, setUserData] = useState<User | null>(null); | ||
const { t } = useTranslation(); | ||
|
||
useEffect(() => { | ||
(async () => { | ||
const userProfile = await services.user.getProfile(); | ||
setUserData(userProfile.data); | ||
})(); | ||
}, []); | ||
|
||
const UserPage = () => <DashboardPageWrapper title="User settings" />; | ||
return ( | ||
<DashboardPageWrapper title={t("user.settings.title")}> | ||
{userData && <UserSettings user={userData} />} | ||
</DashboardPageWrapper> | ||
); | ||
}; | ||
|
||
export default UserPage; |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useEffect, useState } from "react"; | ||
|
||
const useSystemTheme = (): "dark" | "light" => { | ||
if (typeof window === "undefined") return "dark"; | ||
const getCurrentTheme = () => window.matchMedia("(prefers-color-scheme: dark)").matches; | ||
const [isDarkTheme, setIsDarkTheme] = useState(getCurrentTheme()); | ||
const mqListener = (e: MediaQueryListEvent) => { | ||
setIsDarkTheme(e.matches); | ||
}; | ||
|
||
useEffect(() => { | ||
const darkThemeMq = window.matchMedia("(prefers-color-scheme: dark)"); | ||
darkThemeMq.addEventListener("change", mqListener); | ||
return () => darkThemeMq.removeEventListener("change", mqListener); | ||
}, []); | ||
return isDarkTheme ? "dark" : "light"; | ||
}; | ||
|
||
export default useSystemTheme; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { useTranslation } from "react-i18next"; | ||
import { User } from "@/types/user"; | ||
|
||
type UserSettingsProps = { | ||
user: User; | ||
}; | ||
const UserSettings = ({ user }: UserSettingsProps) => { | ||
const { t } = useTranslation(); | ||
|
||
return ( | ||
<div className="w-fit ml-4"> | ||
<div> | ||
<label className="label"> | ||
<span className="text-primary label-text">{t("auth.fields.email")}</span> | ||
</label> | ||
<input type="text" value={user.email} className="input input-bordered input-primary bg-neutral" /> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default UserSettings; |
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { getProfile, updateProfile } from "@/services/user/me"; | ||
|
||
const userService = { | ||
getProfile, | ||
updateProfile, | ||
}; | ||
|
||
export default userService; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { axiosInstance } from "@/services"; | ||
import { SERVICE_ERROR_UNKNOWN } from "@/config/services"; | ||
import { ServiceReturn } from "@/types/api"; | ||
import { User, UserProfileUpdate } from "@/types/user"; | ||
|
||
const getProfile = async (): Promise<ServiceReturn<User>> => { | ||
try { | ||
const response = await axiosInstance.get<User>(`/me`); | ||
return { data: response.data, error: undefined }; | ||
} catch (error) { | ||
return { data: null, error: SERVICE_ERROR_UNKNOWN }; | ||
} | ||
}; | ||
|
||
const updateProfile = async (data: UserProfileUpdate): Promise<ServiceReturn<void>> => { | ||
try { | ||
const response = await axiosInstance.patch(`/me`, data); | ||
return { data: response.data, error: undefined }; | ||
} catch (error) { | ||
return { data: null, error: SERVICE_ERROR_UNKNOWN }; | ||
} | ||
}; | ||
|
||
export { getProfile, updateProfile }; |
This file contains 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 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