@@ -30,10 +30,12 @@ import CardSection from "@code0-tech/pictor/dist/components/card/CardSection";
3030import { Tab , TabContent , TabList , TabTrigger } from "@code0-tech/pictor/dist/components/tab/Tab" ;
3131import { User , UsersUpdateInput } from "@code0-tech/sagittarius-graphql-types" ;
3232import { UserService } from "@edition/user/services/User.service" ;
33+ import { useUserSession } from "@edition/user/hooks/User.session.hook" ;
3334import { addIslandSuccessNotification } from "@code0-tech/pictor/dist/components/island/Island.hook" ;
3435import { IconAt , IconBackground , IconLock , IconMail , IconSettings2 , IconShieldLock } from "@tabler/icons-react" ;
3536import { Layout } from "@code0-tech/pictor/dist/components/layout/Layout" ;
3637import { motion } from "framer-motion" ;
38+ import { UserSessionsDataTableComponent } from "@edition/user/components/UserSessionsDataTableComponent" ;
3739
3840export interface UserEditDialogComponentProps {
3941 userId ?: User [ 'id' ]
@@ -49,11 +51,14 @@ export const UserEditDialogComponent: React.FC<UserEditDialogComponentProps> = (
4951 const userStore = useStore ( UserService )
5052 const [ , startTransition ] = React . useTransition ( )
5153
54+ const currentSession = useUserSession ( )
5255 const user = React . useMemo (
5356 ( ) => userService . getById ( userId ) ,
5457 [ userStore , userId ]
5558 )
5659
60+ const isSelf = ! ! user && ! ! currentSession ?. user ?. id && user . id === currentSession . user . id
61+
5762 const initialValues = React . useMemo ( ( ) => ( {
5863 firstname : user ?. firstname ?? null ,
5964 lastname : user ?. lastname ?? null ,
@@ -110,8 +115,10 @@ export const UserEditDialogComponent: React.FC<UserEditDialogComponentProps> = (
110115 if ( values . firstname !== ( user ?. firstname ?? null ) ) payload . firstname = values . firstname
111116 if ( values . lastname !== ( user ?. lastname ?? null ) ) payload . lastname = values . lastname
112117 if ( values . readme !== ( user ?. readme ?? null ) ) payload . readme = values . readme
113- if ( values . admin !== ( user ?. admin ?? false ) ) payload . admin = values . admin
114- if ( values . blocked !== ( user ?. blocked ?? false ) ) payload . blocked = values . blocked
118+ if ( ! isSelf ) {
119+ if ( values . admin !== ( user ?. admin ?? false ) ) payload . admin = values . admin
120+ if ( values . blocked !== ( user ?. blocked ?? false ) ) payload . blocked = values . blocked
121+ }
115122 if ( values . password ) {
116123 payload . password = values . password
117124 payload . passwordRepeat = values . repeatPassword
@@ -185,16 +192,24 @@ export const UserEditDialogComponent: React.FC<UserEditDialogComponentProps> = (
185192 < Text size = { "md" } > General</ Text >
186193 </ Button >
187194 </ TabTrigger >
188- < TabTrigger value = { "permissions" } w = { "100%" } asChild >
195+ { ! isSelf && (
196+ < TabTrigger value = { "permissions" } w = { "100%" } asChild >
197+ < Button paddingSize = { "xxs" } variant = { "none" } justify = { "start" } >
198+ < IconShieldLock size = { 13 } />
199+ < Text size = { "md" } > Access</ Text >
200+ </ Button >
201+ </ TabTrigger >
202+ ) }
203+ < TabTrigger value = { "security" } w = { "100%" } asChild >
189204 < Button paddingSize = { "xxs" } variant = { "none" } justify = { "start" } >
190- < IconShieldLock size = { 13 } />
191- < Text size = { "md" } > Access </ Text >
205+ < IconSettings2 opacity = { 0 } size = { 13 } />
206+ < Text size = { "md" } > Security </ Text >
192207 </ Button >
193208 </ TabTrigger >
194- < TabTrigger value = { "security " } w = { "100%" } asChild >
209+ < TabTrigger value = { "sessions " } w = { "100%" } asChild >
195210 < Button paddingSize = { "xxs" } variant = { "none" } justify = { "start" } >
196211 < IconSettings2 opacity = { 0 } size = { 13 } />
197- < Text size = { "md" } > Security </ Text >
212+ < Text size = { "md" } > Sessions </ Text >
198213 </ Button >
199214 </ TabTrigger >
200215 </ TabList >
@@ -256,7 +271,8 @@ export const UserEditDialogComponent: React.FC<UserEditDialogComponentProps> = (
256271 description = { "A short bio or notes shown on the user's profile." }
257272 { ...inputs . getInputProps ( "readme" ) } />
258273 </ TabContent >
259- < TabContent value = { "permissions" } style = { { overflow : "hidden" } } >
274+ < TabContent value = { "permissions" }
275+ style = { { overflow : "hidden" , display : isSelf ? "none" : undefined } } >
260276 < Flex justify = { "space-between" } align = { "center" } >
261277 < Text size = { "lg" } hierarchy = { "primary" } display = { "block" } > Access</ Text >
262278 < Button paddingSize = { "xxs" } color = { "success" } variant = { "none" }
@@ -314,6 +330,24 @@ export const UserEditDialogComponent: React.FC<UserEditDialogComponentProps> = (
314330 onChange = { ( ) => validate ( "repeatPassword" ) }
315331 { ...inputs . getInputProps ( "repeatPassword" ) } />
316332 </ TabContent >
333+ < TabContent value = { "sessions" }
334+ style = { {
335+ overflow : "hidden" ,
336+ height : "100%" ,
337+ display : "flex" ,
338+ flexDirection : "column"
339+ } } >
340+ < Flex justify = { "space-between" } align = { "center" } >
341+ < Text size = { "lg" } hierarchy = { "primary" } display = { "block" } > Sessions</ Text >
342+ </ Flex >
343+ < Spacing spacing = { "xs" } />
344+ < Text size = { "md" } hierarchy = { "tertiary" } >
345+ Active sign-in sessions for @{ user ?. username ?? "" } . Log out a session to revoke
346+ its access.
347+ </ Text >
348+ < Spacing spacing = { "md" } />
349+ < UserSessionsDataTableComponent userId = { userId } />
350+ </ TabContent >
317351 </ Card >
318352 </ Layout >
319353 </ Tab >
0 commit comments