improve test push notifications;
renames; more alerts (merge)
This commit is contained in:
@@ -242,7 +242,10 @@ function PwaManager({ subs }) {
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ subscription })
|
||||
//sends test notification to the current subscription
|
||||
// body: JSON.stringify({ subscription })
|
||||
//sends test notification to all subscriptions of this user
|
||||
body: JSON.stringify({ id: session.user.id, title: "Тестово уведомление", message: "Това е тестово уведомление" })
|
||||
});
|
||||
};
|
||||
|
||||
|
@@ -7,6 +7,7 @@ function PwaManagerNotifications() {
|
||||
const [isPermissionGranted, setIsPermissionGranted] = useState(false);
|
||||
const [subscription, setSubscription] = useState(null);
|
||||
const [registration, setRegistration] = useState(null);
|
||||
const [isSubSaved, setIsSubSaved] = useState(false);
|
||||
const { data: session } = useSession();
|
||||
|
||||
// Check if all required APIs are supported
|
||||
@@ -53,6 +54,7 @@ function PwaManagerNotifications() {
|
||||
if (existingSubscription) {
|
||||
console.log('Already subscribed.');
|
||||
setSubscription(existingSubscription);
|
||||
sendSubscriptionToServer(existingSubscription);
|
||||
} else if (Notification.permission === "granted") {
|
||||
// Permission was already granted but no subscription exists, so subscribe now
|
||||
subscribeToNotifications(registration);
|
||||
@@ -90,6 +92,7 @@ function PwaManagerNotifications() {
|
||||
};
|
||||
|
||||
const sendSubscriptionToServer = async (sub) => {
|
||||
if (isSubSaved) { return; }
|
||||
if (session.user?.id != null) {
|
||||
await fetch(`/api/notify`, {
|
||||
method: 'PUT',
|
||||
@@ -105,6 +108,7 @@ function PwaManagerNotifications() {
|
||||
console.log('Subscription data saved on server.');
|
||||
const s = await response.json();
|
||||
setSubscription(sub);
|
||||
setIsSubSaved(true);
|
||||
console.log('Web push subscribed!');
|
||||
}
|
||||
});
|
||||
|
@@ -412,7 +412,7 @@ export default function AvailabilityForm({ publisherId, existingItems, inline, o
|
||||
<ToastContainer></ToastContainer>
|
||||
<form id="formAv" className="form p-5 bg-white shadow-md rounded-lg" onSubmit={handleSubmit}>
|
||||
<h3 className="text-xl font-semibold mb-5 text-gray-800 border-b pb-2">
|
||||
{editMode ? "Редактирай" : "Нова"} възможност: {common.getDateFormatedShort(new Date(day))}
|
||||
{editMode ? "Редактирай" : "Нова"} възможност: {common.getDateFormattedShort(new Date(day))}
|
||||
</h3>
|
||||
|
||||
<LocalizationProvider dateAdapter={AdapterDateFns} localeText={bgBG} adapterLocale={bg}>
|
||||
|
@@ -239,7 +239,7 @@ const AvCalendar = ({ publisherId, events, selectedDate, cartEvents, lastPublish
|
||||
if (startdate < new Date() || end < new Date() || startdate > end) return;
|
||||
//or if schedule is published (lastPublishedDate)
|
||||
if (editLockedBefore && startdate < editLockedBefore) {
|
||||
toast.error(`Не можете да променяте предпочитанията си за дати преди ${common.getDateFormatedShort(editLockedBefore)}.`, { autoClose: 5000 });
|
||||
toast.error(`Не можете да променяте предпочитанията си за дати преди ${common.getDateFormattedShort(editLockedBefore)}.`, { autoClose: 5000 });
|
||||
return;
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user