1- import React , { Fragment } from 'react' ;
1+ import { Button } from '@openfun/cunningham-react' ;
2+ import React , { Fragment , useState } from 'react' ;
23import { useTranslation } from 'react-i18next' ;
34
45import { Box , Card , StyledLink , Text } from '@/components' ;
@@ -9,96 +10,124 @@ import {
910 currentDocRole ,
1011 useTransRole ,
1112} from '@/features/docs/doc-management' ;
13+ import { ModalVersion , Versions } from '@/features/docs/doc-versioning' ;
1214import { useDate } from '@/hook' ;
1315
1416import { DocToolBox } from './DocToolBox' ;
1517
1618interface DocHeaderProps {
1719 doc : Doc ;
20+ versionId ?: Versions [ 'version_id' ] ;
1821}
1922
20- export const DocHeader = ( { doc } : DocHeaderProps ) => {
23+ export const DocHeader = ( { doc, versionId } : DocHeaderProps ) => {
2124 const { colorsTokens } = useCunninghamTheme ( ) ;
2225 const { t } = useTranslation ( ) ;
2326 const { formatDate } = useDate ( ) ;
2427 const transRole = useTransRole ( ) ;
28+ const [ isModalVersionOpen , setIsModalVersionOpen ] = useState ( false ) ;
2529
2630 return (
27- < Card
28- $margin = "small"
29- aria-label = { t ( 'It is the card information about the document.' ) }
30- >
31- < Box $padding = "small" $direction = "row" $align = "center" >
32- < StyledLink href = "/" >
33- < Text
34- $isMaterialIcon
35- $theme = "primary"
36- $size = "2rem"
37- $css = { `&:hover {background-color: ${ colorsTokens ( ) [ 'primary-100' ] } ; };` }
38- $hasTransition
39- $radius = "5px"
40- $padding = "tiny"
41- >
42- home
43- </ Text >
44- </ StyledLink >
45- < Box
46- $width = "1px"
47- $height = "70%"
48- $background = { colorsTokens ( ) [ 'greyscale-100' ] }
49- $margin = { { horizontal : 'small' } }
50- />
51- < Text as = "h2" $align = "center" $margin = { { all : 'none' , left : 'tiny' } } >
52- { doc . title }
53- </ Text >
54- < DocToolBox doc = { doc } />
55- </ Box >
56- < Box
57- $direction = "row"
58- $align = "center"
59- $css = "border-top:1px solid #eee"
60- $padding = { { horizontal : 'big' , vertical : 'tiny' } }
61- $gap = "0.5rem 2rem"
62- $justify = "space-between"
63- $wrap = "wrap"
31+ < >
32+ < Card
33+ $margin = "small"
34+ aria-label = { t ( 'It is the card information about the document.' ) }
6435 >
65- < Box $direction = "row" $align = "center" $gap = "0.5rem 2rem" $wrap = "wrap" >
66- { doc . is_public && (
36+ < Box $padding = "small" $direction = "row" $align = "center" >
37+ < StyledLink href = "/" >
38+ < Text
39+ $isMaterialIcon
40+ $theme = "primary"
41+ $size = "2rem"
42+ $css = { `&:hover {background-color: ${ colorsTokens ( ) [ 'primary-100' ] } ; };` }
43+ $hasTransition
44+ $radius = "5px"
45+ $padding = "tiny"
46+ >
47+ home
48+ </ Text >
49+ </ StyledLink >
50+ < Box
51+ $width = "1px"
52+ $height = "70%"
53+ $background = { colorsTokens ( ) [ 'greyscale-100' ] }
54+ $margin = { { horizontal : 'small' } }
55+ />
56+ < Box $gap = "1rem" $direction = "row" >
6757 < Text
68- $weight = "bold"
69- $background = { colorsTokens ( ) [ 'primary-600' ] }
70- $color = "white"
71- $padding = "xtiny"
72- $radius = "3px"
73- $size = "s"
58+ as = "h2"
59+ $align = "center"
60+ $margin = { { all : 'none' , left : 'tiny' } }
7461 >
75- { t ( 'Public' ) }
62+ { doc . title }
7663 </ Text >
77- ) }
64+ { versionId && (
65+ < Button
66+ onClick = { ( ) => {
67+ setIsModalVersionOpen ( true ) ;
68+ } }
69+ size = "small"
70+ >
71+ { t ( 'Restore this version' ) }
72+ </ Button >
73+ ) }
74+ </ Box >
75+ < DocToolBox doc = { doc } />
76+ </ Box >
77+ < Box
78+ $direction = "row"
79+ $align = "center"
80+ $css = "border-top:1px solid #eee"
81+ $padding = { { horizontal : 'big' , vertical : 'tiny' } }
82+ $gap = "0.5rem 2rem"
83+ $justify = "space-between"
84+ $wrap = "wrap"
85+ >
86+ < Box $direction = "row" $align = "center" $gap = "0.5rem 2rem" $wrap = "wrap" >
87+ { doc . is_public && (
88+ < Text
89+ $weight = "bold"
90+ $background = { colorsTokens ( ) [ 'primary-600' ] }
91+ $color = "white"
92+ $padding = "xtiny"
93+ $radius = "3px"
94+ $size = "s"
95+ >
96+ { t ( 'Public' ) }
97+ </ Text >
98+ ) }
99+ < Text $size = "s" $display = "inline" >
100+ { t ( 'Created at' ) } < strong > { formatDate ( doc . created_at ) } </ strong >
101+ </ Text >
102+ < Text $size = "s" $display = "inline" $elipsis $maxWidth = "60vw" >
103+ { t ( 'Owners:' ) } { ' ' }
104+ < strong >
105+ { doc . accesses
106+ . filter (
107+ ( access ) => access . role === Role . OWNER && access . user . email ,
108+ )
109+ . map ( ( access , index , accesses ) => (
110+ < Fragment key = { `access-${ index } ` } >
111+ { access . user . email } { ' ' }
112+ { index < accesses . length - 1 ? ' / ' : '' }
113+ </ Fragment >
114+ ) ) }
115+ </ strong >
116+ </ Text >
117+ </ Box >
78118 < Text $size = "s" $display = "inline" >
79- { t ( 'Created at' ) } < strong > { formatDate ( doc . created_at ) } </ strong >
80- </ Text >
81- < Text $size = "s" $display = "inline" $elipsis $maxWidth = "60vw" >
82- { t ( 'Owners:' ) } { ' ' }
83- < strong >
84- { doc . accesses
85- . filter (
86- ( access ) => access . role === Role . OWNER && access . user . email ,
87- )
88- . map ( ( access , index , accesses ) => (
89- < Fragment key = { `access-${ index } ` } >
90- { access . user . email } { ' ' }
91- { index < accesses . length - 1 ? ' / ' : '' }
92- </ Fragment >
93- ) ) }
94- </ strong >
119+ { t ( 'Your role:' ) } { ' ' }
120+ < strong > { transRole ( currentDocRole ( doc . abilities ) ) } </ strong >
95121 </ Text >
96122 </ Box >
97- < Text $size = "s" $display = "inline" >
98- { t ( 'Your role:' ) } { ' ' }
99- < strong > { transRole ( currentDocRole ( doc . abilities ) ) } </ strong >
100- </ Text >
101- </ Box >
102- </ Card >
123+ </ Card >
124+ { isModalVersionOpen && versionId && (
125+ < ModalVersion
126+ onClose = { ( ) => setIsModalVersionOpen ( false ) }
127+ docId = { doc . id }
128+ versionId = { versionId }
129+ />
130+ ) }
131+ </ >
103132 ) ;
104133} ;
0 commit comments