| 1 |
import React, { useState } from "react"; |
| 2 |
// PatternFly |
| 3 |
import { PageSection, Tabs, Tab, TabTitleText } from "@patternfly/react-core"; |
| 4 |
// Components |
| 5 |
import UserSettings from "src/components/UsersSections/UserSettings"; |
| 6 |
import BreadCrumb, { BreadCrumbItem } from "src/components/layouts/BreadCrumb"; |
| 7 |
import DataSpinner from "src/components/layouts/DataSpinner"; |
| 8 |
import TitleLayout from "src/components/layouts/TitleLayout"; |
| 9 |
import ContextualHelpPanel from "src/components/ContextualHelpPanel/ContextualHelpPanel"; |
| 10 |
// Hooks |
| 11 |
import { useStageUserSettings } from "src/hooks/useUserSettingsData"; |
| 12 |
// Redux |
| 13 |
import { useAppDispatch } from "src/store/hooks"; |
| 14 |
import { updateBreadCrumbPath } from "src/store/Global/routes-slice"; |
| 15 |
// Navigation |
| 16 |
import { URL_PREFIX } from "src/navigation/NavRoutes"; |
| 17 |
import { NotFound } from "src/components/errors/PageErrors"; |
| 18 |
import { UidParams, useSafeParams } from "src/utils/paramsUtils"; |
| 19 |
|
| 20 |
const StageUsersTabs = () => { |
| 21 |
const { uid } = useSafeParams<UidParams>(["uid"]); |
| 22 |
const dispatch = useAppDispatch(); |
| 23 |
|
| 24 |
const [breadcrumbItems, setBreadcrumbItems] = React.useState< |
| 25 |
BreadCrumbItem[] |
| 26 |
>([]); |
| 27 |
|
| 28 |
React.useEffect(() => { |
| 29 |
// Update breadcrumb route |
| 30 |
const currentPath: BreadCrumbItem[] = [ |
| 31 |
{ |
| 32 |
name: "Stage users", |
| 33 |
url: URL_PREFIX + "/stage-users", |
| 34 |
}, |
| 35 |
{ |
| 36 |
name: uid, |
| 37 |
url: URL_PREFIX + "/stage-users/" + uid, |
| 38 |
isActive: true, |
| 39 |
}, |
| 40 |
]; |
| 41 |
setBreadcrumbItems(currentPath); |
| 42 |
setActiveTabKey(0); |
| 43 |
dispatch(updateBreadCrumbPath(currentPath)); |
| 44 |
}, [uid]); |
| 45 |
|
| 46 |
// Contextual links panel |
| 47 |
const [fromPageSelected, setFromPageSelected] = React.useState( |
| 48 |
"stage-users-settings" |
| 49 |
); |
| 50 |
const [isContextualPanelExpanded, setIsContextualPanelExpanded] = |
| 51 |
React.useState(false); |
| 52 |
|
| 53 |
const changeFromPage = (fromPage: string) => { |
| 54 |
setFromPageSelected(fromPage); |
| 55 |
}; |
| 56 |
|
| 57 |
const onOpenContextualPanel = () => { |
| 58 |
setIsContextualPanelExpanded(!isContextualPanelExpanded); |
| 59 |
}; |
| 60 |
|
| 61 |
const onCloseContextualPanel = () => { |
| 62 |
setIsContextualPanelExpanded(false); |
| 63 |
}; |
| 64 |
|
| 65 |
// Data loaded from DB |
| 66 |
const userSettingsData = useStageUserSettings(uid); |
| 67 |
|
| 68 |
// Tab |
| 69 |
const [activeTabKey, setActiveTabKey] = useState(0); |
| 70 |
|
| 71 |
const handleTabClick = ( |
| 72 |
_event: React.MouseEvent<HTMLElement, MouseEvent>, |
| 73 |
tabIndex: number | string |
| 74 |
) => { |
| 75 |
setActiveTabKey(tabIndex as number); |
| 76 |
}; |
| 77 |
|
| 78 |
if (userSettingsData.isLoading) { |
| 79 |
return <DataSpinner />; |
| 80 |
} |
| 81 |
|
| 82 |
// Show the 'NotFound' page if the user is not found |
| 83 |
if ( |
| 84 |
!userSettingsData.isLoading && |
| 85 |
Object.keys(userSettingsData.user).length === 0 |
| 86 |
) { |
| 87 |
return <NotFound />; |
| 88 |
} |
| 89 |
|
| 90 |
return ( |
| 91 |
<> |
| 92 |
<ContextualHelpPanel |
| 93 |
fromPage={fromPageSelected} |
| 94 |
isExpanded={isContextualPanelExpanded} |
| 95 |
onClose={onCloseContextualPanel} |
| 96 |
> |
| 97 |
<PageSection hasBodyWrapper={false}> |
| 98 |
<BreadCrumb breadcrumbItems={breadcrumbItems} /> |
| 99 |
<TitleLayout |
| 100 |
id={uid} |
| 101 |
preText="Staged user:" |
| 102 |
text={uid} |
| 103 |
headingLevel="h1" |
| 104 |
/> |
| 105 |
</PageSection> |
| 106 |
<PageSection hasBodyWrapper={false} type="tabs" isFilled> |
| 107 |
<Tabs |
| 108 |
activeKey={activeTabKey} |
| 109 |
onSelect={handleTabClick} |
| 110 |
variant="secondary" |
| 111 |
isBox |
| 112 |
className="pf-v6-u-ml-lg" |
| 113 |
mountOnEnter |
| 114 |
unmountOnExit |
| 115 |
> |
| 116 |
<Tab |
| 117 |
eventKey={0} |
| 118 |
name="details" |
| 119 |
title={<TabTitleText>Settings</TabTitleText>} |
| 120 |
> |
| 121 |
<UserSettings |
| 122 |
originalUser={userSettingsData.originalUser} |
| 123 |
user={userSettingsData.user} |
| 124 |
metadata={userSettingsData.metadata} |
| 125 |
pwPolicyData={userSettingsData.pwPolicyData} |
| 126 |
krbPolicyData={userSettingsData.krbtPolicyData} |
| 127 |
certData={userSettingsData.certData} |
| 128 |
onUserChange={userSettingsData.setUser} |
| 129 |
isDataLoading={userSettingsData.isFetching} |
| 130 |
onRefresh={userSettingsData.refetch} |
| 131 |
isModified={userSettingsData.modified} |
| 132 |
onResetValues={userSettingsData.resetValues} |
| 133 |
modifiedValues={userSettingsData.modifiedValues} |
| 134 |
radiusProxyData={userSettingsData.radiusServers} |
| 135 |
idpData={userSettingsData.idpServers} |
| 136 |
from="stage-users" |
| 137 |
changeFromPage={changeFromPage} |
| 138 |
onOpenContextualPanel={onOpenContextualPanel} |
| 139 |
/> |
| 140 |
</Tab> |
| 141 |
</Tabs> |
| 142 |
</PageSection> |
| 143 |
</ContextualHelpPanel> |
| 144 |
</> |
| 145 |
); |
| 146 |
}; |
| 147 |
|
| 148 |
export default StageUsersTabs; |