();
+ const form = profileForm({user, editPassword});
+
+ useEffect(() => {
+ if (editResult.isError) {
+ if (editResult.error.status === 403)
+ editProfileErrorNotification(editResult.data.message);
+ } else if (editResult.isSuccess) {
+ editProfileNotification();
+ form.reset();
+ refetch();
+ }
+ }, [editResult])
+
+ return userId ? (
+
+
+
+ ) : ;
+}
+
+export default UserProfile;
\ No newline at end of file
diff --git a/src/features/home/user/userProfile/index.tsx b/src/features/home/user/userProfile/index.tsx
new file mode 100644
index 0000000..ed92319
--- /dev/null
+++ b/src/features/home/user/userProfile/index.tsx
@@ -0,0 +1 @@
+export { default } from "./UserProfile";
\ No newline at end of file
diff --git a/src/features/home/user/userProfile/utils/profileForm.ts b/src/features/home/user/userProfile/utils/profileForm.ts
new file mode 100644
index 0000000..9063929
--- /dev/null
+++ b/src/features/home/user/userProfile/utils/profileForm.ts
@@ -0,0 +1,26 @@
+import { isEmail, useForm } from "@mantine/form";
+
+import { UserInfos } from "store/api/types/fetchedData";
+
+interface Props {
+ user: UserInfos;
+ editPassword: boolean;
+}
+
+export const profileForm = ({user, editPassword}: Props) => {
+ return useForm({
+ initialValues: {
+ firstname: user.firstname,
+ lastname: user.lastname,
+ email: user.email,
+ password: '',
+ role: user.role,
+ },
+ validate: {
+ firstname: (value) => (value.length < 2 ? 'Part name must have at least 2 letters' : null),
+ lastname: (value) => (value.length < 2 ? 'Part name must have at least 2 letters' : null),
+ email: isEmail(),
+ password: (value) => (value.length < 6 && editPassword === true ? 'Part name must have at least 6 characters' : null),
+ },
+ });
+}
\ No newline at end of file
diff --git a/src/pages/home/profile.tsx b/src/pages/home/profile.tsx
new file mode 100644
index 0000000..350271a
--- /dev/null
+++ b/src/pages/home/profile.tsx
@@ -0,0 +1,23 @@
+import { Button, Container, Group } from "@mantine/core";
+
+import CustomLoader from "components/loader/CustomLoader";
+import UserProfile from "features/home/user/userProfile";
+
+import { useGetUserInfos } from "hooks/api/useGetUserInfos";
+import Head from "next/head";
+
+const Profile = () => {
+ const { data: user, refetch } = useGetUserInfos();
+
+ return user ? (
+
+
WAP | Profile
+
+ Profile
+
+
+
+ ) : ;
+}
+
+export default Profile;
\ No newline at end of file
diff --git a/src/store/api/authAPI.ts b/src/store/api/authAPI.ts
index 630635e..40430cd 100644
--- a/src/store/api/authAPI.ts
+++ b/src/store/api/authAPI.ts
@@ -1,6 +1,6 @@
import { wapAPI } from "./wapAPI";
-import { User } from "./types/fetchedData";
+import { User, UserInfos } from "./types/fetchedData";
import { Login } from "./types/queryParams";
const authApi = wapAPI.injectEndpoints({
@@ -15,7 +15,7 @@ const authApi = wapAPI.injectEndpoints({
}
}),
}),
- userInfos: build.query({
+ userInfos: build.query({
query: (id) => ({
url: `users/${id}`,
method: 'GET',
diff --git a/src/store/api/types/fetchedData.ts b/src/store/api/types/fetchedData.ts
index 9f455eb..4b75066 100644
--- a/src/store/api/types/fetchedData.ts
+++ b/src/store/api/types/fetchedData.ts
@@ -18,4 +18,12 @@ export interface PartsList {
id: string;
name: string;
cards: Card[];
+}
+
+export interface UserInfos {
+ id: string;
+ firstname: string;
+ lastname: string;
+ email: string;
+ role: string;
}
\ No newline at end of file
diff --git a/src/store/api/types/queryParams.ts b/src/store/api/types/queryParams.ts
index ec7765f..a402b20 100644
--- a/src/store/api/types/queryParams.ts
+++ b/src/store/api/types/queryParams.ts
@@ -15,7 +15,7 @@ export interface EditUser {
firstname: string;
lastname: string;
email: string;
- password: string;
+ password: string | null;
role: string;
}