From 90efb5be001393134aaef07fe11e9ad605692043 Mon Sep 17 00:00:00 2001 From: Mo Tarbin Date: Sat, 20 Jul 2024 03:40:41 -0400 Subject: Support for history Modification and deletion --- src/views/Modals/EditHistoryModal.jsx | 121 ++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 src/views/Modals/EditHistoryModal.jsx (limited to 'src/views/Modals') diff --git a/src/views/Modals/EditHistoryModal.jsx b/src/views/Modals/EditHistoryModal.jsx new file mode 100644 index 0000000..1baab49 --- /dev/null +++ b/src/views/Modals/EditHistoryModal.jsx @@ -0,0 +1,121 @@ +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 -- cgit