feat(settings): implement user profile page and notification handler
This commit introduces a new user settings page and enhances push notification functionality. The new settings page, located at `/pages/settings`, allows users to view and update their personal profile information. It fetches the current user's data and provides a form to edit fields such as name, email, phone number, position, and role. The form is built using `react-hook-form` for state management and validation, and it leverages custom hooks (`useProfileQuery`, `useUpdateProfileQuery`) to interact with the API. Additionally, a `notificationclick` event listener has been added to the Firebase messaging service worker. This handler improves the user experience for push notifications by focusing on an existing tab with the relevant URL or opening a new one if none exists when a notification is clicked.
This commit is contained in:
@@ -1,15 +1,46 @@
|
||||
import { parseWithSchema } from "@/utils/shared";
|
||||
import api from "../axios";
|
||||
|
||||
import { API_ENDPOINTS } from "../endpoints";
|
||||
import { CurrentUserProfileSchema } from "../types";
|
||||
import {
|
||||
CurrentUserProfileSchema,
|
||||
IUser,
|
||||
TCurrentUser,
|
||||
TUpdateProfileCredentials,
|
||||
UserSchema,
|
||||
} from "../types";
|
||||
export const profileService = {
|
||||
getProfile: async () => {
|
||||
try {
|
||||
const response = (await api.get(API_ENDPOINTS.PROFILE.READ)).data;
|
||||
|
||||
return CurrentUserProfileSchema.parse(response.data);
|
||||
const userData = parseWithSchema(
|
||||
CurrentUserProfileSchema,
|
||||
response.data,
|
||||
"Profile Service: Get Profile",
|
||||
);
|
||||
return userData;
|
||||
} catch (error) {
|
||||
console.error("ERROR caught in Profile Service: Get Profile", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
updateProfile: async ({
|
||||
credentials,
|
||||
}: {
|
||||
credentials: TUpdateProfileCredentials;
|
||||
}): Promise<IUser> => {
|
||||
try {
|
||||
const response = (
|
||||
await api.put(API_ENDPOINTS.PROFILE.UPDATE, credentials)
|
||||
).data;
|
||||
return parseWithSchema(
|
||||
UserSchema,
|
||||
response.data,
|
||||
"Profile Service: Update Profile",
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("ERROR caught in Profile Service: Update Profile", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user