diff --git a/src/components/Comment/Comment.tsx b/src/components/Comment/Comment.tsx
index 8e9248fe2c..13a8e229f7 100644
--- a/src/components/Comment/Comment.tsx
+++ b/src/components/Comment/Comment.tsx
@@ -1,13 +1,126 @@
-import React from 'react'
-import { Box } from 'rebass'
+import React, { useState } from 'react'
+import { FaTrash, FaRegEdit } from 'react-icons/fa'
+import { Flex } from 'rebass'
+import { useCommonStores } from 'src'
import { IComment } from 'src/models'
+import { hasAdminRights } from 'src/utils/helpers'
import { CommentHeader } from './CommentHeader'
+import { Text } from 'src/components/Text'
+import { Modal } from '../Modal/Modal'
+import { TextAreaField } from '../Form/Fields'
+import { Field, Form } from 'react-final-form'
+import { Button } from 'src/components/Button'
export interface IProps extends IComment {}
-export const Comment = (props: IProps) => (
-
-
- {props.text}
-
-)
+export const Comment: React.FC = ({
+ _creatorId,
+ text,
+ _id,
+ ...props
+}) => {
+ const { stores } = useCommonStores()
+ const user = stores.userStore.activeUser
+
+ const [showEditModal, setShowEditModal] = useState(false)
+
+ return (
+
+
+
+ {text}
+
+
+ {user && (user._id === _creatorId || hasAdminRights(user)) && (
+
+ {user._id === _creatorId && (
+ setShowEditModal(true)}
+ >
+ edit
+
+ )}
+ {
+ const confirmation = window.confirm(
+ 'Are you sure you want to delete this comment?',
+ )
+ if (confirmation) {
+ await stores.howtoStore.deleteComment(_id)
+ }
+ }}
+ >
+ delete
+
+
+ )}
+
+ {showEditModal && (
+
+
+ )}
+
+ )
+}
diff --git a/src/components/Comment/CommentHeader.tsx b/src/components/Comment/CommentHeader.tsx
index d8ba82e950..331db53b74 100644
--- a/src/components/Comment/CommentHeader.tsx
+++ b/src/components/Comment/CommentHeader.tsx
@@ -1,25 +1,16 @@
-import React from 'react'
-import { FaTrash } from 'react-icons/fa'
import { Box, Flex, Text } from 'rebass'
-import { useCommonStores } from 'src'
import { FlagIconHowTos } from 'src/components/Icons/FlagIcon/FlagIcon'
import { IComment } from 'src/models'
-import { hasAdminRights } from 'src/utils/helpers'
import { Link } from 'src/components/Links'
-
-export interface IProps extends Omit { }
+interface IProps extends Omit {}
export const CommentHeader = ({
creatorName,
creatorCountry,
_created,
- _creatorId,
- _id,
+ _edited,
}: IProps) => {
- const { stores } = useCommonStores()
- const user = stores.userStore.activeUser
-
return (
@@ -36,21 +27,24 @@ export const CommentHeader = ({
-
-
- {new Date(_created).toLocaleDateString('en-GB').replaceAll('/', '-')}
-
- {user && (user._id === _creatorId || hasAdminRights(user)) && (
- await stores.howtoStore.deleteComment(_id)}
- >
+
+ {_edited ? (
+ <>
+
+ (Edited)
+
+
+ {new Date(_edited)
+ .toLocaleDateString('en-GB')
+ .replaceAll('/', '-')}
+
+ >
+ ) : (
+
+ {new Date(_created)
+ .toLocaleDateString('en-GB')
+ .replaceAll('/', '-')}
+
)}
diff --git a/src/components/Modal/Modal.tsx b/src/components/Modal/Modal.tsx
index ad28c856bd..8eb2a62376 100644
--- a/src/components/Modal/Modal.tsx
+++ b/src/components/Modal/Modal.tsx
@@ -8,6 +8,7 @@ interface IProps {
// provide onDidDismiss function to enable backdrop click dismiss
onDidDismiss: (data?: any) => void
height?: number
+ width?: number
}
interface IState {
isOpen: boolean
@@ -54,12 +55,12 @@ export class Modal extends React.Component {
render() {
const isOpen = this.state
- const { height, children } = this.props
+ const { height, width, children } = this.props
return (
isOpen && (
this.dismiss()} />
-
+
{children}
diff --git a/src/models/howto.models.tsx b/src/models/howto.models.tsx
index b2e0a337f2..6409a87d88 100644
--- a/src/models/howto.models.tsx
+++ b/src/models/howto.models.tsx
@@ -9,6 +9,7 @@ import { IUploadedFileMeta } from 'src/stores/storage'
export interface IComment {
_id: string
_created: string
+ _edited?: string
_creatorId: string
creatorName: string
creatorCountry?: string | null
diff --git a/src/pages/Howto/Content/Howto/HowToComments/HowToComments.tsx b/src/pages/Howto/Content/Howto/HowToComments/HowToComments.tsx
index b67ddf7b70..2c848bcc70 100644
--- a/src/pages/Howto/Content/Howto/HowToComments/HowToComments.tsx
+++ b/src/pages/Howto/Content/Howto/HowToComments/HowToComments.tsx
@@ -10,7 +10,6 @@ import styled from 'styled-components'
const MAX_COMMENTS = 5
interface IProps {
- userName?: string
comments?: IComment[]
}
diff --git a/src/pages/Howto/Content/Howto/Howto.tsx b/src/pages/Howto/Content/Howto/Howto.tsx
index fdcb1639b6..48f28fb73c 100644
--- a/src/pages/Howto/Content/Howto/Howto.tsx
+++ b/src/pages/Howto/Content/Howto/Howto.tsx
@@ -142,10 +142,7 @@ export class Howto extends React.Component<
))}
-
+
diff --git a/src/stores/Howto/howto.store.tsx b/src/stores/Howto/howto.store.tsx
index 720d2850b2..09d819c386 100644
--- a/src/stores/Howto/howto.store.tsx
+++ b/src/stores/Howto/howto.store.tsx
@@ -189,6 +189,7 @@ export class HowtoStore extends ModuleStore {
)
if (commentIndex !== -1) {
comments[commentIndex].text = newText.slice(0, 400).trim()
+ comments[commentIndex]._edited = new Date().toISOString()
const updatedHowto: IHowto = {
...toJS(howto),