Skip to content

Commit

Permalink
feat(EditablePages): add functionality to truncate email
Browse files Browse the repository at this point in the history
The changes introduce a new utility function `truncateEmail` to truncate
email addresses for privacy reasons. The function is used in both
EditView and EditableView components to display a truncated version of
the user's email instead of their full name.
  • Loading branch information
ktun95 committed Jan 9, 2025
1 parent 666d532 commit 3c73731
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
12 changes: 7 additions & 5 deletions apps/dicty-frontpage/src/features/EditablePages/EditView.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { useNavigate } from "react-router-dom"
import { makeStyles, Container, Button } from "@material-ui/core"
import { replace as Sreplace } from "fp-ts/string"
import PersonIcon from "@material-ui/icons/Person"
import { ActionBar } from "@dictybase/ui-common"
import { Editor } from "@dictybase/editor"
import { type ContentBySlugQuery } from "dicty-graphql-schema"
import { UpdateButton } from "../../common/components/UpdateButton"
import { timeSince } from "../../common/utils/timeSince"
import { truncateEmail } from "../../common/utils/truncateEmail"

const useStyles = makeStyles((theme) => ({
container: {
Expand All @@ -15,14 +17,14 @@ const useStyles = makeStyles((theme) => ({
}))

type EditActionBarProperties = {
fullName: string
editedBy: string
updatedAt: string
contentId: string
}

const EditActionBar = ({
contentId,
fullName,
editedBy,
updatedAt,
}: EditActionBarProperties) => {
const navigate = useNavigate()
Expand All @@ -34,7 +36,7 @@ const EditActionBar = ({
descriptionElement={
<>
<strong>
<PersonIcon /> {fullName}
<PersonIcon /> {editedBy}
</strong>{" "}
edited {timeSince(updatedAt)} ago
</>
Expand All @@ -52,7 +54,7 @@ type EditViewProperties = {
const EditView = ({ data }: EditViewProperties) => {
const classes = useStyles()
const { id, updated_at, updated_by, content } = data
const fullName = `${updated_by.first_name} ${updated_by.last_name}`
const editedBy = truncateEmail(updated_by.email)
return (
<Container className={classes.container}>
<Editor
Expand All @@ -62,7 +64,7 @@ const EditView = ({ data }: EditViewProperties) => {
<EditActionBar
contentId={id}
updatedAt={updated_at}
fullName={fullName}
editedBy={editedBy}
/>
}
/>
Expand Down
11 changes: 6 additions & 5 deletions apps/dicty-frontpage/src/features/EditablePages/EditableView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { type ContentBySlugQuery } from "dicty-graphql-schema"
import { Editor } from "@dictybase/editor"
import { ActionBar } from "@dictybase/ui-common"
import { timeSince } from "../../common/utils/timeSince"
import { truncateEmail } from "../../common/utils/truncateEmail"

const useStyles = makeStyles((theme) => ({
container: {
Expand All @@ -14,12 +15,12 @@ const useStyles = makeStyles((theme) => ({
}))

type EditableActionBarProperties = {
fullName: string
editedBy: string
updatedAt: string
}

const EditableActionBar = ({
fullName,
editedBy,
updatedAt,
}: EditableActionBarProperties) => {
const navigate = useNavigate()
Expand All @@ -28,7 +29,7 @@ const EditableActionBar = ({
descriptionElement={
<>
<strong>
<PersonIcon /> {fullName}
<PersonIcon /> {editedBy}
</strong>{" "}
edited {timeSince(updatedAt)} ago
</>
Expand All @@ -49,13 +50,13 @@ type EditableViewProperties = {

const EditableView = ({ data }: EditableViewProperties) => {
const { updated_at, updated_by, content, slug } = data
const fullName = `${updated_by.first_name} ${updated_by.last_name}`
const editedBy = truncateEmail(updated_by.email)
const classes = useStyles()
return (
<Container className={classes.container}>
<Editor
toolbar={
<EditableActionBar fullName={fullName} updatedAt={updated_at} />
<EditableActionBar editedBy={editedBy} updatedAt={updated_at} />
}
editable={false}
content={{ storageKey: slug, editorState: content }}
Expand Down

0 comments on commit 3c73731

Please sign in to comment.