Files
clinicpro/assets/admin/hooks/usePwaInstall.ts
T
hamed 3c103bc51e feat: update SMS settings review functionality
- Changed the tab name from 'post-visit-review' to 'post-visit-approved' in SmsPage.
- Introduced a new query for fetching approved post-visit texts.
- Updated the UI to display approved post-visit texts and their details.
- Enhanced the API endpoint to filter SMS settings based on status (pending/approved).
- Added entity name resolution for doctors and clinics in the SMS settings.
- Updated the SmsWalletPage to include new post-visit text variables for SMS templates.
- Improved type definitions in index.ts for better clarity and consistency.
2026-06-22 10:30:46 +03:30

68 lines
1.9 KiB
TypeScript

import { useEffect, useState } from "react";
export interface BeforeInstallPromptEvent extends Event {
prompt(): Promise<void>;
userChoice: Promise<{ outcome: "accepted" | "dismissed" }>;
}
const DISMISSED_KEY = "pwa-dismissed";
export function usePwaInstall() {
const [promptEvent, setPromptEvent] =
useState<BeforeInstallPromptEvent | null>(null);
const [isInstalled, setIsInstalled] = useState(false);
const [isDismissed, setIsDismissed] = useState(
() => !!localStorage.getItem(DISMISSED_KEY),
);
useEffect(() => {
if (window.matchMedia("(display-mode: standalone)").matches) {
setIsInstalled(true);
return;
}
const handleBeforeInstallPrompt = (e: Event) => {
e.preventDefault();
setPromptEvent(e as BeforeInstallPromptEvent);
};
const handleAppInstalled = () => {
setIsInstalled(true);
setPromptEvent(null);
};
window.addEventListener(
"beforeinstallprompt",
handleBeforeInstallPrompt,
);
window.addEventListener("appinstalled", handleAppInstalled);
return () => {
window.removeEventListener(
"beforeinstallprompt",
handleBeforeInstallPrompt,
);
window.removeEventListener("appinstalled", handleAppInstalled);
};
}, []);
const install = async (): Promise<boolean> => {
if (!promptEvent) return false;
try {
await promptEvent.prompt();
const { outcome } = await promptEvent.userChoice;
return outcome === "accepted";
} finally {
setPromptEvent(null);
}
};
const dismiss = () => {
localStorage.setItem(DISMISSED_KEY, "1");
setIsDismissed(true);
};
return { promptEvent, isInstalled, isDismissed, install, dismiss };
}