Skip to content

Commit 9d2ecd7

Browse files
committed
Let apps add their own controls to the user dropdown.
1 parent 5384ebd commit 9d2ecd7

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

‎.changeset/user-menu-extras.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@churchapps/apphelper": minor
3+
---
4+
5+
SiteHeader takes an optional `userMenuExtras` prop, which is passed to UserMenu as `extras`. It renders app-specific controls, such as a theme picker, in the user dropdown above Logout.

‎apphelper/src/components/header/SiteHeader.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ type Props = {
1919
context: UserContextInterface;
2020
appName: string;
2121
onNavigate: (url: string) => void;
22+
/** Extra controls for the user dropdown (e.g. a theme picker); see UserMenu `extras`. */
23+
userMenuExtras?: React.ReactNode;
2224
}
2325

2426
export const SiteHeader = React.memo((props:Props) => {
@@ -120,6 +122,7 @@ export const SiteHeader = React.memo((props:Props) => {
120122
loadCounts={refresh}
121123
notificationCounts={{ notificationCount: 0, pmCount: 0 }}
122124
onNavigate={props.onNavigate}
125+
extras={props.userMenuExtras}
123126
/>
124127
)}
125128
{!props.context?.user?.id && <Link id="login-link" href="/login" color="inherit" style={{ textDecoration: "none" }}>Login</Link>}

‎apphelper/src/components/wrapper/UserMenu.tsx‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ interface Props {
2222
context: UserContextInterface;
2323
appName: string;
2424
onNavigate: (url: string) => void;
25+
/** App-specific controls shown above Logout. Pass a component that reads its own state; the menu is memoized and won't re-render for it. */
26+
extras?: React.ReactNode;
2527
}
2628

2729
// Create a persistent store for modal state that survives component re-renders
@@ -121,6 +123,11 @@ const UserMenuContent: React.FC<Props> = React.memo((props) => {
121123
result.push(<NavItem onClick={() => { modalStateStore.setShowNotifications(true); }} label={getLabel("wrapper.notifications", "Notifications")} icon="notifications" key="/notifications" onNavigate={props.onNavigate} badgeCount={directNotificationCounts.notificationCount} />);
122124

123125
result.push(<NavItem label={getLabel("wrapper.editProfile", "Edit Profile")} key="EditProfile" icon="person" onClick={() => { setTabIndex(3); }} />);
126+
if (props.extras) {
127+
result.push(<div key="extras-divider" style={{ borderTop: "1px solid #CCC", marginTop: 4 }}></div>);
128+
result.push(<Box key="extras" sx={{ px: 2, py: 1.5 }}>{props.extras}</Box>);
129+
result.push(<div key="extras-divider-end" style={{ borderTop: "1px solid #CCC", marginBottom: 4 }}></div>);
130+
}
124131
// Create logout URL with current page as return URL
125132
const currentPath = typeof window !== "undefined" ? window.location.pathname + window.location.search : "/";
126133
const logoutUrl = `/login?action=logout&returnUrl=${encodeURIComponent(currentPath)}`;

0 commit comments

Comments
 (0)