Files
tm_panel/public/firebase-messaging-sw.js
AmirReza Jamali 387747b9b0 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.
2025-10-11 16:41:26 +03:30

42 lines
1.1 KiB
JavaScript

importScripts("https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js");
importScripts(
"https://www.gstatic.com/firebasejs/8.10.0/firebase-messaging.js",
);
firebase.initializeApp({
apiKey: "AIzaSyCTjdsk2jE34IfnvSKP1JMTIf_Abd7tbt0",
authDomain: "opplens-270d1.firebaseapp.com",
projectId: "opplens-270d1",
storageBucket: "opplens-270d1.firebasestorage.app",
messagingSenderId: "6923326255",
appId: "1:6923326255:web:584a017e8e1bd0e4ed87da",
measurementId: "G-VQW40G8VKC",
});
const messaging = firebase.messaging();
self.addEventListener("notificationclick", (event) => {
event.notification.close();
const urlToOpen = event.notification.data.url || "/";
event.waitUntil(
clients
.matchAll({
type: "window",
includeUncontrolled: true,
})
.then((clientList) => {
for (const client of clientList) {
if (client.url === urlToOpen && "focus" in client) {
return client.focus();
}
}
if (clients.openWindow) {
return clients.openWindow(urlToOpen);
}
}),
);
});