import { Box, Button, FormLabel, Input, Modal, ModalDialog, Typography, } from '@mui/joy' import moment from 'moment' import { useEffect, useState } from 'react' import ConfirmationModal from './Inputs/ConfirmationModal' function EditHistoryModal({ config, historyRecord }) { useEffect(() => { setCompletedDate( moment(historyRecord.completedAt).format('YYYY-MM-DDTHH:mm'), ) setDueDate(moment(historyRecord.dueDate).format('YYYY-MM-DDTHH:mm')) setNotes(historyRecord.notes) }, [historyRecord]) const [completedDate, setCompletedDate] = useState( moment(historyRecord.completedDate).format('YYYY-MM-DDTHH:mm'), ) const [dueDate, setDueDate] = useState( moment(historyRecord.dueDate).format('YYYY-MM-DDTHH:mm'), ) const [notes, setNotes] = useState(historyRecord.notes) const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false) return ( Edit History Due Date { setDueDate(e.target.value) }} /> Completed Date { setCompletedDate(e.target.value) }} /> Note { if (e.target.value.trim() === '') { setNotes(null) return } setNotes(e.target.value) }} size='md' sx={{ mb: 1, }} /> {/* 3 button save , cancel and delete */} { if (isConfirm) { config.onDelete(historyRecord.id) } setIsDeleteModalOpen(false) }, title: 'Delete History', message: 'Are you sure you want to delete this history?', confirmText: 'Delete', cancelText: 'Cancel', }} /> ) } export default EditHistoryModal