LibreChat/client/src/components/Banners/Banner.tsx

49 lines
1.6 KiB
TypeScript
Raw Normal View History

🛂 feat: OpenID Logout Redirect to `end_session_endpoint` (#5626) * WIP: end session endpoint * refactor: move useGetBannerQuery outside of package * refactor: add queriesEnabled and move useGetEndpointsConfigQuery to data-provider (local) * refactor: move useGetEndpointsQuery import to data-provider * refactor: relocate useGetEndpointsQuery import to improve module organization * refactor: move `useGetStartupConfig` from package to `~/data-provider` * refactor: move useGetUserBalance to data-provider and update imports * refactor: update query enabled conditions to include config check * refactor: remove unused useConfigOverride import from useAppStartup * refactor: integrate queriesEnabled state into file and search queries and move useGetSearchEnabledQuery to data-provider (local) * refactor: move useGetUserQuery to data-provider and update imports * refactor: enhance loginUser mutation with success and error handling as pass in options to hook * refactor: update enabled condition in queries to handle undefined config * refactor: enhance authentication mutations with queriesEnabled state management * refactor: improve conditional rendering for error messages and feature flags in Login component * refactor: remove unused queriesEnabled state from AuthContextProvider * refactor: implement queriesEnabled state management in LoginLayout with timeout handling * refactor: add conditional check for end session endpoint in OpenID strategy * ci: fix tests after changes * refactor: remove endSessionEndpoint from user schema and update logoutController to use OpenID issuer's end_session_endpoint * refactor: update logoutController to use end_session_endpoint from issuer metadata
2025-02-03 10:53:04 -05:00
import { useEffect, useRef } from 'react';
import { XIcon } from 'lucide-react';
import { useRecoilState } from 'recoil';
🛂 feat: OpenID Logout Redirect to `end_session_endpoint` (#5626) * WIP: end session endpoint * refactor: move useGetBannerQuery outside of package * refactor: add queriesEnabled and move useGetEndpointsConfigQuery to data-provider (local) * refactor: move useGetEndpointsQuery import to data-provider * refactor: relocate useGetEndpointsQuery import to improve module organization * refactor: move `useGetStartupConfig` from package to `~/data-provider` * refactor: move useGetUserBalance to data-provider and update imports * refactor: update query enabled conditions to include config check * refactor: remove unused useConfigOverride import from useAppStartup * refactor: integrate queriesEnabled state into file and search queries and move useGetSearchEnabledQuery to data-provider (local) * refactor: move useGetUserQuery to data-provider and update imports * refactor: enhance loginUser mutation with success and error handling as pass in options to hook * refactor: update enabled condition in queries to handle undefined config * refactor: enhance authentication mutations with queriesEnabled state management * refactor: improve conditional rendering for error messages and feature flags in Login component * refactor: remove unused queriesEnabled state from AuthContextProvider * refactor: implement queriesEnabled state management in LoginLayout with timeout handling * refactor: add conditional check for end session endpoint in OpenID strategy * ci: fix tests after changes * refactor: remove endSessionEndpoint from user schema and update logoutController to use OpenID issuer's end_session_endpoint * refactor: update logoutController to use end_session_endpoint from issuer metadata
2025-02-03 10:53:04 -05:00
import { useGetBannerQuery } from '~/data-provider';
import store from '~/store';
export const Banner = ({ onHeightChange }: { onHeightChange?: (height: number) => void }) => {
const { data: banner } = useGetBannerQuery();
const [hideBannerHint, setHideBannerHint] = useRecoilState<string[]>(store.hideBannerHint);
const bannerRef = useRef<HTMLDivElement>(null);
useEffect(() => {
if (onHeightChange && bannerRef.current) {
onHeightChange(bannerRef.current.offsetHeight);
}
}, [banner, hideBannerHint, onHeightChange]);
if (!banner || (banner.bannerId && hideBannerHint.includes(banner.bannerId))) {
return null;
}
const onClick = () => {
setHideBannerHint([...hideBannerHint, banner.bannerId]);
if (onHeightChange) {
onHeightChange(0); // Reset height when banner is closed
}
};
return (
<div
ref={bannerRef}
className="sticky top-0 z-20 flex items-center bg-neutral-900 from-gray-700 to-gray-900 px-2 py-1 text-slate-50 dark:bg-gradient-to-r dark:text-white md:relative"
>
<div
className="w-full truncate px-4 text-center text-sm"
dangerouslySetInnerHTML={{ __html: banner.message }}
></div>
<button
type="button"
aria-label="Dismiss banner"
className="h-8 w-8 opacity-80 hover:opacity-100"
onClick={onClick}
>
<XIcon className="mx-auto h-4 w-4" aria-hidden="true" />
</button>
</div>
);
};