35 lines
866 B
TypeScript
35 lines
866 B
TypeScript
import { useEffect } from "react";
|
|
|
|
import { bootstrapTelephonyPush } from "~/lib/pwa/telephonyPush";
|
|
|
|
type TelephonyPushBootstrapProps = {
|
|
enabled: boolean;
|
|
tenantSlug: string;
|
|
vapidPublicKey?: string;
|
|
csrfToken?: string;
|
|
isDev?: boolean;
|
|
onError?: (error: unknown) => void;
|
|
};
|
|
|
|
/** Non-visual bootstrap for users who have already granted Web Push. */
|
|
export function TelephonyPushBootstrap({
|
|
enabled,
|
|
tenantSlug,
|
|
vapidPublicKey,
|
|
csrfToken,
|
|
isDev,
|
|
onError,
|
|
}: TelephonyPushBootstrapProps): null {
|
|
useEffect(() => {
|
|
let active = true;
|
|
void bootstrapTelephonyPush({ enabled, tenantSlug, vapidPublicKey, csrfToken, isDev }).catch((error: unknown) => {
|
|
if (active) onError?.(error);
|
|
});
|
|
return () => {
|
|
active = false;
|
|
};
|
|
}, [csrfToken, enabled, isDev, onError, tenantSlug, vapidPublicKey]);
|
|
|
|
return null;
|
|
}
|