-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DEV-1315]: highlight and hide webinars questions (#646)
* feat(DEV-1315): highlight and hide webinars questions * feat(DEV-1315): add UpdateItem to host user * chore: fix typo * feat(DEV-1315): remove definitions from terraform * chore: add changeset * feat(DEV-1358): remove unused code * feat(DEV-1315): update webinars questions' row * feat(DEV-1315): update style Co-authored-by: Marco Ponchia <[email protected]> * feat(DEV-1315): update style Co-authored-by: Marco Ponchia <[email protected]> * feat(DEV-1315): update style Co-authored-by: Marco Ponchia <[email protected]> * chore: update changeset Co-authored-by: marcobottaro <[email protected]> * feat(DEV-1315): add user names * chore: remove unused code * feat(DEV-1315): update tests * feat(DEV-1315): update code * chore: remove unused code * test: update tests * feat(DEV-1315): update logic * feat(DEV-1315): add default tcColor * feat(DEV-1315): update IconButton visibility icon Co-authored-by: Marco Ponchia <[email protected]> * feat(DEV-1315): update WebinarQuestion codec to accept undefined values * chore: remove test webinar * feat(DEV-1315): unify update question logic * chore: remove test webinar * Webinar questions review (#704) * feat(DEV-1315): update translation Co-authored-by: marcobottaro <[email protected]> --------- Co-authored-by: Marco Ponchia <[email protected]> Co-authored-by: marcobottaro <[email protected]> Co-authored-by: AF <[email protected]> Co-authored-by: Marco Comi <[email protected]>
- Loading branch information
1 parent
b7ed47f
commit 458c58f
Showing
10 changed files
with
439 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"nextjs-website": minor | ||
--- | ||
|
||
Add the highlight and hide action on webinars' questions list |
124 changes: 124 additions & 0 deletions
124
apps/nextjs-website/src/components/molecules/WebinarQuestion/WebinarQuestionRow.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import { WebinarQuestion } from '@/lib/webinars/webinarQuestions'; | ||
import { Box, IconButton, TableCell, TableRow, useTheme } from '@mui/material'; | ||
import { CopyToClipboardButton } from '@pagopa/mui-italia'; | ||
import DOMPurify from 'dompurify'; | ||
import AutoFixHighIcon from '@mui/icons-material/AutoFixHigh'; | ||
import VisibilityOffIcon from '@mui/icons-material/VisibilityOff'; | ||
import Visibility from '@mui/icons-material/Visibility'; | ||
import { useFormatter, useTranslations } from 'next-intl'; | ||
import AutoFixOffIcon from '@mui/icons-material/AutoFixOff'; | ||
|
||
type WebinarQuestionRowProps = { | ||
question: WebinarQuestion; | ||
userName: string; | ||
onHighlight: (highlighted: boolean) => Promise<void>; | ||
onHide: (hidden: boolean) => Promise<void>; | ||
}; | ||
|
||
export default function WebinarQuestionRow({ | ||
question, | ||
userName, | ||
onHide, | ||
onHighlight, | ||
}: WebinarQuestionRowProps) { | ||
const formatter = useFormatter(); | ||
const { palette } = useTheme(); | ||
const t = useTranslations('webinar.questionList'); | ||
|
||
const { hiddenBy, highlightedBy } = question; | ||
|
||
const isHidden = !!hiddenBy; | ||
const isHighlighted = !!highlightedBy; | ||
|
||
const tcColor = | ||
isHighlighted && !isHidden ? palette.common.white : palette.text.primary; | ||
|
||
return ( | ||
<TableRow | ||
hover | ||
key={question.id.createdAt.toISOString()} | ||
sx={{ | ||
'&:last-child td, &:last-child th': { border: 0 }, | ||
'&.MuiTableRow-hover:hover': { | ||
backgroundColor: | ||
isHighlighted && !isHidden | ||
? palette.primary.dark | ||
: palette.action.hover, | ||
}, | ||
backgroundColor: | ||
isHighlighted && !isHidden ? palette.primary.light : '', | ||
fontStyle: isHidden ? 'italic' : '', | ||
position: 'relative', | ||
}} | ||
> | ||
<TableCell | ||
sx={{ | ||
color: tcColor, | ||
}} | ||
> | ||
{!isHidden | ||
? formatter.dateTime(question.id.createdAt, { | ||
year: 'numeric', | ||
month: 'numeric', | ||
day: 'numeric', | ||
hour: 'numeric', | ||
minute: 'numeric', | ||
}) | ||
: ''} | ||
</TableCell> | ||
<TableCell | ||
width='70%' | ||
sx={{ | ||
color: tcColor, | ||
}} | ||
> | ||
{!isHidden | ||
? question.question | ||
: hiddenBy === userName | ||
? `${t('hiddenByMe')}: (${question.question})` | ||
: `${t('hiddenBy')}: ${hiddenBy}`} | ||
</TableCell> | ||
<TableCell> | ||
<Box display={'flex'} justifyContent={'space-between'}> | ||
{(!isHidden || (isHidden && hiddenBy === userName)) && ( | ||
<IconButton | ||
onClick={() => onHide(!isHidden)} | ||
sx={{ color: tcColor }} | ||
> | ||
{!isHidden ? <VisibilityOffIcon /> : <Visibility />} | ||
</IconButton> | ||
)} | ||
|
||
{!isHidden && | ||
(userName === highlightedBy || !isHighlighted ? ( | ||
<IconButton | ||
onClick={() => onHighlight(!isHighlighted)} | ||
sx={{ color: tcColor }} | ||
> | ||
{!isHidden ? <AutoFixHighIcon /> : <AutoFixOffIcon />} | ||
</IconButton> | ||
) : ( | ||
<Box | ||
sx={{ | ||
position: 'absolute', | ||
top: 4, | ||
left: 16, | ||
fontSize: 14, | ||
color: palette.common.white, | ||
}} | ||
> | ||
{t('highlightedBy')}: {highlightedBy} | ||
</Box> | ||
))} | ||
|
||
{!isHidden && ( | ||
<CopyToClipboardButton | ||
sx={{ color: tcColor }} | ||
value={DOMPurify.sanitize(question.question)} | ||
></CopyToClipboardButton> | ||
)} | ||
</Box> | ||
</TableCell> | ||
</TableRow> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.