| 1 |
import { memo } from "@wordpress/element"; |
| 2 |
import { Draggable } from "react-beautiful-dnd"; |
| 3 |
import { __ } from "@wordpress/i18n"; |
| 4 |
import { IconDrag, IconDelete, IconOpen, IconEdit } from "../../../icons"; |
| 5 |
import { gutenbergEditScreenUrl } from "../helpers/Helpers"; |
| 6 |
import { decodeEntities } from "@wordpress/html-entities"; |
| 7 |
import { applyFilters } from "@wordpress/hooks"; |
| 8 |
|
| 9 |
const GridItem = ({ doc, index, deleteIds, isLoading, termId, setQuickEdit, mutate, term }) => { |
| 10 |
return ( |
| 11 |
<Draggable key={doc?.unique_id} draggableId={doc?.unique_id?.toString()} index={index}> |
| 12 |
{(provided, snapshot) => { |
| 13 |
const actions = applyFilters('dashboardGridViewItem',{ |
| 14 |
editAction:() => { |
| 15 |
return <a |
| 16 |
className="betterdocs-dashboard-doc-action-edit" |
| 17 |
title={__("Quick Edit", "betterdocs")} |
| 18 |
href={gutenbergEditScreenUrl(doc.id)} |
| 19 |
onClick={(e) => { |
| 20 |
e.preventDefault(); |
| 21 |
setQuickEdit((prevState) => { |
| 22 |
return {...prevState, isOpen: !prevState.isOpen, data:{docData:doc, termId:termId, docId:doc?.id}} |
| 23 |
}) |
| 24 |
}} |
| 25 |
> |
| 26 |
<IconEdit /> |
| 27 |
</a> |
| 28 |
}, |
| 29 |
viewAction:() => { |
| 30 |
return <a |
| 31 |
className="betterdocs-dashboard-doc-action-open" |
| 32 |
target="_blank" |
| 33 |
title={__("View", "betterdocs")} |
| 34 |
href={doc?.link} |
| 35 |
> |
| 36 |
<IconOpen /> |
| 37 |
</a> |
| 38 |
}, |
| 39 |
deleteAction:() => { |
| 40 |
return <button |
| 41 |
className="betterdocs-dashboard-doc-action-delete" |
| 42 |
type="button" |
| 43 |
title={__("Trash", "betterdocs")} |
| 44 |
onClick={(e) => { |
| 45 |
deleteIds[termId] = { |
| 46 |
post_id_index:index, |
| 47 |
term_id:termId, |
| 48 |
post_id:doc.id |
| 49 |
} |
| 50 |
mutate(deleteIds); |
| 51 |
}} |
| 52 |
> |
| 53 |
<IconDelete /> |
| 54 |
</button> |
| 55 |
}, |
| 56 |
editDoc: <a href={gutenbergEditScreenUrl(doc?.id)}>{decodeEntities(doc?.title)}{doc?.status != 'publish' && <span className="status">{` - ${doc?.status?.charAt(0).toUpperCase()}${doc?.status?.slice(1)}`}</span>}</a> |
| 57 |
}, doc, term, termId); |
| 58 |
|
| 59 |
return <li |
| 60 |
className={`${snapshot.isDragging ? 'is-dragging' : ''}`} |
| 61 |
ref={provided.innerRef} |
| 62 |
{...provided.draggableProps} |
| 63 |
{...provided.dragHandleProps} |
| 64 |
style={{ |
| 65 |
cursor:snapshot.isDragging ? 'move' : 'move', |
| 66 |
...provided.draggableProps.style |
| 67 |
}} |
| 68 |
> |
| 69 |
{((deleteIds[termId]?.post_id == doc?.id && isLoading)) && <div className="delete-row"></div>} |
| 70 |
<span |
| 71 |
className="betterdocs-dashboard-doc-drag" |
| 72 |
> |
| 73 |
<IconDrag /> |
| 74 |
</span> |
| 75 |
{actions['editDoc']} |
| 76 |
{Object.values(actions)?.length > 0 && <span className="betterdocs-dashboard-doc-actions"> |
| 77 |
{Object.keys(actions)?.map((key) => { |
| 78 |
if( key != 'editDoc' ) { |
| 79 |
return actions[key](); |
| 80 |
} |
| 81 |
})} |
| 82 |
</span>} |
| 83 |
</li> |
| 84 |
}} |
| 85 |
</Draggable> |
| 86 |
); |
| 87 |
}; |
| 88 |
|
| 89 |
export default memo(GridItem); |
| 90 |
|