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.
This commit is contained in:
hamed
2026-06-22 10:30:46 +03:30
parent 8ed119e12a
commit 3c103bc51e
8 changed files with 1831 additions and 1011 deletions
+55 -35
View File
@@ -1,47 +1,67 @@
import { useEffect, useState } from 'react';
import { useEffect, useState } from "react";
export interface BeforeInstallPromptEvent extends Event {
prompt(): Promise<void>;
userChoice: Promise<{ outcome: 'accepted' | 'dismissed' }>;
prompt(): Promise<void>;
userChoice: Promise<{ outcome: "accepted" | "dismissed" }>;
}
const DISMISSED_KEY = 'pwa-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));
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;
}
useEffect(() => {
if (window.matchMedia("(display-mode: standalone)").matches) {
setIsInstalled(true);
return;
}
const handler = (e: Event) => {
e.preventDefault();
setPromptEvent(e as BeforeInstallPromptEvent);
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);
}
};
window.addEventListener('beforeinstallprompt', handler);
return () => window.removeEventListener('beforeinstallprompt', handler);
}, []);
const dismiss = () => {
localStorage.setItem(DISMISSED_KEY, "1");
setIsDismissed(true);
};
const install = async (): Promise<boolean> => {
if (!promptEvent) return false;
await promptEvent.prompt();
const { outcome } = await promptEvent.userChoice;
if (outcome === 'accepted') {
setPromptEvent(null);
return true;
}
return false;
};
const dismiss = () => {
localStorage.setItem(DISMISSED_KEY, '1');
setIsDismissed(true);
};
return { promptEvent, isInstalled, isDismissed, install, dismiss };
return { promptEvent, isInstalled, isDismissed, install, dismiss };
}