import { useState, useRef } from 'react'; import EditableMediaService from '../../services/editable-media-service' import { Card, CardImg, CardTitle, CardText, CardBody, Input, InputGroup, InputGroupText, FormFeedback, Button, ButtonGroup } from 'reactstrap'; import { Link } from 'react-router-dom'; import ModalComponent from './modal-component'; function CardListViewer(props) { const [nameFieldInvalid, setNameFieldInvalid] = useState(false) const [descriptionFieldInvalid, setDescriptionFieldInvalid] = useState(false) const [taglineFieldInvalid, setTaglineFieldInvalid] = useState(false) const [modal, setModal] = useState(false); const [modalText, setModalText] = useState(false); const [modalTitle, setModalTitle] = useState(false); const toggle = () => setModal(!modal); const nameField = useRef(null) const descriptionField = useRef(null) const taglineField = useRef(null) const handleInputUpdate = (elementValue, fieldType) => { if (fieldType === 'nameField'){ if (elementValue === '') setNameFieldInvalid(true) else setNameFieldInvalid(false) } if (fieldType === 'descriptionField'){ if (elementValue === '') setDescriptionFieldInvalid(true) else setDescriptionFieldInvalid(false) } if (fieldType === 'taglineField'){ if (elementValue === '') setTaglineFieldInvalid(true) else setTaglineFieldInvalid(false) } props.addToIdsToUpdate({ 'id': props.id, 'name': nameField.current.value, 'featuredBlog': '', 'description': descriptionField.current.value, 'tagLine': taglineField.current.value, }) } const showModal = () => { setModalTitle('Confirm') setModalText('Are you sure that you wish to delete this category?') toggle() } const deleteResource = () => { props.deleteResource(props.id) toggle() } const itemObject = props.itemObject if (props.totalItems > 0 && itemObject && Object.keys(itemObject).length !== 0){ if (props.resourceType === 'categories') return ( <> Name handleInputUpdate(nameField.current.value, 'nameField')}/> {nameFieldInvalid ? This field cannot be empty :''} Description handleInputUpdate(descriptionField.current.value, 'descriptionField')}/> {descriptionFieldInvalid ? This field cannot be empty :''} Tagline handleInputUpdate(taglineField.current.value, 'taglineField')} /> {taglineFieldInvalid ? This field cannot be empty :''} ) else return ( {itemObject.coverImage !== '' ? : ''} {itemObject.name} {itemObject.description} {itemObject.tagLine} { props.showSetFeaturedBlog ? : '' } ) } else return(

No items found in this section

) } export default CardListViewer