|
| 1 | +import React, { Fragment } from 'react'; |
| 2 | +import { useTranslation } from 'react-i18next'; |
| 3 | + |
| 4 | +import { Box, Card, StyledLink, Text } from '@/components'; |
| 5 | +import { useCunninghamTheme } from '@/cunningham'; |
| 6 | +import { |
| 7 | + Doc, |
| 8 | + Role, |
| 9 | + currentDocRole, |
| 10 | + useTransRole, |
| 11 | +} from '@/features/docs/doc-management'; |
| 12 | +import { useDate } from '@/hook'; |
| 13 | + |
| 14 | +import { DocToolBox } from './DocToolBox'; |
| 15 | + |
| 16 | +interface DocHeaderProps { |
| 17 | + doc: Doc; |
| 18 | +} |
| 19 | + |
| 20 | +export const DocHeader = ({ doc }: DocHeaderProps) => { |
| 21 | + const { colorsTokens } = useCunninghamTheme(); |
| 22 | + const { t } = useTranslation(); |
| 23 | + const { formatDate } = useDate(); |
| 24 | + const transRole = useTransRole(); |
| 25 | + |
| 26 | + return ( |
| 27 | + <Card |
| 28 | + $margin="big" |
| 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 | + className="material-icons" |
| 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" |
| 64 | + > |
| 65 | + <Box $direction="row" $align="center" $gap="0.5rem 2rem" $wrap="wrap"> |
| 66 | + {doc.is_public && ( |
| 67 | + <Text |
| 68 | + $weight="bold" |
| 69 | + $background={colorsTokens()['primary-600']} |
| 70 | + $color="white" |
| 71 | + $padding="xtiny" |
| 72 | + $radius="3px" |
| 73 | + $size="s" |
| 74 | + > |
| 75 | + {t('Public')} |
| 76 | + </Text> |
| 77 | + )} |
| 78 | + <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((access) => access.role === Role.OWNER) |
| 86 | + .map((access, index, accesses) => ( |
| 87 | + <Fragment key={`access-${index}`}> |
| 88 | + {access.user.email}{' '} |
| 89 | + {index < accesses.length - 1 ? ' / ' : ''} |
| 90 | + </Fragment> |
| 91 | + ))} |
| 92 | + </strong> |
| 93 | + </Text> |
| 94 | + </Box> |
| 95 | + <Text $size="s" $display="inline"> |
| 96 | + {t('Your role:')}{' '} |
| 97 | + <strong>{transRole(currentDocRole(doc.abilities))}</strong> |
| 98 | + </Text> |
| 99 | + </Box> |
| 100 | + </Card> |
| 101 | + ); |
| 102 | +}; |
0 commit comments