feat: enhance modal functionality with reset and confirmation handlers

This commit is contained in:
Siddhant Rai
2025-06-24 02:14:15 +05:30
parent d36f12a4ea
commit 0d48159da8
4 changed files with 61 additions and 45 deletions

View File

@@ -33,6 +33,19 @@ export default function ChunkModal({
setChunkText(originalText || '');
}, [originalTitle, originalText]);
const resetForm = () => {
setTitle('');
setChunkText('');
};
const handleDeleteConfirmed = () => {
if (handleDelete) {
handleDelete();
}
setDeleteModal('INACTIVE');
setModalState('INACTIVE');
};
if (modalState !== 'ACTIVE') return null;
const content = (
@@ -71,6 +84,7 @@ export default function ChunkModal({
onClick={() => {
handleSubmit(title, chunkText);
setModalState('INACTIVE');
resetForm();
}}
className="rounded-3xl bg-purple-30 px-5 py-2 text-sm text-white transition-all hover:bg-violets-are-blue"
>
@@ -79,6 +93,7 @@ export default function ChunkModal({
<button
onClick={() => {
setModalState('INACTIVE');
resetForm();
}}
className="cursor-pointer rounded-3xl px-5 py-2 text-sm font-medium hover:bg-gray-100 dark:bg-transparent dark:text-light-gray dark:hover:bg-[#767183]/50"
>
@@ -124,6 +139,7 @@ export default function ChunkModal({
<WrapperModal
close={() => setModalState('INACTIVE')}
className="sm:w-[620px]"
isPerformingTask={true}
>
{content}
</WrapperModal>
@@ -133,13 +149,7 @@ export default function ChunkModal({
message={t('modals.chunk.deleteConfirmation')}
modalState={deleteModal}
setModalState={setDeleteModal}
handleSubmit={
handleDelete
? handleDelete
: () => {
/* no-op */
}
}
handleSubmit={handleDeleteConfirmed}
submitLabel={t('modals.chunk.delete')}
/>
)}