feat: browser push notifications (#14888)
* feat: web push notifications feature * Revert yarn.lock changes * added new env variables requirement in .env.example * moved useNotifications hook in packages/lib/hooks * fix: bug * use i18n * chore: move to new file * chore: add yarn.lock * Update .env.example Co-authored-by: Amit Sharma <[email protected]> * chore: add instruction for brave browser * fix: tooltip * chore: use enum * chore * small update --------- Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: Udit Takkar <[email protected]> Co-authored-by: Udit Takkar <[email protected]> Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: Amit Sharma <[email protected]> Co-authored-by: Carina Wollendorfer <[email protected]> Co-authored-by: unknown <[email protected]> Co-authored-by: Anik Dhabal Babu <[email protected]>
This commit is contained in:
17 files changed
+465
-11
No files matched your search
@@ -12,6 +12,7 @@ import type { filterQuerySchema } from "@calcom/features/bookings/lib/useFilterQ
|
||||
import { useFilterQuery } from "@calcom/features/bookings/lib/useFilterQuery";
|
||||
import Shell from "@calcom/features/shell/Shell";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { useNotifications, ButtonState } from "@calcom/lib/hooks/useNotifications";
|
||||
import { useParamsWithFallback } from "@calcom/lib/hooks/useParamsWithFallback";
|
||||
import type { RouterOutputs } from "@calcom/trpc/react";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
@@ -144,6 +145,27 @@ export default function Bookings() {
|
||||
)[0] || [];
|
||||
|
||||
const [animationParentRef] = useAutoAnimate<HTMLDivElement>();
|
||||
const { buttonToShow, isLoading, enableNotifications, disableNotifications } = useNotifications();
|
||||
|
||||
const actions = (
|
||||
<div>
|
||||
{buttonToShow && (
|
||||
<Button
|
||||
color="primary"
|
||||
onClick={buttonToShow === ButtonState.ALLOW ? enableNotifications : disableNotifications}
|
||||
loading={isLoading}
|
||||
disabled={buttonToShow === ButtonState.DENIED}
|
||||
tooltipSide="bottom"
|
||||
tooltip={buttonToShow === ButtonState.DENIED ? t("you_have_denied_notifications") : undefined}>
|
||||
{t(
|
||||
buttonToShow === ButtonState.DISABLE
|
||||
? "disable_browser_notifications"
|
||||
: "allow_browser_notifications"
|
||||
)}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<Shell
|
||||
@@ -152,7 +174,8 @@ export default function Bookings() {
|
||||
heading={t("bookings")}
|
||||
subtitle={t("bookings_description")}
|
||||
title="Bookings"
|
||||
description="Create events to share for people to book on your calendar.">
|
||||
description="Create events to share for people to book on your calendar."
|
||||
actions={actions}>
|
||||
<div className="flex flex-col">
|
||||
<div className="flex flex-row flex-wrap justify-between">
|
||||
<HorizontalTabs tabs={tabs} />
|
||||
|
||||
+10
-3
@@ -1,6 +1,6 @@
|
||||
import type { IncomingMessage } from "http";
|
||||
import type { AppContextType } from "next/dist/shared/lib/utils";
|
||||
import React from "react";
|
||||
import React, { useEffect } from "react";
|
||||
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
|
||||
@@ -11,8 +11,15 @@ import "../styles/globals.css";
|
||||
function MyApp(props: AppProps) {
|
||||
const { Component, pageProps } = props;
|
||||
|
||||
if (Component.PageWrapper !== undefined) return Component.PageWrapper(props);
|
||||
return <Component {...pageProps} />;
|
||||
useEffect(() => {
|
||||
if (typeof window !== "undefined" && "serviceWorker" in navigator) {
|
||||
navigator.serviceWorker.register("/service-worker.js");
|
||||
}
|
||||
}, []);
|
||||
|
||||
const content = Component.PageWrapper ? <Component.PageWrapper {...props} /> : <Component {...pageProps} />;
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
declare global {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
self.addEventListener("push", (event) => {
|
||||
let notificationData = event.data.json();
|
||||
|
||||
const title = notificationData.title || "You have new notification from Cal.com";
|
||||
const image ="/cal-com-icon.svg";
|
||||
const options = {
|
||||
...notificationData.options,
|
||||
icon: image,
|
||||
};
|
||||
self.registration.showNotification(title, options);
|
||||
});
|
||||
|
||||
self.addEventListener("notificationclick", (event) => {
|
||||
event.notification.close();
|
||||
event.waitUntil(self.clients.openWindow(event.notification.data.targetURL || "https://app.cal.com"));
|
||||
});
|
||||
@@ -461,6 +461,14 @@
|
||||
"dynamic_booking": "Dynamic group links",
|
||||
"allow_seo_indexing": "Allow search engines to access your public content",
|
||||
"seo_indexing": "Allow SEO Indexing",
|
||||
"allow_browser_notifications": "Allow Browser Notifications",
|
||||
"you_have_denied_notifications": "You have denied notifications. Reset permission in browser settings to enable.",
|
||||
"disable_browser_notifications": "Disable Browser Notifications",
|
||||
"browser_notifications_turned_on": "Browser Notifications turned on",
|
||||
"browser_notifications_turned_off": "Browser Notifications turned off",
|
||||
"browser_notifications_denied": "Browser Notifications denied",
|
||||
"please_allow_notifications": "Please allow notifications from the prompt",
|
||||
"browser_notifications_not_supported": "Your browser does not support Push Notifications. If you are Brave user then enable `Use Google services for push messaging` Option on brave://settings/?search=push+messaging",
|
||||
"email": "Email",
|
||||
"email_placeholder": "[email protected]",
|
||||
"full_name": "Full name",
|
||||
|
||||
Reference in new issue
Block a user